So, you want to compare groups (intervention units) who are similar on baseline
but who differ on the intervention. Here is a very very quick and dirty
overview of going from data to an estimate of the ATE (taken in part from the
documentation for optmatch see also Mark Fredrickson’s work through.)
12345678910111213141516171819
library(optmatch)data(nuclearplants)## Make a propensity scoreppty <- glm(pr ~ . -(pr + cost), family = binomial(), data = nuclearplants)ppty.dist <- match_on(ppty)## a propensity score distance matrix### Make a mahalanobis (MH) distance matrix (similarity on X) could also rank first.mhd <- match_on(pr ~ t1 + t2, data = nuclearplants)## Prepare to match on MH distance but require observations be no more than ## 2sd on propensity score apartmhd.pptyc <- mhd + caliper(ppty.dist, width =2)pm <- pairmatch(mhd.pptyc,data=nuclearplants)## for pairsfm <- fullmatch(mhd.pptyc,data=nuclearplants)## for a full match summary(pm)summary(fm)
You can then add the matching-factors to the data for later analysis:
1
nuclearplants[names(fm),"fm"]<-as.factor(fm) ## to get rid of attributes and such
confint.HC<-function (object, parm, level = 0.95, thevcov, ...) {
## a copy of the confint.lm function adding "thevcov" to
cf <- coef(object)
pnames <- names(cf)
if (missing(parm))
parm <- pnames
else if (is.numeric(parm))
parm <- pnames[parm]
a <- (1 - level)/2
a <- c(a, 1 - a)
fac <- qt(a, object$df.residual)
pct <- stats:::format.perc(a, 3)
ci <- array(NA, dim = c(length(parm), 2L), dimnames = list(parm,
pct))
##ses <- sqrt(diag(vcov(object)))[parm]
ses <- sqrt(diag(thevcov))[parm]
ci[] <- cf[parm] + ses %o% fac
ci
}
confint.HC(lm1,level=.95,parm="pr",thevcov=vcovHC(lm1,type="HC2"))