2

从这个数据:

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,它会抛出这个错误:Estuarys(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

有任何想法吗?

4

1 回答 1

3

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

于 2013-08-21T23:05:32.023 回答