Skip to content

standardized coefficients in lme4 package

2 messages · Simon Sun, Andrea Cantieni

#
Dear Ben,

I am a user of your excellent work lme4. While during my work I realized the 
problem that the package doesn't provide function to return standardized 
coefficients.

I found a section of code on your website:
##
lm.beta.lmer <- function(mod) {
  b <- fixef(mod)[-1]              ## fixed-effect coefs, sans intercept
  sd.x <- apply(mod @ X[,-1],2,sd) ## pull out model (design) matrix,
                                   ## drop intercept column, calculate
                                   ## sd of remaining columns
  sd.y <- sd(mod @ y)              ## sd of response
  b*sd.x/sd.y
}
##

But I couldn't make it work, every time it showed:

 Error in apply(Mod at x[, -1], 2, sd) : no slot of name "x" for this object of 
class "lmerMod"

Could you please help me figure it out? Thank you very much!
2 days later