I am studying mixed models and have a doubt about nested random effects..
In the example, we tested subjects variable X and outcome Y and want to see if X is correlated with Y. The data were collected on 8 different mountains in 3 different site (i.e. mountain A was collected on site 1 2 and 3, mountain B site 1 2 and 3, etc). Site 1 of mountain A is not related at all with site 1 of mountain B. Then we want to analyse the relationship Y ~ X controlling for mountain and site.
Since that site and mountain are nested, we created a variable "sample" that is
sample <- factor(mountainRange:site)*
Now, here is my doubt. The course suggest to do the analysis as following
mixed.lmer2 <- lmer(Y~ X + (1|mountain) + (1|sample), data = data)
But I don't understand why we include (1|mountain). I thought I don't need to include it as it is already included in the variable (1|sample)
What I mean is that I would run the analysis as following:
mixed.lmer3 <- lmer(Y~ X + (1|sample), data = data)
Could anyone explain why am I wrong? Thanks
You simply embedded
mountainandsitewithin the same termsample, which makes it nested. Alternatively, you could have doneOR
to represent the same thing. Again, you just did it outside the model formula.
Do see https://stats.stackexchange.com/q/228800/238878 for a more thorough answer.