# NOT RUN {
data(costa)
z<-1*(costa$welder=="Y")
aa<-1*(costa$race=="A")
smoker=1*(costa$smoker=="Y")
age<-costa$age
x<-cbind(age,aa,smoker)
dmat<-smahal(z,x)
# Mahalanobis distances
round(dmat[,1:6],2)
# Compare with Table 9.6 in "Design of
# Observational Studies", second edition
# Impose propensity score calipers
prop<-glm(z~age+aa+smoker,family=binomial)$fitted.values # propensity score
# Mahalanobis distanced penalized for violations of a propensity score caliper.
# This version is used for numerical work.
dmat<-addcaliper(dmat,z,prop,caliper=.5)
round(dmat[,1:6],2)
# Compare with Table 9.6 in "Design of
# Observational Studies", second edition
# }
# NOT RUN {
# You must load 'optmatch' to produce the match.
# Find the minimum distance match within propensity score calipers.
optmatch::pairmatch(dmat,data=costa)
# }
# NOT RUN {
# Conceptual versions with infinite distances
# for violations of propensity caliper.
dmat[dmat>20]<-Inf
round(dmat[,1:6],2)
# }
Run the code above in your browser using DataLab