我有一个很大的动物数量数据集,在过去的20年中以20分的网格形式收集。我想运行一个数据的negbin模型,考虑到点之间(我知道有)的空间自相关。
我按照spatial autocorrelation with glmmTMB的教程构建了一个模型:
玩具数据:
df <- structure(list(Stratum = structure(c(2L, 1L, 3L, 3L, 2L, 2L,
1L, 3L, 2L, 3L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 1L), .Label = c("A",
"C", "G"), class = "factor"), SubstratumNum = structure(c(3L,
3L, 3L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 2L, 3L, 3L, 1L, 3L,
2L, 1L, 3L), .Label = c("1", "2", "3"), class = "factor"), Round_IDGlobal = structure(c(33L,
9L, 1L, 14L, 1L, 15L, 12L, 5L, 20L, 8L, 4L, 31L, 23L, 10L, 2L,
3L, 19L, 16L, 2L, 22L), .Label = c("494", "506", "746", "821",
"822", "829", "830", "831", "834", "841", "842", "858", "862",
"864", "866", "868", "869", "881", "886", "887", "888", "892",
"894", "905", "920", "929", "939", "950", "951", "952", "954",
"961", "962", "963"), class = "factor"), NTotal = c(0, 0, 0,
22, 0, 0, 0, 44, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), Easting = c(421404.301562637,
418803.885030836, 418042.117225571, 417187.715740421, 419311.45516526,
417264.924140131, 416268.565309357, 416408.875490186, 419311.45516526,
417187.715740421, 416268.565309357, 417488.310843067, 419311.45516526,
421404.301562637, 421404.301562637, 416268.565309357, 421404.301562637,
417488.310843067, 416268.565309357, 418803.885030836), Northing = c(7000230.98045177,
7004401.10398065, 6992987.57831617, 6994272.80680691, 6999227.50164136,
6998264.92240288, 7002164.31946824, 6995705.21394914, 6999227.50164136,
6994272.80680691, 7002164.31946824, 7003320.22469426, 6999227.50164136,
7000230.98045177, 7000230.98045177, 7002164.31946824, 7000230.98045177,
7003320.22469426, 7002164.31946824, 7004401.10398065)), row.names = c(NA,
-20L), class = c("tbl_df", "tbl", "data.frame"))
用于空间自相关的变量的计算:
library(glmmTMB)
df$pos <- numFactor(df$Easting, df$Northing)
型号:
mod1 <- glmmTMB(NTotal ~ YearF +
# sampling variables
Stratum + SubstratumNum +
# random variable
(1 | Round_IDGlobal) +
# autocorrelation
exp(pos + 0 | Round_IDGlobal),
family = nbinom2,
data= df)
这是我完整模型的简化版本。每当我对完整数据集运行完整模型或任何简化模型时,除非我注释掉non-positive-definite Hessian matrix
空间结构,否则我都会得到exp()
警告。小插图告诉我,这可能是模型复杂性的问题,但是肯定有24,000点数据集将为此提供足够的信息。这使我认为我做错了。从玩具数据集和模型结构来看-有什么想法吗?