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.