How to modify slots lme4 >1.0

后端 未结 1 1989
执笔经年
执笔经年 2021-01-22 16:56

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

相关标签:
1条回答
  • 2021-01-22 17:30

    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)
    
    0 讨论(0)
提交回复
热议问题