# Cf. Hastie and Tibshirani (1990) p.209. The variable n must be even.
# Here, the intercept for each matched set accounts for x3 which is
# the confounder or matching variable.
n = 700 # Requires a big machine with lots of memory. Expensive wrt time
n = 100 # This requires a reasonably big machine.
mydat = data.frame(x2 = rnorm(n), x3 = rep(rnorm(n/2), each = 2))
xmat = with(mydat, cbind(x2, x3))
mydat = transform(mydat, eta = -0.1 + 0.2 * x2 + 0.3 * x3)
etamat = with(mydat, matrix(eta, n/2, 2))
condmu = exp(etamat[, 1]) / (exp(etamat[, 1]) + exp(etamat[, 2]))
y1 = ifelse(runif(n/2) < condmu, 1, 0)
y = cbind(y1, 1 - y1)
mydat = transform(mydat, y = c(y1, 1-y1),
ID = factor(c(row(etamat))))
fit = vglm(y ~ 1 + ID + x2, trace = TRUE,
fam = mbinomial(mvar = ~ ID - 1), data = mydat)
dimnames(coef(fit, matrix = TRUE))
coef(fit, matrix = TRUE)
summary(fit)
head(fitted(fit))
objsizemb = function(object) round(object.size(object) / 2^20, dig = 2)
objsizemb(fit) # in Mb
VLMX = model.matrix(fit, type = "vlm") # The big model matrix
dim(VLMX)
objsizemb(VLMX) # in Mb
rm(VLMX)
Run the code above in your browser using DataLab