# Set data dimension:
# - 1 million observations,
# - 7 'dense' fixed effect covariates,
# - stratified random effects with 2000 strata (levels)
nobs <- 1000000;
ndays <- 7;
nPostCodes <- 2000;
# Generate data
counts <- as.integer(runif(nobs, 1, 10));
days <- matrix(rnorm(nobs * ndays), nrow = nobs, ncol = ndays);
seifa <- rnorm(nobs);
postCodes <- as.factor(as.integer(runif(nobs, 0, nPostCodes)));
ipostCodes <- as.integer(postCodes) - 1L; # zero-based vector of indices
# Generate coefficients
offset = runif(nobs, -1, 1);
intercept = -0.5;
sd.days <- 0.1;
beta.days <- rnorm(ndays, sd = sd.days);
sd.seifa <- 0.1;
intercept.seifa <- rnorm(nPostCodes, sd = sd.seifa);
beta.seifa <- rnorm(nPostCodes, sd = sd.seifa);
# Generate linear predictor
eta <- intercept + days %*% beta.days;
eta <- eta + intercept.seifa[as.integer(postCodes)] + seifa * beta.seifa[as.integer(postCodes)];
# Generate response
y <- as.integer(rbinom(nobs, counts, plogis(eta)));
# Define identity precision model and control list
I <- glmmGS.CovarianceModel("identity");
control <- glmmGS.Control(reltol = 1.e-8, abstol = 1.e-25, maxit = 200);
# Fit model using Gauss-Seidel algorithm with two blocks:
# - one fixed effect block: (1 + days);
# - one stratified random effect block with an identity
# covariance model: (1 + seifa | ipostCodes ~ I).
formula = (y | counts) ~ offset(offset) + (1 + days) + (1 + seifa | ipostCodes ~ I);
results <- glmmGS(formula = formula, family = binomial, control = control);
Run the code above in your browser using DataLab