I have been using the code below to successfully modify the \'Zt\', \'L\', and \'A\' slots of models fit using lme4 versions <1.0. I just updated to lme4 1.0-4 today and foun
Does this do what you want? (This follows ?modular
pretty closely ...)
Create the Zl and ZZ matrices:
Zl <- lapply(c("pop1","pop2"),
function(nm) Matrix:::fac2sparse(dat[[nm]], "d", drop=FALSE))
ZZ <- Reduce("+", Zl[-1], Zl[[1]])
Construct the random-effects data structures:
lf <- lFormula(Y ~ X + (1|pop1), data=dat)
Modify them:
lf$reTrms$Zt <- ZZ
Proceed through the remaining model-construction and fitting steps:
dfun <- do.call(mkLmerDevfun,lf) ## create dev fun from modified lf
opt <- optimizeLmer(dfun) ## fit the model
## make the results into a 'merMod' object
fit <- mkMerMod(environment(dfun), opt, lf$reTrms,
fr = lf$fr)