library("microsynth") data("seattledmi", package = "microsynth") match.out <- c("i_felony", "i_misdemea", "i_drugs", "any_crime") cov.var <- c("TotalPop", "BLACK", "HISPANIC", "Males_1521", "HOUSEHOLDS", "FAMILYHOUS", "FEMALE_HOU", "RENTER_HOU", "VACANT_HOU") ### To replicate the results in the article, use n.cores = 1 in the examples. ### For better computational performance, use a higher value of n.cores. ### Example 1 set.seed(99199) sea1 <- microsynth(seattledmi, idvar = "ID", timevar = "time", intvar = "Intervention", start.pre = 1, end.pre = 12, end.post = 16, match.out = match.out, match.covar = cov.var, result.var = match.out, jack = TRUE, perm = 250, test = "lower", cal.epsilon = 1e-05, n.cores = 1) summary(sea1) print(sea1) library("xtable") print(xtable(sea1$w$Summary, type = "latex", tabular.environment = "longtable"), file = "Ex1wSummary.tex") plot_microsynth(sea1) ### Example 2 match.out <- c("i_robbery","i_aggassau","i_burglary","i_larceny", "i_felony","i_misdemea","i_drugsale","i_drugposs","any_crime") sea2 <- microsynth(seattledmi, idvar = "ID", timevar = "time", intvar = "Intervention", start.pre = 1, end.pre = 12, end.post = 16, match.out = match.out, match.covar = cov.var, result.var = match.out, jack = TRUE, perm = 250, check.feas = TRUE, use.backup = TRUE, test = "lower", n.cores = 1) summary(sea2) plot_microsynth(sea2) ### Example 3 match.out <- list("i_robbery" = rep(2, 6), "i_aggassau" = rep(2, 6), "i_burglary" = rep(1, 12), "i_larceny" = rep(1, 12), "i_felony" = rep(2, 6), "i_misdemea" = rep(2, 6), "i_drugsale" = rep(4, 3), "i_drugposs" = rep(4, 3), "any_crime" = rep(1, 12)) sea3 <- microsynth(seattledmi, idvar = "ID", timevar = "time", intvar = "Intervention", start.pre = 1, end.pre = 12, end.post = 16, match.out = match.out, match.covar = cov.var, result.var = names(match.out), jack = TRUE, perm = 250, test = "lower", cal.epsilon = 1e-05, n.cores = 1) summary(sea3) plot_microsynth(sea3) ### Example 4 set.seed(86872) ids.t <- names(table(seattledmi$ID[seattledmi$Intervention == 1])) ids.c <- names(table(seattledmi$ID[seattledmi$Intervention == 0])) ids.synth <- c(base::sample(ids.t, 1), base::sample(ids.c, 100)) seattledmi.one <- seattledmi[is.element(seattledmi$ID, as.numeric(ids.synth)), ] sea4 <- microsynth(seattledmi.one, idvar = "ID", timevar = "time", intvar = "Intervention", start.pre = 1, end.pre = 12, end.post = 16, match.out = "any_crime", match.covar = cov.var, result.var = "any_crime", test = "lower", perm = 250, jack = FALSE, check.feas = TRUE, use.backup = TRUE, n.cores = 1) summary(sea4) plot_microsynth(sea4) ### Example 5 match.out <- c("i_felony", "i_misdemea", "i_drugs", "any_crime") seattledmi.cross <- seattledmi[seattledmi$time == 16, colnames(seattledmi) != "time"] sea5 <- microsynth(seattledmi.cross, idvar = "ID", intvar = "Intervention", timevar = NULL, match.out = FALSE, match.covar = cov.var, result.var = match.out, test = "lower", perm = 250, jack = TRUE, cal.epsilon = 1e-06, n.cores = 1) summary(sea5) ### Example 6 set.seed(99199) match.out <- c("i_felony", "i_misdemea", "i_drugs", "any_crime") cov.var <- c("TotalPop", "BLACK", "HISPANIC", "Males_1521", "HOUSEHOLDS", "FAMILYHOUS", "FEMALE_HOU", "RENTER_HOU", "VACANT_HOU") sea6a <- microsynth(seattledmi, idvar = "ID", timevar = "time", intvar = "Intervention", start.pre = 1, end.pre = 12, match.out = match.out, match.covar = cov.var, result.var = NULL, jack = TRUE, perm = 250, cal.epsilon = 1e-05) summary(sea6a) sea6b <- microsynth(seattledmi, idvar = "ID", timevar = "time", intvar = "Intervention", end.pre = 12, end.post = 16, result.var = match.out, w = sea6a, test = "lower") summary(sea6b) plot_microsynth(sea6b)