data(plantdist)
round(plantdist)
plantsfm <- fullmatch(plantdist) # A full match with unrestricted
# treatment-control balance
pr <- logical(26)
pr[match(dimnames(plantdist)[[1]], names(plantsfm))] <- TRUE
table(plantsfm, # treatment-control balance,
ifelse(pr,'treated', 'control')) # by matched set
stratumStructure(plantsfm) # summary of sets' trt-ctl balance
sum(plantdist* # sum of matched distances
outer(plantsfm[pr], plantsfm[!pr],
"==") )
plantsfm1 <- fullmatch(plantdist, # A full match with
min.controls=2, max.controls=3) # restrictions on matched sets'
# treatment-control balance
stratumStructure(plantsfm1) # treatment-control balance is
# improved by restrictions
sum(plantdist* # but distances between
outer(plantsfm1[pr], plantsfm1[!pr],# matched units increase
"==") )
tapply(names(plantsfm), # largest treatment-control
plantsfm1, FUN= function(x, dmat) { # distances, by matched set
max(
dmat[match(x, dimnames(dmat)[[1]]),
match(x, dimnames(dmat)[[2]])],
na.rm=TRUE )
}, dmat=plantdist)Run the code above in your browser using DataLab