2

I am trying to apply a linear mixed effects model using the R package 'lme4'. I am wondering how I can incorporate two random effects in my model rather than just one.

I have a dataset where I am trying to asses differences in decay rate of DNA and RNA of multiple species across time using two distinct markers (18S and COI). My fixed effects are the gene (DNA_COI, RNA_COI, DNA_18S, RNA_18S), time, and the interaction between gene and time. My random effects are the individual mesocosms, and the species themselves. So far, I have the following equation:

model <- lmer(log(copies) ~ 0 + gene + time + gene:time + (1|mesocosm), data)

However, I am not interested in whether the decay rates of different species differs over time; I am only interested in how the decay rates of my genes differ from each other over time. In this case, would species be characterized as a random effect? If so, is there a way to include another random effect in the equation (species)?

A bit of explanation into my data structure: I have 3 mesocosms that were sampled across 7 time points for DNA and RNA using 2 markers (18S and COI). Those markers detected copies of DNA and RNA belonging to multiple species over time (thus allowing me to generate decay curves for each species detected). These species can be detected in multiple mesocosms (e.g. species A is detected in mesocosms 1 and 2, etc.). Does this mean species as a random effect is crossed or nested?

I hope this is clear...

Thanks in advance!

1 Answers1

2

That depends on whether species and mesocosm are crossed random effects or whether they are nested.

If they are crossed you can simply add species:

model <- lmer(log(copies) ~ 0 + gene + time + gene:time + 
                           (1|mesocosm) + (1|species), data)

If species is nested in mesocosm, it would look like this:

model <- lmer(log(copies) ~ 0 + gene + time + gene:time + 
                           (1|mesocosm/species), data)

I am not sure whether this is possible given your data since we don't know anything about your data structure.

In any case, also have a look here (a must have bookmark when dealing with mixed models): https://bbolker.github.io/mixedmodels-misc/glmmFAQ and specifically for your question: https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html#model-specification

Stefan
  • 6,431
  • Thank you Stefan! I am a bit confused whether my data should be treated as crossed, nested or both. A bit of an explanation: Several species were detected using my gene in my mesocosms. Since the mesocosms were replicates, it is possible that the same species was detected in multiple mesocosms (e.g. species A occurs in both mesocosm 1 and 2, for example). Would species be crossed or nested in this case? – ramateur Apr 11 '22 at 15:38
  • @ramateur If you look into the link in my answer you will find this section: https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html#nested-or-crossed Also have a look at this nice answer: https://stats.stackexchange.com/a/228814/32477 – Stefan Apr 11 '22 at 16:08
  • 1
    Awesome! That was very helpful. Thank you! – ramateur Apr 11 '22 at 16:11