I would like to test for differences in variation, not in means, between two sites. By looking at a boxplot of my data I see that bird song in one site look much more variable in length than in another site, and also it seems there is more variation within individuals in one site than in the other. In other words, more variation within and between individuals (or so it looks..).
I’m fitting this random model to test for differences:
a <- lmer (song_length~factor(zone)+date+(1|male/songtype), data, REML=TRUE)
The reason for the
songtyperandom factor is that birds have different types of songs, and I take measurements of 4 songs per song type per bird.
The question would be: is there more inter- and/or intraindividual variation in site A than in site B?
Also, if there is indeed heteroscedasticity, the model is wrong, and I would need to account for that. But that is a second question I guess.
A few points:
- sometimes log-transforming data can clear up heteroscedasticity nicely; this would be my first attempt, especially as you have a positive responses variable (song length), so we would expect it to be skewed if the coefficient of variation is large
zonein your model is equivalent to “site” in your verbal description (i.e. “site A vs. site B”, is coded in the
zonevariable in your data), you can use the
nlme::lmeto add heteroscedasticity (within-individual variability) to the model:
a <- lme(song_length~factor(zone)+date, random=~1|male/songtype, data, method="REML", weights=varIdent(~zone))
You can do this a little bit more awkwardly with
lmerby adding an observation-level variable and using a dummy variable to set its value to zero in the first site:
data <- transform(data, obs=factor(1:nrow(data)), zonedummy=as.numeric(zone=="B")) a <- lmer(song_length~factor(zone)+date+ (1|male/songtype) + (zonedummy-1|obs), data, REML=TRUE, control=lmerControl(check.nobs.vs.nRE = "ignore", check.nobs.vs.nlev = "ignore"))
You can do a similar thing for the among-bird variation by adding a term of the type
(zonedummy-1|male); this adds an additional among-male variance term only in site B (you may have to use additional arguments to
lmerControlto override some errors).