Liao, J.G. and Lipsitz, S.R. (2002) A type of restricted maximum likelihood estimator for variance components in generalized linear mixed models. Biometrika 89, 401-409 The following is only a “proof of concept” for the proposed algorithm. It is not intended for general use. rm(list=ls(all=TRUE)) library(MASS); ###small and common functions################################## glmm.sample.y <- function(b, D.u, x, z) { pp <- matrix(0, nrow = n, ncol = m); zero <- numeric(n.random); ran <- t( mvrnorm(m, zero, D.u) ); for(j in 1:m) pp[, j] <- as.vector( x[, , j] %*% b + z[, , j] %*% ran[ ,j] ); pp <- exp(pp)/( 1+exp(pp) ); y <- runif(m*n); ifelse(y