How to use lmer inside a function

后端 未结 1 1081
梦谈多话
梦谈多话 2021-01-19 10:40

I\'m trying to write a function that collects some calls I use often in scripts
I use the sleepstudy data of the lme4 package in my examples
Here\'s (a simplified

相关标签:
1条回答
  • 2021-01-19 11:03

    Do it like this:

    trimModel1 <- function(frm, df) {
      require(LMERConvenienceFunctions)
      require(lme4)
      dfname <- as.name(deparse(substitute(df)))
    
      lm<-lmer(frm,data=df)
      lm.trimmed = romr.fnc(lm, df)
      df = lm.trimmed$data
      # update initial model on trimmed data
      lm<-lmer(frm,data=df)
      lm@call$formula <- frm
      lm@call$data <- dfname
      mcp.fnc(lm)
      lm
    }
    

    It's the "deparse-substitute trick" to get an object name from the object itself.

    0 讨论(0)
提交回复
热议问题