[R] Testing an interaction with a random effect in lmer

Ben Bolker bbolker at gmail.com
Tue Dec 14 03:45:59 CET 2010


Reed, Nicola <nr232 <at> exeter.ac.uk> writes:

> I was hoping to get some advice regarding the testing of interactions,
> when one factor is modelled as a
> random effect...
> I have a model with binomial error structure where the response 
> variable is the proportion of time spent at
> the main sett (animals were tracked for 28 consecutive days 
> in each season, and were recorded either at the
> main sett or an outlier sett, so the response variable is a number out of 28).
> Animals from 9 social groups were tracked for 28 days in each of 
> the four seasons of the year.
> Thus, in my model, 'individual' nested within 'social group' 
> are my random error terms.
> 
> model<-lmer(binom~season+(1|group/individual),binomial,data=data1)
> 
> Group explains some variation in the sett use patterns, 
> and what i was wanting to test and display was an
> interaction between season and group, as the raw data suggests 
> that different groups may behave
> differently in different seasons. Is there a way to do this in 
> the lmer package?
> 
> When i put it in directly:
> 
> model<-lmer(binom~season*group+(1|group/individual),binomial,data=data1)
> 
> I get an error messgae:
> Warning message:
> In mer_finalize(ans) : gr cannot be computed at initial par (65)
> 
  I think you want 

 binom~season + (season|group) + (1|individual)

[assuming that individuals are coded uniquely, i.e. you don't have
an 'individual A' in each group]

  If you had enough data to consider testing variation in seasonality
among individuals, you could try

  binom~season + (season|group/individual)


  was the switch from 'individual' above to 'badger' below
a slip?

  Thanks for the clear description.

 Ben Bolker



More information about the R-help mailing list