[R-sig-ME] coding for an interaction

Andrew Dolman andydolman at gmail.com
Sun Mar 27 13:20:08 CEST 2011


If time is being modelled as a continuous variable, i.e. you are
looking at a continuous change in x over time, then

mod2=lmer(x~time+(1|site),  data=mydata)
mod3=lmer(x~time+(time|site),  data=mydata)

is probably what you want.

And you can test whether time interacts with site (the slope for time
differs between sites) by a likelihood ratio test

anova(mod2, mod3)



andydolman at gmail.com



On 27 March 2011 07:10, Saang-Yoon Hyun <shyunuw at gmail.com> wrote:
> Hi.
> I have one fixed and one random effect.  However, I cannot find how to code
> their interaction term.  For example, the data have the following two
> columns: site as random effect, and time as fixed effect.
>
> mod1=lmer(x~(1|site),  data=mydata);       #site: random effect;
> mod2=lmer(x~time+(1|site),  data=mydata);    #time: fixed effect;
>
> These above codes work.  But I wonder how you do code for their interaction
> term.  I tried to do several things (e.g., +time*(1|site), +(1|time*site),
> ... etc.), but all failed.
>
> Please give me some tips.  Thank you,
> Saang-Yoon
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>




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