热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在gamm4R包中导电胶?-conductingGAM-GEEingamm4Rpackage?

Iamtryingtoanalyzesomevisualtransectdataoforganismstogenerateahabitatdistributionmod

I am trying to analyze some visual transect data of organisms to generate a habitat distribution model. Once organisms are sighted, they are followed as point data is collected at a given time interval. Because of the autocorrelation among these "follows," I wish to utilize a GAM-GEE approach similar to that of Pirotta et al. 2011, using packages 'yags' and 'splines' (http://www.int-res.com/abstracts/meps/v436/p257-272/). Their R scripts are shown here (http://www.int-res.com/articles/suppl/m436p257_supp/m436p257_supp1-code.r). I have used this code with limited success and multiple issues of models failing to converge.

我正试图分析一些生物的视觉横断面数据,以建立一个栖息地分布模型。一旦发现了生物,在给定的时间间隔内收集点数据时,就会跟踪它们。由于这些“接下来”之间的自相关,我希望使用与Pirotta等人类似的GAM-GEE方法,使用包'yags'和'splines' (http://www.int-res.com/abstracts/meps/v436/p257-272/)。它们的R脚本如下所示(http://www.int-res.com/articles/suppl/m436p257_supp/m436p257_supp1-code.r)。我使用这段代码的成功程度有限,而且模型的多个问题也不一致。

Below is the structure of my data:

以下是我的数据结构:

> 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

Here is the summary of my block variable (indicating the number of groups for which autocorrelation exists within each block

这是块变量的摘要(指示每个块中存在自相关的组的数量)

> summary(dat2$block)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   1.00   39.00   76.00   73.52  111.00  148.00

However, I would like to use the package 'gamm4', as I am more familiar with Professor Simon Wood's packages and functions, and it appears gamm4 might be the most appropriate. It is important to note that the models have a binary response (organism presence of absence along a transect), and thus why I think gamm4 is more appropriate than gamm. In the gamm help, it provides the following example for autocorrelation within factors:

但是,我更喜欢使用“gamm4”这个包,因为我更熟悉Simon Wood教授的包和函数,看来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))

Following this example, the following is the code I used for my dataset

在这个示例之后,下面是我为数据集使用的代码

b <- gamm4(dolphin_presence~s(dist_slag)+s(Depth),random=(form=~1|block),  family=binomial(),data=dat)

However, by examining the output (summary(b$gam)) and specifically summary(b$mer)), I am either unsure of how to interpret the results, or do not believe that the autocorrelation within the group is being taken into consideration.

