简体   繁体   中英

specifying multiple separate random effects in nlme

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 animal
  • Length : length of the animal
  • Year
  • Month (nested within Year ).

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM