看看郭申阳著的《倾向值分析:统计方法与应用》一书P114-115中有用R的optmatch函数进行全匹配分析的例子。
#optmatch using glm to create propensity scores and then optmatch
set.seed(10)
library(foreign)
cds <- read.dta("chpt5_2.dta")
attach(cds)
#logistic regression
lcds <- glm(kuse ~ pcg_adc + age97 + mratio96 + pcged97 + black, family=binomial, data=cds)
summary(lcds)
library(optmatch)
#create propensity scores based on the logistic regression
pdist <- mdist(lcds)
#run full match
fm <- fullmatch(pdist)
(fm.d <- matched.distances(fm, pdist, pres=TRUE))
unlist(fm.d, max)
mean(unlist(fm.d))
sum(unlist(fm.d))
stratumStructure(fm)