我试图分析一些可视化的生物横断面数据,以生成一个生境分布模型。一旦有机体被发现,它们就会被跟踪,在给定的时间间隔内收集点数据。由于这些“跟随”之间的自相关性,我希望使用类似于Pirotta等人的GEE方法。2011年,使用包'yags‘和’样条‘(http://www.int-res.com/abstracts/meps/v436/p257-272/)。他们的R脚本显示在这里(http://www.int-res.com/articles/suppl/m436p257_supp/m436p257_supp1-code.r)。我使用这段代码的成功程度有限,而且多个问题的模型无法收敛。
以下是我的数据结构:
> str(dat2)
'data.frame': 10792 obs. of 4 variables:
$ dist_slag : num 26475 26340 25886 25400 24934 ...
$ Depth : num -10.1 -10.5 -16.6 -22.2 -29.7 ...
$ dolphin_presence: int 0 0 0 0 0 0 0 0 0 0 ...
$ block : int 1 1 1 1 1 1 1 1 1 1 ...
> head(dat2)
dist_slag Depth dolphin_presence block
1 26475.47 -10.0934 0 1
2 26340.47 -10.4870 0 1
3 25886.33 -16.5752 0 1
4 25399.88 -22.2474 0 1
5 24934.29 -29.6797 0 1
6 24519.90 -26.2370 0 1下面是my块变量的摘要(指示每个块中存在自相关的组数)
> summary(dat2$block)
Min. 1st Qu. Median Mean 3rd Qu. Max.
1.00 39.00 76.00 73.52 111.00 148.00然而,我想使用' gamm4‘包,因为我更熟悉Simon教授的包和函数,而且gamm4可能是最合适的。重要的是要注意,模型有一个二元响应(生物体在横断面上的存在),因此我认为gamm4比gamm更合适。在gamm中,它提供了下列因素内的自相关示例:
## more complicated autocorrelation example - AR errors
## only within groups defined by `fac'
e <- rnorm(n,0,sig)
for (i in 2:n) e[i] <- 0.6*e[i-1]*(fac[i-1]==fac[i]) + e[i]
y <- f + e
b <- gamm(y~s(x,k=20),correlation=corAR1(form=~1|fac))下面是我为我的数据集使用的代码
b <- gamm4(dolphin_presence~s(dist_slag)+s(Depth),random=(form=~1|block), family=binomial(),data=dat)但是,通过检查输出(概要(b$gam),特别是摘要(b$mer)),我要么不确定如何解释结果,要么不相信组内的自相关性正在被考虑在内。
> summary(b$gam)
Family: binomial
Link function: logit
Formula:
dolphin_presence ~ s(dist_slag) + s(Depth)
Parametric coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -13.968 5.145 -2.715 0.00663 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Approximate significance of smooth terms:
edf Ref.df Chi.sq p-value
s(dist_slag) 4.943 4.943 70.67 6.85e-14 ***
s(Depth) 6.869 6.869 115.59 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
R-sq.(adj) = 0.317glmer.ML score = 10504 Scale est. = 1 n = 10792
>
> summary(b$mer)
Generalized linear mixed model fit by the Laplace approximation
AIC BIC logLik deviance
10514 10551 -5252 10504
Random effects:
Groups Name Variance Std.Dev.
Xr s(dist_slag) 1611344 1269.39
Xr.0 s(Depth) 98622 314.04
Number of obs: 10792, groups: Xr, 8; Xr.0, 8
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
X(Intercept) -13.968 5.145 -2.715 0.00663 **
Xs(dist_slag)Fx1 -35.871 33.944 -1.057 0.29063
Xs(Depth)Fx1 3.971 3.740 1.062 0.28823
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
X(Int) X(_)F1
Xs(dst_s)F1 0.654
Xs(Dpth)Fx1 -0.030 0.000
> 如何确保自相关确实在“块”变量的每个唯一值中得到考虑?最简单的解释“摘要(b$mer)”输出的方法是什么?
结果确实不同于使用相同变量和参数的普通gam (package ),而不使用“correlation=.”术语,表示正在发生不同的事情。
但是,当我为相关项(季节)使用不同的变量时,我得到了相同的输出:
> dat2 <- data.frame(dist_slag = dat$dist_slag, Depth = dat$Depth, dolphin_presence = dat$dolphin_presence,
+ block = dat$block, season=dat$season)
> head(dat2)
dist_slag Depth dolphin_presence block season
1 26475.47 -10.0934 0 1 F
2 26340.47 -10.4870 0 1 F
3 25886.33 -16.5752 0 1 F
4 25399.88 -22.2474 0 1 F
5 24934.29 -29.6797 0 1 F
6 24519.90 -26.2370 0 1 F
> summary(dat2$season)
F S
3224 7568
> b <- gamm4(dolphin_presence~s(dist_slag)+s(Depth),correlation=corAR1(1, form=~1 | season), family=binomial(),data=dat2)
> summary(b$gam)
Family: binomial
Link function: logit
Formula:
dolphin_presence ~ s(dist_slag) + s(Depth)
Parametric coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -13.968 5.145 -2.715 0.00663 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Approximate significance of smooth terms:
edf Ref.df Chi.sq p-value
s(dist_slag) 4.943 4.943 70.67 6.85e-14 ***
s(Depth) 6.869 6.869 115.59 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
R-sq.(adj) = 0.317glmer.ML score = 10504 Scale est. = 1 n = 10792
> summary(b$mer)
Generalized linear mixed model fit by the Laplace approximation
AIC BIC logLik deviance
10514 10551 -5252 10504
Random effects:
Groups Name Variance Std.Dev.
Xr s(dist_slag) 1611344 1269.39
Xr.0 s(Depth) 98622 314.04
Number of obs: 10792, groups: Xr, 8; Xr.0, 8
Fixed effects:
Estimate Std. Error z value Pr(>|z|)
X(Intercept) -13.968 5.145 -2.715 0.00663 **
Xs(dist_slag)Fx1 -35.871 33.944 -1.057 0.29063
Xs(Depth)Fx1 3.971 3.740 1.062 0.28823
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Correlation of Fixed Effects:
X(Int) X(_)F1
Xs(dst_s)F1 0.654
Xs(Dpth)Fx1 -0.030 0.000
> 我只想确保它正确地允许“块”变量的每个值之间的关联。我如何制定模型,说自相关可以存在于每个块的单个值中,但假设块之间是独立的?
另外,对于较大的模型(变量比2多),在模型完成后,我还会收到以下警告消息:
Warning message:
In mer_finalize(ans) : false convergence (8)发布于 2012-05-03 14:44:03
gamm4构建在lme4之上,这使得而不是允许使用correlation参数(与mgcv::gamm下面的nlme包形成对比)。mgcv::gamm确实处理二进制数据,尽管它使用的是PQL,这通常不如gamm4/lme4中的Laplace/GHQ近似精确。这是不幸的(!)您没有收到警告,告诉您忽略了gamm4).lme4的correlation参数的简单示例时,我确实得到了一个警告,但额外的参数可能在mgcv::gamm).nlme中编码相关结构的方式(因此在mgcv::gamm).mcgv::gamm,并建议,如果有可能的话,您可以在一些已知结构的模拟数据上进行试验(或者使用上述补充材料中提供的数据集,看看您的替代approach).r-sig-mixed-models@r-project.org可能有更多的混合模型专家。
https://stackoverflow.com/questions/10432671
复制相似问题