从这些数据:
UQdata MudUQ Estuary Site
7.00 10.9 NoriPau A
6.00 13.9 NoriPau A
5.00 10.3 NoriPau B
4.00 7.9 Porirua A
4.00 8.3 Porirua A
4.00 8.7 Porirua A
4.00 10.9 NoriPau B
3.00 9.8 Porirua B
3.00 9.8 Porirua B
3.00 11.5 Porirua B
我使用mgcv包装拟合以下GAM模型:
aa2.estuary <- gam(UQdata~s(MudUQ, bs="ps", k=5) + s(Estuary, bs="re"),
family=Gamma(link=log),data=Antho)
问题:我想在Estuary
中添加Site
和Estuary
作为两个随机效果(即s(Estuary ~ Site + Estuary, bs="re")
),但是当我尝试此操作时会抛出此错误:< / p>
aa2.estuary <- gam(UQdata ~ s(MudUQ,bs="ps", k=5) +
s(Estuary~Estuary+Site, bs="re"),
family=Gamma(link=log),data=Antho)
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
In addition: Warning message:
In s(Estuary ~ Estuary + Site, bs = "re") :
number of items to replace is not a multiple of replacement length
非常感谢任何帮助。
mnel,我尝试了你的建议字符串:
> aa1.estuary<-gam(UQdata~s(MudUQ,bs="ps", k=5) + s(Estuary, bs="re") + s(Site, Estuary, bs = 're'),family=binomial, gamma=1,data=Antho)
Error in while (mean(ldxx/(ldxx + ldss)) < 0.4) { :
missing value where TRUE/FALSE needed
有什么想法吗?
答案 0 :(得分:2)
回到原始数据并重命名Sites
与每个河口相关联(见下文):
UQdata MudUQ Estuary Site
7.00 10.9 NoriPau Nori1
6.00 13.9 NoriPau Nori1
5.00 10.3 NoriPau Nori2
4.00 7.9 Porirua Pori1
4.00 8.3 Porirua Pori1
4.00 8.7 Porirua Pori1
4.00 10.9 NoriPau Nori2
3.00 9.8 Porirua Pori2
3.00 9.8 Porirua Pori2
3.00 11.5 Porirua Pori2
包括Site
作为另一种随机效果:
aa2.estuary <- gam(UQdata ~ s(MudUQ,bs="ps", k=5) + s(Estuary, bs="re") + s(Site, bs="re"),family=Gamma(link=log),data=Antho)
并不担心哪个嵌套在哪个内。这会同时处理Site
内部相关性和内部Estuary
相关性。