# NOT RUN {
# }
# NOT RUN {
## USAGE 1
# }
# NOT RUN {
library(optmatch)
## User is required to install and load the optmatch package separately,
data(Dodgeram) # dodge ram pk 2500
grouplabel = 2*Dodgeram$WITHSABS + 1*Dodgeram$NOSAB + 3*Dodgeram$optSAB
# distance components consists of log propensity
# distance and rank based Mahalanobis distance.
components <- list(prop = c("AGE", "IMPACT3"), mahal = c("SEX.2", "AGE", "FIRE_EXP1.1"))
wgts <- c(10, 5)
distmat <- multigrp_dist_struc(Dodgeram, grouplabel = grouplabel, components, wgts)
# Matching
design = c(1,1,3) # 3 units from the optional period, 1 each from other periods
indexgroup = 2
res = tripletmatching(distmat = distmat, grouplabel = grouplabel, design = design,
indexgroup = indexgroup)
# covariance balance
details = 'mean'
covbalance(Dodgeram, grouplabel=c("NOSAB", "optSAB", "WITHSABS"), matches = res,
vars = c("AGE", "SEX.2", "IMPACT3.3", "DR_DRINK"), details)
# }
# NOT RUN {
## USAGE 2
# }
# NOT RUN {
library(optmatch)
## User is required to install and load the optmatch package separately,
data(Dodgeram)
# Example distance structure
components <- list(prop = c("AGE", "SEX.2", "FR.pass", "REST_USE1", "ROLLOVER1",
"IMPACT3", "SP_LIMIT", "DR_DRINK", "FIRE_EXP1.1"),
mahal = c("SEX.2", "AGE", "SP_LIMIT", "DR_DRINK"),
mahal = c("IMPACT3", "REST_USE1"))
wgts <- c(5, 8, 20)
distmat <- multigrp_dist_struc(Dodgeram, grouplabel = c("NOSAB", "optSAB", "WITHSABS"),
components, wgts)
# Matching with fine balance and exact match
indexgroup = "WITHSABS"
finebalanceVars = c("ROLLOVER1.1", "FIRE_EXP1.1")
exactmatchon = "FR.pass"
res = tripletmatching(distmat = distmat, grouplabel = c("NOSAB", "optSAB", "WITHSABS"),
design = c(3,3,1), indexgroup = indexgroup, .data = Dodgeram,
finebalanceVars = finebalanceVars, exactmatchon = exactmatchon)
# covariance balance
vars = c("AGE", "SEX.2", "IMPACT3.3", "DR_DRINK")
details = c('std_diff', 'mean', 'function(x) diff(range(x))',
'function(x) quantile(x, probs = .9)')
names(details) <- c('std_diff', 'mean', 'range', '90perc')
covbalance(.data=Dodgeram, grouplabel=c("NOSAB", "optSAB", "WITHSABS"),
matches = res, vars = vars, details)
# }
Run the code above in your browser using DataLab