Skip to content

Instantly share code, notes, and snippets.

@markmfredrickson
Created July 22, 2015 20:41
Show Gist options
  • Save markmfredrickson/1d4c13885f967cef5412 to your computer and use it in GitHub Desktop.
Save markmfredrickson/1d4c13885f967cef5412 to your computer and use it in GitHub Desktop.
Replacing explict strata arg
library(RItools)
library(optmatch)
set.seed(20130801)
n <- 500
library(MASS)
xs <- mvrnorm(n,
mu = c(1,2,3),
Sigma = matrix(c(1, 0.5, 0.2,
0.5, 1, 0,
0.2, 0, 1), nrow = 3, byrow = T))
colnames(xs) <- paste0("x", 1:3)
p <- plogis(0.5 * xs[,1] - 0.25 * xs[,2] - 1)
z <- rbinom(n, p = p, size = 1)
s1 <- rep(c(0,1), each = n/2)
s2 <- rep(1:10, each = n/10)
ff <- fullmatch(match_on(glm(z ~ p, data = dat, family = binomial)), data = dat)
dat <- data.frame(z, xs, s1, s2, ff)
# should be equivalent to z ~ x1 + x2 + x3 + strata(s1) + strata(s2) + strata(ff)
# and no explict strata arg
res <- xBalance(z ~ x1 + x2 + x3,
data = dat,
report = 'all',
strata = list("Unadj" = NULL,
"S1" = ~ s1,
"S2" = ~ s2,
"FF" = ~ ff))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment