Skip to content
Prev 15150 / 20628 Next

force lmer/glmer to use known random effects

I think you can actually do this if you're willing to hack a little
bit.  Here's an example modifying the one shown in ?modular :

library(lme4)
## 1.  Parse the data and formula:
glmod <- glFormula(cbind(incidence, size - incidence) ~ period + (1 | herd),
                   data = cbpp, family = binomial)
## 2.  Create the deviance function for optimizing over theta:
##     skip initial (nAGQ=0, theta parameters only) step
devfun <- updateGlmerDevfun(do.call(mkGlmerDevfun, c(glmod, list(nAGQ=1))),
                            reTrms=glmod$reTrms)
devfun2 <- function(beta) {
    devfun(c(1,beta))
}
devfun2(c(0,0,0,0))   ## test: evaluate
## deviance with all fixed-effect parameters set to zero
## optimize
opt <- nloptwrap(fn=devfun2,
          par=c(0,0,0,0),
          lower=rep(-Inf,4),
          upper=rep(Inf,4))
opt$par
[1] -1.4570408 -0.9533831 -1.0913854 -1.5366132
On 17-01-09 05:40 AM, Thierry Onkelinx wrote: