optmatch_snap | R Documentation |
Longitudinal snapshot matching.
optmatch_snap( x, data, id, tol=1e-6)
x |
Any valid input to Alternatively, a precomputed distance may be entered. A matrix of
non-negative discrepancies, each indicating the permissibility and
desirability of matching the unit corresponding to its row (a 'treatment') to
the unit corresponding to its column (a 'control'); or, better, a distance
specification as produced by |
controls |
The number of controls to be matched to each treatment. |
data |
|
id |
A string to indicate which column of the |
tol |
The minimum difference in distance that |
The usage of this function is very similar to the fullmatch
in the optmatch package.
A vector indicating matched groups.
Tianchen Xu, Yiyue Lou
dat <- SnapMatch:::demo() ### Match With Covariate Distance # calculate the distance matrix dis <- match_on(trt~X1+X2, data = dat, method="mahalanobis") # conduct optimal matching. 'Id' is the id column for each subject pm <- optmatch_snap(dis, data = dat, id = 'id') # plot result # plot(xBalance(trt ~ X1+X2+strata(pm), data=dat), xlim=c(-2,1), ylim=c(0,3)) ### Match With Propensity Score # calculate propensity score prop <- glm(trt ~ X1+X2, data = dat, family = binomial()) # conduct optimal matching by propensity score. 'Id' is the id column for each subject pm <- optmatch_snap(prop, data = dat, id = 'id') # plot result # plot(xBalance(trt ~ X1+X2+strata(pm), data=dat), xlim=c(-2,1), ylim=c(0,3)) ### Complex Match With 'match_on' Function # calculate distance by propensity score dis <- match_on(glm(trt ~ X1+X2, data = dat, family = binomial())) # add caliper dis <- caliper(dis,2) + dis # conduct optimal snapshot matching dis <- as.matrix(dis) dis[which(is.infinite(dis))] <- 100 pm <- optmatch_snap(dis, data = dat, id = 'id') # plot result # plot(xBalance(trt ~ X1+X2+strata(pm), data=dat), xlim=c(-2,1), ylim=c(0,3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.