然而,通过检查输出(summary(b$gam)和特定的summary(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
> 

How do I ensure that autocorrelation is indeed being accounted for within each unique value of the "block" variable? What is the simplest way to interpret the output for "summary(b$mer)"?

如何确保在“块”变量的每个惟一值中确实存在自相关?解释“摘要”输出的最简单方法是什么?

The results do differ from a normal gam (package mgcv) using the same variables and parameters without the "correlation=..." term, indicating that something different is occurring.

结果与使用相同变量和参数的普通gam (package mgcv)不同,没有“correlation=…”项,这表明发生了一些不同的事情。

However, when I use a different variable for the correlation term (season), I get the SAME output:

但是,当我对相关项(季节)使用不同的变量时,得到的输出是相同的:

> 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
> 

I just want to make sure it is correctly allowing for correlation within each value for the "block" variable. How do I formulate the model to say that autocorrelation can exist within each single value for block, but assume independence among blocks?

我只是想确保它正确地允许“块”变量的每个值之间的相关性。如何构造模型来表示块的每个单独值中都可以存在自相关,而假定块之间是独立的?

On another note, I am also receiving the following warning message after model completion for larger models (with many more variables than 2):

另一方面,在模型完成后,我也收到了以下警告信息(有更多的变量多于2):

Warning message:
 In mer_finalize(ans) : false convergence (8)

1 个解决方案

#1


3  

  • gamm4 is built on top of lme4, which does not allow for a correlation parameter (in contrast to the nlme, package, which underlies mgcv::gamm). mgcv::gamm does handle binary data, although it uses PQL, which is generally less accurate than Laplace/GHQ approximations as in gamm4/lme4. It is unfortunate (!!) that you're not getting a warning telling you that the correlation argument is being ignored (when I try a simple example using a correlation argument with lme4, I do get a warning, but it's possible that the extra argument is getting swallowed somewhere inside gamm4).
  • gamm4构建在lme4之上,lme4不允许有相关参数(与mgcv: gamm下面的nlme包相反)。gamm确实处理二进制数据,尽管它使用PQL,这通常比gamm4/lme4中的拉普拉斯/GHQ近似更不准确。不幸的是(!!)您没有得到一个警告,告诉您相关参数正在被忽略(当我尝试使用一个使用lme4的相关性参数的简单示例时,我确实得到了一个警告,但可能额外的参数正在gamm4内部的某个地方被吞掉)。
  • Your desired autocorrelation structure ("autocorrelation can exist within each single value for block, but assume independence among blocks") is exactly the way correlation structures are coded in nlme (and hence in mgcv::gamm).
  • 您想要的自相关结构(“自相关可以存在于块的每个单独值中,但假设块之间是独立的”)正是在nlme(以及在mgcv: gamm中)编码相关结构的方式。
  • I would use mcgv::gamm, and would suggest that if at all possible you try it out on some simulated data with known structure (or use the data set provided in the supplementary material above and see if you can reproduce their qualitative conclusions with your alternative approach).
  • 我将使用mcgv::gamm,并建议如果可能的话,您可以在一些已知结构的模拟数据上进行尝试(或者使用上面补充材料中提供的数据集,看看是否可以用您的替代方法再现它们的定性结论)。
  • StackOverflow is nice, but there is probably more mixed model expertise at r-sig-mixed-models@r-project.org
  • StackOverflow是一个不错的网站,但是在r-sig-mix -models@r-project.org上可能有更多的混合模型专家

推荐阅读
  • Introduction(简介)Forbeingapowerfulobject-orientedprogramminglanguage,Cisuseda ... [详细]
  • 本文由编程笔记#小编为大家整理,主要介绍了logistic回归(线性和非线性)相关的知识,包括线性logistic回归的代码和数据集的分布情况。希望对你有一定的参考价值。 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • Python脚本编写创建输出数据库并添加模型和场数据的方法
    本文介绍了使用Python脚本编写创建输出数据库并添加模型数据和场数据的方法。首先导入相应模块,然后创建输出数据库并添加材料属性、截面、部件实例、分析步和帧、节点和单元等对象。接着向输出数据库中添加场数据和历程数据,本例中只添加了节点位移。最后保存数据库文件并关闭文件。文章还提供了部分代码和Abaqus操作步骤。另外,作者还建立了关于Abaqus的学习交流群,欢迎加入并提问。 ... [详细]
  • 线程漫谈——线程基础
    本系列意在记录Windwos线程的相关知识点,包括线程基础、线程调度、线程同步、TLS、线程池等。进程与线程理解线程是至关重要的,每个进程至少有一个线程,进程是线程的容器,线程才是真正的执行体,线程必 ... [详细]
  • 我正在尝试将Firebase添加到涉及添加以下内容的现有应用程序中:classpath'com.googl ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • IB 物理真题解析:比潜热、理想气体的应用
    本文是对2017年IB物理试卷paper 2中一道涉及比潜热、理想气体和功率的大题进行解析。题目涉及液氧蒸发成氧气的过程,讲解了液氧和氧气分子的结构以及蒸发后分子之间的作用力变化。同时,文章也给出了解题技巧,建议根据得分点的数量来合理分配答题时间。最后,文章提供了答案解析,标注了每个得分点的位置。 ... [详细]
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • 怀疑是每次都在新建文件,具体代码如下 ... [详细]
  • IOS开发之短信发送与拨打电话的方法详解
    本文详细介绍了在IOS开发中实现短信发送和拨打电话的两种方式,一种是使用系统底层发送,虽然无法自定义短信内容和返回原应用,但是简单方便;另一种是使用第三方框架发送,需要导入MessageUI头文件,并遵守MFMessageComposeViewControllerDelegate协议,可以实现自定义短信内容和返回原应用的功能。 ... [详细]
  • 一、概述nmon是一种在AIX与各种Linux操作系统上广泛使用的监控与分析工具,相对于其它一些系统资源监控工具来说,nmon所记录的信息是比较全面的 ... [详细]
author-avatar
PHP小龙
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有