MatchIt进行倾向性评分匹配(最佳临近法)
library("survival")
library("MatchIt")
data(colon)
colon$surg<-as.factor(colon$surg)
str(colon)
newdata<-na.omit(colon)
fit.match<-matchit(surg~age+sex+differ+obstruct,data=newdata,method="nearest",ratio=1,caliper=02)
summary(fit.match)
plot( fit.match,type = "jitter" )
plot( fit.match, type = " hist" )
plot(fit.match, type = "QQ" )
match.data<-match.data(fit.match)
write.csv(match.data,file = "match.data. csv" )
完整方程为:
matchit(formula, data=NULL, discard=0, exact=FALSE, replace=FALSE, ratio=1, model="logit", reestimate=FALSE, nearest=TRUE, m.order=2, caliper=0, calclosest=FALSE, mahvars=NULL, subclass=0, sub.by="treat", counter=TRUE, full=FALSE, full.options=list(), ...)
重要参数主要有caliper为卡钳值,越小两组可比性越高,但是可能会有较多患者无法匹配上,一般选择0.01-0.2之间。
method的包括以下几个情况
This argument specifies a matching method. Currently, "exact" (exact matching), "full" (full matching), "genetic" (genetic matching), "nearest" (nearest neighbor matching), "optimal" (optimal matching), and "subclass" (subclassification) are available. The default is "nearest". Note that within each of these matching methods, MatchIt offers a variety of options.
结果展示可以用以下命令
A summary of the results can be seen graphically using plot(matchitobject), or numerically using summary(matchitobject). print(matchitobject) also prints out the output.