简体   繁体   English

为什么嵌套随机效果在 nlme 中有效,但在 lme4 中无效?

[英]Why do nested random effects work in nlme but not work in lme4?

A glimse of my data我的数据一瞥

I want to see the effect of M on Com using linear mixed model, with M as the fixed effect and year nested in plot as random effect.我想使用线性混合 model 来查看 M 对 Com 的影响,其中 M 作为固定效应,而嵌套在 plot 中的年份作为随机效应。 There is no problem if I use lme in package 'nlme'.如果我在 package 'nlme' 中使用 lme 没有问题。

fit <- lme(Com ~ M + random = ~ 1|plot/year, data)

But it didn't work in lmer in package 'lme4'.但它在 package 'lme4' 的 lmer 中不起作用。

fit <- lmer(Com ~ M + (1|plot/year), data)

# Error: number of levels of each grouping factor must be < number of observations

However, it works if I only include plot or year in the random effect.但是,如果我只在随机效应中包含 plot 或年份,它就会起作用。 Is there any way to solve it?有什么办法可以解决吗?

fit <- lme(Com ~ M + random = ~ 1|plot, data)
fit <- lme(Com ~ M + random = ~ 1|year, data)

nlme is well known to deal with nested random effects and not with interactions whereas on the contrary lme4 deals well with interactions and does not suits well for some things nlme is good for.众所周知,nlme 可以处理嵌套的随机效应,而不是交互,而相反,lme4 可以很好地处理交互,并且不适合 nlme 擅长的某些事情。 I think lme4 provides variance component models only whereas nlme allows correlations between observations.我认为 lme4 仅提供方差分量模型,而 nlme 允许观察之间的相关性。 Maybe if your nested structure lies within your data you could try fit <- lmer(Com ~ M + (1:plot) + (1|year:plot), data = t) , assuming that years are nested within plots.也许如果您的嵌套结构位于您的数据中,您可以尝试fit <- lmer(Com ~ M + (1:plot) + (1|year:plot), data = t) ,假设年份嵌套在图中。

fit <- lmer(Com ~ M + (1:plot) + (1|year:plot), data = t) and fit <- lmer(Com ~ M + (1:plot) + (1|plot:year), data = t) are equivalent but the latter formula may be more consistant. fit <- lmer(Com ~ M + (1:plot) + (1|year:plot), data = t)fit <- lmer(Com ~ M + (1:plot) + (1|plot:year), data = t)是等价的,但后一个公式可能更一致。 You could also compare the results of this command with fit <- lme(Com ~ M, random = ~ 1|plot/year, data) and see if you find the same variance components.您还可以将此命令的结果与fit <- lme(Com ~ M, random = ~ 1|plot/year, data)进行比较,看看是否找到相同的方差分量。 I think it should work.我认为它应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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