[R-sig-ME] interaction and nested notation in lmer

Ben Bolker bbolker at gmail.com
Wed Sep 23 15:57:38 CEST 2015

On Mon, Sep 21, 2015 at 6:24 PM, Mashitah Jusoh <mashitahj at gmail.com> wrote:
> Hi,
> I would like to ask about the notation to indicated nested and interaction
> when using lmer function.
> Here is my experiment look like:
> I have 95 genotypes with 2 replications that were conducted in two years.
> Some of the observation were missing, making the dataset unbalance. So, I
> decided to use lmer function to fit the data to get the variance component
> and will treat all components as random. The model that I am going to fit
> is:
> Y=mean + year + genotype + rep (nested in year)  + genotype*year + error
> I am wondering how to write the command for nested and interaction term in
> R using lmer function for this model? As far as I search in the internet,
> the command for nested and interaction seems like using similar notation,
> for example (1|year:rep) to show rep is nested within year (for random
> effect) the same notation is used to indicate the interaction (for other
> variables, such as genotype:year). Correct me if i am wrong. And, can you
> give some clarification about this and also how lmer/ R works with
> interaction and nested data?

  If you have samples from only 2 years, it's not going to be
particularly practical to fit
a model with year as random effect.  Setting that aside for the moment,
the distinction between (1|year/rep) and (1|year:rep) is that the
former expands to
(1|year) + (1|year:rep)  (i.e., effect of year and effect of rep
within year), while the latter
is just rep within year -- i.e. no main effect of year.

  However, nesting syntax doesn't really doesn't work well for fixed
effects (partly
due to the way R handles the formulae, and partly for conceptual reasons) -- in
your model, year:rep would give 4 fixed-effect parameters, as would
or year*rep (two ways of specifying crossed effects)

  I think I would recommend

Y  ~ 1 + year*rep + (1|genotype) + (1|genotype:year)

With unbalanced data, it may be hard to get a unique decomposition of
variance ...

 Ben Bolker

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