specifying multiple separate random effects in nlme

筅森魡賤 提交于 2021-01-24 07:17:28

问题


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?


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!