half-pass
half-pass

Reputation: 1931

Force inclusion of observations with missing data in lmer

I want to fit a linear mixed-effects model using lme4::lmer without discarding observations with missing data. That is, I want lmer to go ahead and maximize the likelihood using all the data.

Am I correct in thinking that using na.pass produces this behavior? This unanswered question is making me wonder if this might be wrong.

Upvotes: 1

Views: 5421

Answers (1)

Roland
Roland

Reputation: 132706

lmer(like most model functions) can't deal with missing data. To illustrate that:

data(Orthodont,package="nlme")
Orthodont$nsex <- as.numeric(Orthodont$Sex=="Male")
Orthodont$nsexage <- with(Orthodont, nsex*age)
Orthodont[1, 2] <- NA

lmer(distance ~ age + (age|Subject) + (0+nsex|Subject) +
       (0 + nsexage|Subject), data=Orthodont, na.action = na.pass)
#Error in lme4::lFormula(formula = distance ~ age + (age | Subject) + (0 +  : 
#  NA in Z (random-effects model matrix): please use "na.action='na.omit'" or "na.action='na.exclude'"

If you don't want to discard observations with missing data, your only option is imputation. Check out packages like mice or Amelia.

Upvotes: 1

Related Questions