[R-sig-ME] behavior of na.action = na.exclude using lmer in lme4 1.0-5 inconsistent with lm and with older versions of lme4

Ben Bolker bbolker at gmail.com
Wed Oct 30 19:50:48 CET 2013


David Kane <dave.kane at ...> writes:

> 
> Consider a simple example:
> 
> > set.seed(1)> df <- data.frame(x = c(rnorm(7), NA),
>  y = rep(c("A", "B"), 4))> length(fitted(lm(data =
> df, x ~ y, na.action = na.exclude)))[1] 8
> 
> This behaves as I would expect. Although there is no fitted value for
> the 8th observation, because x is NA for that row, the fitted values
> are "padded" with NA so that they are the same length as the number of
> rows in the input data frame df, which is very handy. But calling
> na.action = na.exclude no longer has the same effect in lme4.
> 
> > length(fitted(lmer(data = df, x ~ (1 | y), 
> na.action = na.exclude)))[1] 7
> 
> I am fairly certain that, in older versions of lme4, the length would
> be 8, with the last value being NA, just as it is with lm().
> 
> How can I get lmer to behave in the same way as lm --- padding the fitted
> vector with NAs (in the appropriate locations) so that it is the same
> length as the number of rows in the input data frame.

  Just for the record: as stated at

http://stackoverflow.com/questions/19668783/
  behavior-of-na-action-na-exclude-using-lmer-in-lme4-1-0-5-
    inconsistent-with-lm/19668855#19668855

(broken URL to make Gmane happy), you can just use predict(model)
rather than fitted(model).

  This is fixed in the Github development (1.1-1) version, may
get pulled into the patched (1.0-6) branch, but seems low priority
since the fix is so easy ...


  Ben Bolker



More information about the R-sig-mixed-models mailing list