[R-sig-ME] graphing fixed effects from mixed effects model

Ben Bolker bbolker at gmail.com
Wed Apr 4 23:25:02 CEST 2012


jude girard <jude.girard at ...> writes:

> 
> I feel like this must be a common problem, but I can’t find any
> information on how to graph the results of my mixed effects model.
> 
> I am trying to predict insect biomass from weed cover and month.  I
> have 9 pairs of organic and conventional fields; each field has a
> unique site id.  In each field, insect biomass weed cover were
> measured in june and july.  So my model is
> 
> model<lme(biomass~weed.cover+month, data=weeds, random=~1|pair/site)
> 
> I would like to plot a graph showing the raw data, together with two
> lines, one showing the predicted relationship between biomass and weed
> cover in June and one showing the predicted relationship in July.  I’m
> not interested in showing the slopes for the individual sites; this is
> included in the model only to account for the longitudinal nature of
> the design, not because I am interested in this variation.
> 
> So, is there some way to calculate and average slope across sites in
> each month, or do I have to pick one site to use as a reference and
> just graph the result for that site?  And if so, are there any
> guidelines for which site to use as the reference?
> 

   I would do something like this:

predframe <- with(weeds,expand.grid(month=levels(month),
                weed.cover=seq(min(weed.cover),max(weed.cover),25))
predframe$biomass <- predict.lme(model,level=0,newdata=predframe)
then I would be tempted to use ggplot:

library(ggplot2)
ggplot(weeds,aes(x=weed.cover,y=biomass,colour=month))+
   geom_point()+
   geom_line(data=predframe)

  This plots the data and superimposes the predicted values.

You might also get most of the way there via

  plot(augPred(model,level=0))

the 'level' argument specifies that you want to predict at
the population level (i.e. ignoring site-to-site variation)




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