[R-sig-ME] plotting residuals vs. fitted values by group

Ben Bolker bbolker at gmail.com
Tue Jan 18 19:21:55 CET 2011


On 11-01-18 01:16 PM, Rachel Cohen wrote:
> Hi, I am quite new to using R and am currently trying to plot the
> residuals vs. fitted values by group, taken from an lmer model within
> lme4_0.999375-36.  The model i'm using is:
> 
> mod5<-lmer((centre.log.mass)~centre.log.dbh+centre.log.height+(1+centre.log.height|species_site),REML=F)
> 
> 
> I have tried:
> plot(mod5, resid(.)~fitted(.)|species_site)
> 
> but get the following error message:
> 
> Error in xy.coords(x, y, xlabel, ylabel, log) :
>   'x' and 'y' lengths differ
> 
> I'm not sure what this means?  I have managed to plot the overall model
> residuals vs. fitted values by using:
> 
> fit<-fitted(mod5)
> res<-resid(mod5)
> plot(fit,res, main="Model V Residuals vs. Fitted Mass", ylab="Ln
> Residual", xlab="Ln Fitted Mass")

  I believe your problem is that this way of plotting the results will
only work if you include the data frame from which the variables are
taken as the data= argument in your lmer call, instead of having them
lying around in the global workspace.  Give that a try.
   (Reproducible examples are always appreciated ...)

  Ben Bolker




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