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+(1male/songtype), data, REML=TRUE)
The reason for the
songtype
random 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.
Answer
A few points:
 sometimes logtransforming 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

assuming that
zone
in your model is equivalent to “site” in your verbal description (i.e. “site A vs. site B”, is coded in thezone
variable in your data), you can use theweights
argument innlme::lme
to add heteroscedasticity (withinindividual variability) to the model:a < lme(song_length~factor(zone)+date, random=~1male/songtype, data, method="REML", weights=varIdent(~zone))
You can do this a little bit more awkwardly with
lmer
by adding an observationlevel 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+ (1male/songtype) + (zonedummy1obs), data, REML=TRUE, control=lmerControl(check.nobs.vs.nRE = "ignore", check.nobs.vs.nlev = "ignore"))
You can do a similar thing for the amongbird variation by adding a term of the type
(zonedummy1male)
; this adds an additional amongmale variance term only in site B (you may have to use additional arguments tolmerControl
to override some errors).
Attribution
Source : Link , Question Author : Diego Gil , Answer Author : amoeba