syntax for nested random effects using gamm or lme in R

梦想的初衷 提交于 2020-05-29 09:58:05

问题


I would like to fit three random effects to a gamm in R, including one that is nested in another.

For independent random effects, the gamm function in the mgcv package allows specification of the random effects using the list syntax from lme, i.e:

model<- gamm(y~s(x), random = list(ran1=~1,ran2=~1), data=data)

This works fine. However, I would like to have 'ran2' nested inside a third variable, 'ran3'. I can't seem to find any examples, for either gamm or lme that show how to nest random effects within the list syntax.

Neither of these work:

model<- gamm(y~s(x), random = list(ran1=~1,ran2/ran3=~1), data=data) #error unexpected '='
model<- gamm(y~s(x), random = list(~1|ran1,~1|ran2/ran3), data=data) #error must be a named list

This runs:

model<- gamm(y~s(x), random = list(ran1=~1,ran3=~ran2), data=data)

but produces warnings about fewer observations than random effects (which shouldn't be the case with my data), so I think that syntax isn't doing what I want.

I suppose a simple option might be to create a version of ran3 that is obligatorily nested in ran2, i.e. each level of ran3 only occurs within a single level of ran2. Would that make gamm recognise the nesting structure?

来源:https://stackoverflow.com/questions/59215853/syntax-for-nested-random-effects-using-gamm-or-lme-in-r

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