# NOT RUN {
#This loads the classic Lalonde (1986) dataset,
#as well as two matched datasets:
#one from 1:1 propensity score matching,
#and one from cardinality matching, where
#the standardized covariate mean differences are all below 0.1.
data("lalondeMatches")
#obtain the covariates for these datasets
X.lalonde = subset(lalonde, select = -c(treat))
X.matched.ps = subset(lalonde.matched.ps, select = -c(treat,subclass))
X.matched.card = subset(lalonde.matched.card, select = -c(treat,subclass))
#the treatment indicators are
indicator.lalonde = lalonde$treat
indicator.matched.ps = lalonde.matched.ps$treat
indicator.matched.card = lalonde.matched.card$treat
#the subclass for the matched datasets are
subclass.matched.ps = lalonde.matched.ps$subclass
subclass.matched.card = lalonde.matched.card$subclass
#The following code will display a classic Love plot
#(with a dot for each standardized covariate mean difference).
#Note that, for the full dataset, we only specify X.matched and indicator.matched.
lovePlot(X.matched = X.lalonde, indicator.matched = indicator.lalonde)
lovePlot(X.matched = X.matched.ps, indicator.matched = indicator.matched.ps,
X.full = X.lalonde, indicator.full = indicator.lalonde)
lovePlot(X.matched = X.matched.card, indicator.matched = indicator.matched.card,
X.full = X.lalonde, indicator.full = indicator.lalonde)
#The following lines of code create Love plots assessing
#whether indicator.data follows different assignment mechanisms by
#plotting the permutation quantiles
#Note that the following examples only use 100 permutations
#to approximate the randomization distribution.
#In practice, we recommend setting perms = 1000 or more;
#in these examples we use perms = 50 to save computation time.
#Assessing complete randomization for the full dataset
#Here we conclude complete randomization doesn't hold
#because the standardized covariate mean differences
#are almost all outside the quantiles.
lovePlot(X.matched = X.lalonde, indicator.matched = indicator.lalonde,
permQuantiles = TRUE,
perms = 50)
#assessing block (paired) randomization for
#the 1:1 propensity score matched dataset
#Many of the standardized covariate mean differences
#are within the permutation quantiles,
#but the race covariates (hispan and black)
#are outside these quantiles.
lovePlot(X.matched = X.matched.ps, indicator.matched = indicator.matched.ps,
X.full = X.lalonde, indicator.full = indicator.lalonde,
permQuantiles = TRUE,
perms = 50,
assignment = "blocked", subclass = subclass.matched.ps)
#assessing block (paired) randomization for
#the cardinality matched dataset
#All of the standardized covariate mean differences
#are within the permutation quantiles
lovePlot(X.matched = X.matched.card, indicator.matched = indicator.matched.card,
X.full = X.lalonde, indicator.full = indicator.lalonde,
permQuantiles = TRUE,
perms = 50,
assignment = "blocked", subclass = subclass.matched.card)
#assessing constrained randomization,
#where the Mahalanobis distance is constrained.
#Note that the Mahalanobis distance is approximately
#a chi^2_K distribution, where K is the number of covariates.
#In the Lalonde data, K = 8.
#Thus, the threshold can be chosen as the quantile of the chi^2_8 distribution.
#This threshold constrains the Mahalanobis distance to be below the 25-percent quantile:
a = qchisq(p = 0.25, df = 8)
#Then, the corresponding Love plot and permutation quantiles are:
lovePlot(X.matched = X.matched.card, indicator.matched = indicator.matched.card,
X.full = X.lalonde, indicator.full = indicator.lalonde,
permQuantiles = TRUE,
perms = 50,
assignment = "constrained md",
threshold = a)
# }
Run the code above in your browser using DataLab