将样本级协变量纳入eDNA占用率occModel

时间:2019-03-06 13:48:18

标签: r hierarchy bayesian

我正在使用R包eDNAoccupancy来开发具有三个级别的贝叶斯层次模型,但是我正在努力寻找同时使用站点级和样本级协变量的示例(仅引用是可能的) 。

我已经按照我应该的格式格式化了数据,但我总是遇到错误。

任何帮助或指导将不胜感激!

我的检测矩阵如下:

> head(hbDetections$y)
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15]
S1    0    0    0    0    0    0    0    0    0     0     0     0     0     0     0
S2    1    0    1    0    0    0    0    0    0     0     0     0     0     0     0
S3    0    0    0    0    0    0    1    0    0     0     2     0     1     0     1
   [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26] [,27] [,28]
S1     1     0     0     0     0     0     0     0     0     0     1     0     0
S2     0     0     0     1     0     0     0     0     0     0     0     0     0
S3     0     0     0     1     0     0     0     0     0     0     0     0     0
   [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37] [,38] [,39] [,40] [,41]
S1     1     0     0     2     0     0     0     0     0     0     0     0     0
S2     0     0     1     0     0     0     0     0     0     0     0     0     0
S3     0     1     1     0     0     1     0     0     1     0     0     0    NA
   [,42] [,43] [,44] [,45] [,46]
S1    NA    NA    NA    NA    NA
S2     0     0     1     0     0
S3    NA    NA    NA    NA    NA

> head(hbDetections$K)
   [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15]
S1    5    5    5    5    5    5    5    5    5     5     5     5     5     5     5
S2    5    5    5    5    5    5    5    5    5     5     5     5     5     5     5
S3    5    5    5    5    5    5    5    5    5     5     5     5     5     5     5
   [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26] [,27] [,28]
S1     5     5     5     5     5     5     5     5     5     5     5     5     5
S2     5     5     5     5     5     5     5     5     5     5     5     5     5
S3     5     5     5     5     5     5     5     5     5     5     5     5     5
   [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37] [,38] [,39] [,40] [,41]
S1     5     5     5     5     5     5     5     5     5     5     5     5     5
S2     5     5     5     5     5     5     5     5     5     5     5     5     5
S3     5     5     5     5     5     5     5     5     5     5     5     5     0
   [,42] [,43] [,44] [,45] [,46]
S1     0     0     0     0     0
S2     5     5     5     5     5
S3     0     0     0     0     0

我的协变量如下:

注意:大小,SI和Light站点级协变量以及NDVI和TRI样本级协变量

> head(siteAndSampleData)
  Site Sample   Size   SI Light    NDVI      TRI
1   S1      1 313.28 1.76   881 6398.00 188.3559
2   S1      2 313.28 1.76   881 5881.00 191.6983
3   S1      3 313.28 1.76   881 7253.25 390.0000
4   S1      4 313.28 1.76   881 6565.50 299.3047
5   S1      5 313.28 1.76   881 6332.25 287.0660
6   S1      6 313.28 1.76   881 6641.75 250.7060

然后我用occModel运行eDNAoccupancy,如下所示:

set.seed(0157)
fit = occModel(formulaSite = ~ 1,
               formulaSiteAndSample = ~ NDVI,
               formulaReplicate = ~ 1,
               detectionMats = hbDetections,
               siteData = NULL,
               siteAndSampleData = siteAndSampleData.sc,
               niter = 6000,
               niterInterval = 2000,
               siteColName = "Site",
               sampleColName = "Sample"
               )

我收到以下警告消息:

> warnings()
Warning messages:
1: glm.fit: fitted probabilities numerically 0 or 1 occurred

坚持不懈地奋斗,我尝试并适应后验总结

> posteriorSummary(fit, burnin = 1000, mcError = TRUE, outputSummary=TRUE)

Bayesian estimates of model parameters 
                    Mean    50%   2.5%  97.5%
beta..Intercept.   1.042  1.015 -0.243  2.513
alpha..Intercept.  0.591  0.501 -0.614  2.230
alpha.NDVI        -0.347 -0.338 -1.457  0.898
delta..Intercept. -1.618 -1.647 -1.942 -1.156

Monte Carlo SE of Bayesian estimates 
                    Mean    50%   2.5%  97.5%
beta..Intercept.  0.0100 0.0119 0.0216 0.0277
alpha..Intercept. 0.0687 0.0859 0.0313 0.1224
alpha.NDVI        0.0406 0.0337 0.0689 0.1268
delta..Intercept. 0.0151 0.0163 0.0089 0.0222
NULL

> psi = posteriorSummaryOfSiteOccupancy(fit, burnin = 1000)

> theta = posteriorSummaryOfSampleOccupancy(fit, burnin = 1000)

最后收到一条错误消息:

Error in quantile.default(input, prob = q, type = 1, names = FALSE) : 
  missing values and NaN's not allowed if 'na.rm' is FALSE

再次感谢您提出关于如何使用eDNAoccupancy格式化我的数据框和/或模型以便合并站点级协变量和样本级协变量的建议。

谢谢!

0 个答案:

没有答案