在nlme中指定多个单独的随机效果 [英] specifying multiple separate random effects in nlme

查看:109
本文介绍了在nlme中指定多个单独的随机效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在分析一些鲸鱼旅游数据,并试图在 nlme 包中构建线性混合效应模型,以查看我的解释变量是否会影响鲸鱼和游客之间的相遇时间.(我也愿意在 lme4 中运行此模型.)

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.)

我的变量是:

  • mins :遇到时间(响应变量)
  • Id :单独的鲸鱼ID(随机效应)
  • 船只:船只ID(随机效应)
  • 性别:动物的性别
  • 长度:动物的长度
  • 年份
  • Month (嵌套在 Year 年内).
  • 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).

所以我的随机变量是 Id Vessel ,我还有 Year Month 作为嵌套的随机效果.

So my random variables are Id and Vessel and I also have Year and Month as nested random effects.

我提出了以下建议:

form1 <- formula(Min ~ length + Sex+ Encounter)
 model1 <- lme(form1, 
              random = list(Id = ~1, 
                            Vessel = ~1, 
                            Year=~1,
                            Month = ~1), data=wsdata, method="ML")

但是我所有的随机效果都嵌套在 Id 中.

But all my random effects become nested within Id.

有什么方法可以将 Id Vessel 定义为单独的随机效果,以及将 Year Month 定义为嵌套的随机效应?

Is there any way I can define Id and Vessel as separate random effects and Year and Month as nested random effects?

推荐答案

通常,在中指定 crossed (我认为这是分离"的意思)要容易得多.lme4 ,因此除非您需要用于时间或空间自相关或异方差的模型(使用 nlme 仍然更容易实现),否则我将继续

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)

其他一些评论:

  • 遇到是什么?它在您的公式中,但不在您对数据集的描述中
  • 相遇时间(相遇持续时间?)似乎很可能会出现偏差,在这种情况下,您可能希望对它们进行日志转换.
  • 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.

这篇关于在nlme中指定多个单独的随机效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