问题
I am analysing some whale tourism data and am trying to construct linear mixed effect models in the nlme
package to see if any of my explanatory variables affect encounter time between whales and tourists. (I am also open to running this model in lme4
.)
My variables are:
mins
: encounter time (response variable)Id
: individual whale ID (random effect)Vessel
: vessel Id (random effect)Sex
: sex of the animalLength
: length of the animalYear
Month
(nested withinYear
).
So my random variables are Id
and Vessel
and I also have Year
and Month
as nested random effects.
I have come up with the following:
form1 <- formula(Min ~ length + Sex+ Encounter)
model1 <- lme(form1,
random = list(Id = ~1,
Vessel = ~1,
Year=~1,
Month = ~1), data=wsdata, method="ML")
But all my random effects become nested within Id
.
Is there any way I can define Id
and Vessel
as separate random effects and Year
and Month
as nested random effects?
回答1:
In general it's much easier to specify crossed (what you mean by "separate", I think) random effects in lme4
, so unless you need models for temporal or spatial autocorrelation or heteroscedasticity (which are still easier to achieve with nlme
), I would go ahead with
library(lme4)
fit <- lmer(mins ~ Length + Sex+ (1|Id) + (1|Vessel) +
(1|Year/Month), data=wsdata, REML=FALSE)
A few other comments:
- what is
encounter
? it was in your formula but not in your description of the data set - it seems quite likely that encounter times (a duration of encounters?) would be skewed, in which case you might want to log-transform them.
来源:https://stackoverflow.com/questions/36398100/specifying-multiple-separate-random-effects-in-nlme