gpt4 book ai didi

r - 在因子 : GAM 内添加两个随机效应

转载 作者:行者123 更新时间:2023-12-04 04:44:53 47 4
gpt4 key购买 nike

从这个数据:

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)

问题:我想加 EstuarySiteEstuary作为两个随机效应(即 s(Estuary ~ Site + Estuary, bs="re") ),但是当我尝试这样做时,它会引发此错误:
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

有什么想法吗?

最佳答案

通过返回原始数据并重命名 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相关性。

关于r - 在因子 : GAM 内添加两个随机效应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18348897/

47 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com