[R-sig-ME] need help with predicted values from lmer with newdata

Ben Bolker bbolker at gmail.com
Sat Jun 23 13:27:56 CEST 2012


Joshua Wiley <jwiley.psych at ...> writes:

> 
> Hi Paul,
> 
> I think this may be a bug in predict.merMod.  It is not terribly
> elegant, but I suggest changing line 102 from:
> 
> re_new <- unlist(re_List[m])
> 
> to
> 
> re_new <- as.vector(do.call("rbind", re_List[m]))
> 
> I believe the issue with the current is that the random effects are
> unlisted which essentially 'stacks' the vector, so you have the random
> effects one at a time by effect, not by level (i.e., all intercepts,
> then all slopes).  Later this is post multiplied by a matrix that is
> sorted by level, the dimensions are correct so the matrices multiply
> fine, but the results are not what I believe was intended.
> 
> I cannot see a way to add a patch to R-forge or submit a bug report so
> I cced Doug on this.

  Thanks Josh. This should be fixed now.

 It turned out had to re-vamp things a bit to fix this
in a general and robust way.  I'm not quite sure how this slipped through
the cracks, since I *thought* that I had tested predict() with a multi-response
case (i.e. the sleepstudy data) and gotten sensible answers.  However,
I was testing with graphical output and not with explicit stopifnot() tests,
so it's possible that it was working originally and that I subsequently
broke something ...

  Paul, would you be willing to generate a trimmed-down version of your
example that simply generates multi-trait data?

  For future reference, the lme4 bug tracker lives at:

https://r-forge.r-project.org/tracker/?atid=298&group_id=60&func=browse

  In addition, any advice on how to improve ?predict.merMod ("I can't
tell what those numbers are. Can't be sure from ?predict.merMod") would
be welcome ...

  Ben Bolker



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