微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 betapart 和 ddecay 包的距离衰减错误

如何解决使用 betapart 和 ddecay 包的距离衰减错误

我的目标是为物种数据与地理距离创建距离衰减曲线。但是,我遇到了错误。对于 betapart 包,这可能是由于缺少与行数相关的列。有没有办法克服这个?如果没有,是否有另一种方法来创建距离衰减曲线(并绘制它)?我也尝试过 ddecay 包,但也遇到了错误。任何帮助深表感谢。数据采用以下结构形式。

# BETAPART -------------------------------------------------
library(betapart)
spat.dist<-dist(coords)
dissim.BCI<-beta.pair.abund(spec)$beta.bray.bal

plot(spat.dist,dissim.BCI,ylim=c(0,1),xlim=c(0,max(spat.dist)))

BCI.decay.exp<-decay.model(dissim.BCI,spat.dist,y.type="dissim",model.type="exp",perm=100)
#========================================================================================================

I also tried a few other packages --------------------------

# ddecay package -------------------------------------------
devtools::install_github("chihlinwei/ddecay")
the issue with this method is that it requires the use of a gradient however,I would like to avoid that if possible but I do not see a way around this. Also they do not include their example data in the package.

dd <- beta.decay(gradient=spat.dist,counts=decostand(spec,method="pa"),coords=coords,nboots=1000,dis.fun = "beta.pair",index.family = "sorensen",dis = 1,like.pairs=T)
x <- vegdist(coords,method = "euclidean")
y <- 1 - dist(decostand(spec,index.family = "sorensen")[[1]]
plot(x,y)
lines(dd$Predictions[,"x"],dd$Predictions[,"mean"],col="red",lwd=2)
#========================================================================================================

# DATA -----------------------------------------------------

    spec <- structure(list(Ccol = c(0,1,0),Acol = c(0,3,NYcol = c(0,Mcol = c(0,AAcol = c(14,14,11,2,4,8,7),Ncol = c(0,ATBcol = c(0,20,3),CVcol = c(0,7,6),AZNcol = c(0,GBcol = c(0,KHAcol = c(0,AFcol = c(0,AFPcol = c(0,TIAcol = c(4,6,AUcol = c(0,AScol = c(0,5,NSAcol = c(0,9,WZcol = c(0,10,17,AJcol = c(0,39,12,13,16,5),EADcol = c(4,CAcol = c(0,Pcol = c(0,60,ASDcol = c(3,26,25,8),RMAcol = c(0,OUcol = c(0,KAcol = c(0,PACcol = c(0,37,24,LAAcol = c(0,GAcol = c(1,AAcol = c(1,EVAcol = c(0,EAcol = c(0,AKcol = c(0,QAcol = c(0,YAcol = c(11,21,63,44,95,43,22,48,86,45),BANcol = c(0,17),VCcol = c(0,38,Vcol = c(0,Ocol = c(0,AVcol = c(0,JXcol = c(0,0)),class = "data.frame",row.names = c(NA,-29L))

   coords <- structure(list(Lat.x = c(34.43363,34.36784,34.32587,34.19891,34.24217,34.24863,34.18137,34.16838,34.10961,34.08329,34.40571,34.39591,34.39292,34.37466,34.28948,34.26146,34.04687,34.0409,34.068339,34.34679,34.17161,34.23308,34.21544,34.14922,34.27539,34.2323,34.19057,34.07042,34.06289),Lon.x = c(-94.94494,-94.92512,-94.94429,-94.84497,-94.8573,-94.85641,-94.887,-94.91322,-94.92913,-94.93276,-95.02622,-95.04382,-94.96295,-94.83733,-94.81071,-94.79161,-95.03968,-95.0608,-95.086986,-95.03345,-95.23862,-95.25619,-95.1041,-95.02286,-95.02672,-95.02626,-95.02941,-95.01746,-94.98786)),-29L))

解决方法

如果您说出问题所在,您可以获得更多答案。例如,哪些功能失败以及错误消息是什么。我查看了 betapart::decay.model(),在那里我可以得到以下错误消息:

Error in eval(family$initialize) : 
  cannot find valid starting values: please specify some

我把长话短说:你不能对你的数据使用这个函数,因为你的数据中有 1 的不相似性,不相似性变成了具有 1-不相似性的相似性,这使得这些值的相似性为零(即这些对的抽样单位没有共同点,他们没有共享物种)。函数 decay.modelglmgaussian 系列与 log-link 一起使用,如果 y 变量中有零,log-link 要求您提供起始值。

我认为您有四种选择:

  1. 您不使用该方法,因为它不适合您的数据。
  2. 您修改 decay.model 函数,以便可以指定起始值,如建议的错误消息。这意味着您将 mustart 添加到函数调用中,以便它读取,例如 glm(y ~ x,family=gaussian(link="log"),mustart=pmax(y,0.01))。这会将零替换为 0.01 作为起始值。
  3. 您将最大距离从 1 更改为更小的值,例如 0.99:dissim.BCI[dissim.BCI==1] <- 0.99。但是,这会更改数据,也会更改您使用备选方案 2 获得的结果(仅更改起始值,但数据未修改)。然而,效果并不是很大,任何贝叶斯主义者都会声称差异 1 只是频率论者的愚蠢行为(您只是没有看到这些采样单元的共同点)。
  4. 您更改了缺失值的最大距离。这将比备选方案 3 改变更多的数据。它消除了最大的差异,这些差异不再影响衰减曲线。其效果与审查最大差异相同。结果比备选方案 3 变化更大。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。