# no difference in predict between lm and lmer

I have read several posts here on CV, in which mixed model data were plotted this way (using cake dataset):

library(lme4)
library(ggplot2)
mod <- lmer(angle ~ recipe + temp + (1|replicate), data=cake)
newdat <- expand.grid(recipe=unique(cake$$recipe), temp=c(min(cake$$temp),
max(cake\$temp)))
lmer.pred <- predict(mod, re.form=~0, newdata=newdat)

lmer.plot <- ggplot(cake, aes(x=temp, y=angle, color=recipe)) + geom_line(data=newdat, aes(y=lmer.pred))


However, recently I realized that we could get the same values with a lm model:

mod2 <- lm(angle ~ recipe + temp, data = cake)
lm.pred <- predict(mod2, newdata = newdat)
lm.plot <- ggplot(cake, aes(temp, angle, color = recipe)) + geom_line(data = newdat, aes(y=lm.pred))


My question is whether lmer.plot is an accurate illustration of the linear mixed model? The cake data contains repeated measures (recipe) so mod2 and lm.plot seems wrong, and, by extension, lmer.plot would also be wrong. However, several posts suggest using plots like lmer.plot to illustrate linear mixed model data, so I'm confused.

For the random-effect model you made the predictions with re.form=~0 so you've set random effects to zero, in such a case the only part that you consider is angle ~ recipe + temp, i.e. the same as in fixed-effects model. If you look at summary(mod) vs summary(mod2) you'll see that the fixed effects parameters are nearly the same, hence nearly the same predictions. Your random effects model assumes random intercepts for replicate's so the difference between the models would be just that the regression lines for each replicate would be "shifted" by the intercept. To see the difference between models, show the regression lines for different recipe's.
• Thanks for your answer @Tim, but then the question is why is it common to represent mixed model data in this way? Isn't mod2 plainly wrong, since it violates assumptions of linear models? But it is not uncommon to see the likes of lmer.plot suggested here in CV. Feb 28, 2022 at 23:30
• Could you show me how you would illustrate mod? Feb 28, 2022 at 23:32
• @locus apparently you saw people showing plots with zeroed-out random effects because this was what they intended to show. Here you zero-out random effects and wonder why you don't see their contribution in the plot: you don't see it, because you used plot that does so. How to plot random effects as well? Just make newdata have all the columns as your data and don't use re.form=~0.
• As about mod2 being "wrong": the only difference between the two models is that mod assumes additional source of variability between replicate's; if you don't account it, you assume that there is single intercept and all the variability is just residual variance. The second model ignores important source of variability, but is not "wrong". If you look at the diagnositc plots plot(mod2), you'd see that they look rather ok.
• what I meant by "wrong" is that I thought (fixed-effects) linear models required independent observations, which isn't the case here since we have a repeated measures (recipe). So, for all intents and purposes, mod2 is statistical inaccurate, isn't it? Mar 1, 2022 at 10:57