# 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
#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.
#testing complete randomization for the full dataset
#using the Mahalanobis distance.
#We reject complete randomization in this test.
asIfRandTest(X.matched = X.lalonde, indicator.matched = indicator.lalonde, perms = 50)
#testing complete randomization for the full dataset
#using standardized covariate mean differences.
#We reject complete randomization for most covariates:
asIfRandTest(X.matched = X.lalonde, indicator.matched = indicator.lalonde,
statistic = "diffs",
perms = 50)
#testing complete randomization and block (paired) randomization
#for the propensity score matched dataset
#using the Mahalanobis distance.
#We reject both assignment mechanisms in this test.
asIfRandTest(X.matched = X.matched.ps, indicator.matched = indicator.matched.ps,
X.full = X.lalonde, indicator.full = indicator.lalonde,
assignment = c("complete", "blocked"),
subclass = lalonde.matched.ps$subclass,
perms = 50)
#testing complete randomization and block (paired) randomization
#for the propensity score matched dataset
#using the standardized covariate mean differences.
#We reject these assignment mechanisms for
#the race covariates (hispan and black):
asIfRandTest(X.matched = X.matched.ps, indicator.matched = indicator.matched.ps,
X.full = X.lalonde, indicator.full = indicator.lalonde,
assignment = c("complete", "blocked"),
subclass = lalonde.matched.ps$subclass,
statistic = "diffs",
perms = 50)
#testing three assignment mechanisms for
#the cardinality matched dataset:
# 1) complete randomization
# 2) blocked (paired) randomization
# 3) constrained-MD randomization
#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)
#First we'll run the test using the Mahalanobis distance.
#We fail to reject for the first two assignment mechanisms,
#but reject the third.
asIfRandTest(X.matched = X.matched.card, indicator.matched = indicator.matched.card,
X.full = X.lalonde, indicator.full = indicator.lalonde,
assignment = c("complete", "blocked", "constrained md"),
subclass = lalonde.matched.card$subclass,
threshold = a,
perms = 50)
#Now we'll run the test using the standardized covariate mean differences.
#Interestingly, you fail to reject for all three assignment mechanisms
#for all covariates:
asIfRandTest(X.matched = X.matched.card, indicator.matched = indicator.matched.card,
X.full = X.lalonde, indicator.full = indicator.lalonde,
assignment = c("complete", "blocked", "constrained md"),
subclass = lalonde.matched.card$subclass,
threshold = a,
statistic = "diffs",
perms = 50)
# }
Run the code above in your browser using DataLab