我想知道glmmTMB
添加exp(coordinates + 0 | SITES )
为空间自相关结构是否仍然保持空间自相关。接下来我该怎么做。这是我的公式glmmTMB
:
df$coordinates = numFactor(df$Longitude,df$Latitude)
M <- glmmTMB(lgDouYa ~ MFS*CD*SNC +
I(MFS^2)+I(CD^2)+I(SNC^2) +(1|SITES/YEAR) +
exp(coordinates + 0 | SITES )
, ziformula=~1
,dispformula=~0
, data = df
)
然后,我尝试用DHARMa
.
library(DHARMa)
recalculateResiduals(simulateResiduals(M,n = 1000), group = df$SITES) %>%
testSpatialAutocorrelation(x = aggregate(df$Latitude, list(df$SITES), mean)$x,
y = aggregate(df$Longitude, list(df$SITES), mean)$x)
但该结果对于空间自相关具有重要意义。
DHARMa Moran's I test for spatial
autocorrelation
data: .
observed = -0.109366, expected =
-0.023810, sd = 0.036913, p-value =
0.02046
alternative hypothesis: Spatial autocorrelation
那么我应该怎么做才能解决空间自相关呢?感谢所有关注我问题的人。谢谢你。
这是我的数据集:
df <-
structure(list(YEAR = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("2017", "2018", "2019"
), class = "factor"), SITES = structure(c(1L, 1L, 1L, 2L, 2L,
2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L, 7L, 7L, 7L,
8L, 8L, 8L, 9L, 9L, 9L, 10L, 10L, 10L, 11L, 11L, 11L, 12L, 12L,
12L, 13L, 13L, 13L, 14L, 14L, 14L, 15L, 15L, 15L, 16L, 16L, 16L,
17L, 17L, 17L, 18L, 18L, 18L, 19L, 19L, 19L, 19L, 20L, 20L, 20L,
20L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 23L, 23L, 23L, 23L,
24L, 24L, 24L, 24L, 25L, 25L, 25L, 25L, 28L, 28L, 28L, 28L, 30L,
30L, 30L, 30L, 33L, 33L, 33L, 33L, 35L, 35L, 35L, 35L, 36L, 36L,
36L, 36L, 37L, 37L, 37L, 37L, 38L, 38L, 38L, 38L, 39L, 39L, 39L,
43L, 43L, 43L, 44L, 44L, 44L, 46L, 46L, 46L, 47L, 47L, 47L, 48L,
48L, 48L, 49L, 49L, 49L, 50L, 50L, 50L, 52L, 52L, 52L, 53L, 53L,
53L, 55L, 55L, 55L), .Label = c("CA1", "CA10", "CA11", "CA12",
"CA13", "CA14", "CA15", "CA17", "CA18", "CA19", "CA2", "CA20",
"CA3", "CA4", "CA5", "CA6", "CA7", "CA9", "CB1", "CB10", "CB11",
"CB12", "CB13", "CB14", "CB15", "CB16", "CB17", "CB18", "CB19",
"CB2", "CB20", "CB3", "CB4", "CB5", "CB6", "CB7", "CB8", "CB9",
"CC1", "CC10", "CC11", "CC12", "CC13", "CC14", "CC15", "CC16",
"CC17", "CC18", "CC2", "CC3", "CC4", "CC5", "CC6", "CC7", "CC8",
"CC9", "CA16", "CA8"), class = "factor"), lgDouYa = c(0.869423773288886,
0.0965586152896391, -0.647230897017041, 2.30836181466664, -0.647230897017041,
-0.647230897017041, 1.6906216295849, 0.348755695517045, -0.647230897017041,
0.492483444930366, -0.647230897017041, -0.647230897017041, 0.68000152309815,
0.275129454289906, 0.376838393944666, 0.414754435392883, -0.647230897017041,
-0.647230897017041, 0.463010775531561, 1.0653594780622, 0.658075667360263,
0.615141104595973, -0.647230897017041, -0.647230897017041, 0.783103333893848,
0.921779971361295, 0.0965586152896391, 0.18510477917444, -0.647230897017041,
-0.647230897017041, 1.16318304340856, 1.40225483961546, -0.647230897017041,
1.27362258886383, -0.647230897017041, -0.647230897017041, 0.948927783595636,
-0.647230897017041, -0.647230897017041, 0.573311845426998, -0.647230897017041,
-0.647230897017041, 1.76882503851871, -0.647230897017041, -0.647230897017041,
0.433934970416483, -0.647230897017041, -0.647230897017041, 0.702259280165173,
-0.647230897017041, -0.647230897017041, 0.275129454289906, -0.647230897017041,
-0.647230897017041, 1.0200762327862, 1.31410405776748, 0.532462663541631,
-0.647230897017041, 0.783103333893848, 0.724870518877707, -0.647230897017041,
-0.647230897017041, 0.747858594763302, 0.573311845426998, 0.0965586152896391,
-0.647230897017041, 0.819348843909036, 1.19837970230692, -0.647230897017041,
-0.647230897017041, 0.463010775531561, 0.18510477917444, -0.647230897017041,
-0.647230897017041, 0.18510477917444, -0.647230897017041, -0.647230897017041,
-0.647230897017041, 0.0965586152896391, -0.647230897017041, -0.647230897017041,
-0.647230897017041, -0.647230897017041, 0.573311845426998, -0.647230897017041,
-0.647230897017041, 1.0200762327862, 0.895295078198926, -0.647230897017041,
-0.647230897017041, 0.275129454289906, -0.647230897017041, -0.647230897017041,
-0.647230897017041, 1.85963585496984, -0.647230897017041, 0.0965586152896391,
-0.647230897017041, 0.395725295814487, -0.647230897017041, -0.647230897017041,
-0.647230897017041, 0.512370678114162, -0.647230897017041, -0.647230897017041,
-0.647230897017041, 0.636461718809469, -0.647230897017041, -0.647230897017041,
-0.647230897017041, 0.844121707593991, 1.50289108284423, 0.348755695517045,
1.09680356209351, 1.96901778371413, -0.647230897017041, 0.976793633267482,
1.12937124274826, -0.647230897017041, -0.647230897017041, 0.18510477917444,
-0.647230897017041, 1.55948717001655, 2.10876310243032, -0.647230897017041,
-0.647230897017041, 0.275129454289906, -0.647230897017041, 1.45073686181061,
1.3568616481425, -0.647230897017041, 0.275129454289906, 2.69717709201565,
-0.647230897017041, -0.647230897017041, 1.23512706836797, -0.647230897017041,
-0.647230897017041, 1.62157161294753, 0.0965586152896391, 0.275129454289906,
-0.647230897017041, -0.647230897017041), DouYa = c(0.826666666666667,
0.0133333333333333, 0, 13.56, 0, 0, 5.62666666666667, 0.0533333333333333,
0, 0.186666666666667, 0, 0, 0.32, 0.04, 0.0666666666666667, 0.0933333333333333,
0, 0, 0.12, 1.61333333333333, 0.293333333333333, 0.24, 0, 0,
0.506666666666667, 1.17333333333333, 0.0133333333333333, 0.0266666666666667,
0, 0, 1.86666666666667, 2.88, 0, 2.28, 0, 0, 1.18666666666667,
0, 0, 0.226666666666667, 0, 0, 6.02666666666667, 0, 0, 0.106666666666667,
0, 0, 0.346666666666667, 0, 0, 0.04, 0, 0, 1.50666666666667,
2.36, 0.213333333333333, 0, 0.506666666666667, 0.4, 0, 0, 0.453333333333333,
0.226666666666667, 0.0133333333333333, 0, 0.533333333333333,
1.93333333333333, 0, 0, 0.12, 0.0266666666666667, 0, 0, 0.0266666666666667,
0, 0, 0, 0.0133333333333333, 0, 0, 0, 0, 0.226666666666667, 0,
0, 1.50666666666667, 0.84, 0, 0, 0.04, 0, 0, 0, 7.34666666666667,
0, 0.0133333333333333, 0, 0.08, 0, 0, 0, 0.2, 0, 0, 0, 0.28,
0, 0, 0, 0.8, 4, 0.0533333333333333, 1.64, 7.68, 0, 1.24, 1.78666666666667,
0, 0, 0.0266666666666667, 0, 4.96, 8.77333333333333, 0, 0, 0.04,
0, 2.92, 2.6, 0, 0.04, 14.2, 0, 0, 2, 0, 0, 5.08, 0.0133333333333333,
0.04, 0, 0), MFS = structure(c(-0.704470454018713, -0.704470454018713,
-0.704470454018713, -0.49219727458324, -0.49219727458324, -0.49219727458324,
0.527968407082596, 0.527968407082596, 0.527968407082596, 2.61289211033616,
2.61289211033616, 2.61289211033616, 0.973964696600823, 0.973964696600823,
0.973964696600823, 0.810053831748292, 0.810053831748292, 0.810053831748292,
-0.646038990797124, -0.646038990797124, -0.646038990797124, -0.0405740424844551,
-0.0405740424844551, -0.0405740424844551, -0.608003192334688,
-0.608003192334688, -0.608003192334688, 0.365588661218839, 0.365588661218839,
0.365588661218839, 1.27085722552215, 1.27085722552215, 1.27085722552215,
-0.348247043875247, -0.348247043875247, -0.348247043875247, -1.34256604272275,
-1.34256604272275, -1.34256604272275, -0.442366256663233, -0.442366256663233,
-0.442366256663233, 0.590527862041596, 0.590527862041596, 0.590527862041596,
0.425429474000678, 0.425429474000678, 0.425429474000678, 0.867288135599791,
0.867288135599791, 0.867288135599791, 2.45848921736224, 2.45848921736224,
2.45848921736224, -0.316682761074777, -0.316682761074777, -0.316682761074777,
-0.316682761074777, 1.27997422497702, 1.27997422497702, 1.27997422497702,
1.27997422497702, 0.929231872203228, 0.929231872203228, 0.929231872203228,
0.929231872203228, 0.810280534910473, 0.810280534910473, 0.810280534910473,
0.810280534910473, 0.708521487075458, 0.708521487075458, 0.708521487075458,
0.708521487075458, 1.74376310922201, 1.74376310922201, 1.74376310922201,
1.74376310922201, -0.638866315394154, -0.638866315394154, -0.638866315394154,
-0.638866315394154, -1.04054218648781, -1.04054218648781, -1.04054218648781,
-1.04054218648781, -0.910039293047068, -0.910039293047068, -0.910039293047068,
-0.910039293047068, -0.376862291489762, -0.376862291489762, -0.376862291489762,
-0.376862291489762, -0.92230815650878, -0.92230815650878, -0.92230815650878,
-0.92230815650878, -1.38047124297597, -1.38047124297597, -1.38047124297597,
-1.38047124297597, -0.674768565361297, -0.674768565361297, -0.674768565361297,
-0.674768565361297, -0.673581308608378, -0.673581308608378, -0.673581308608378,
-0.673581308608378, -0.595112731354483, -0.595112731354483, -0.595112731354483,
-1.2473400909545, -1.2473400909545, -1.2473400909545, -1.14108242285356,
-1.14108242285356, -1.14108242285356, -1.06398632494527, -1.06398632494527,
-1.06398632494527, -1.09717275254042, -1.09717275254042, -1.09717275254042,
0.23200886760946, 0.23200886760946, 0.23200886760946, 0.199500012511306,
0.199500012511306, 0.199500012511306, -0.930127869136063, -0.930127869136063,
-0.930127869136063, -1.39138211207404, -1.39138211207404, -1.39138211207404,
0.340576705522566, 0.340576705522566, 0.340576705522566, 1.41673194858262,
1.41673194858262, 1.41673194858262), "`scaled:center`" = 0.531172306358715, "`scaled:scale`" = 0.1321853801893, .Dim = c(143L,
1L)), CD = structure(c(0.571325446748364, 0.571325446748364,
0.571325446748364, 0.0487947267179488, 0.0487947267179488, 0.0487947267179488,
-1.20061533945842, -1.20061533945842, -1.20061533945842, -1.65920875929318,
-1.65920875929318, -1.65920875929318, 0.0776291954336383, 0.0776291954336383,
0.0776291954336383, -1.24474461331896, -1.24474461331896, -1.24474461331896,
-0.423839825708794, -0.423839825708794, -0.423839825708794, -0.398515640141102,
-0.398515640141102, -0.398515640141102, 1.34634581892399, 1.34634581892399,
1.34634581892399, 0.413111970577926, 0.413111970577926, 0.413111970577926,
0.353938626083119, 0.353938626083119, 0.353938626083119, 0.856661319778408,
0.856661319778408, 0.856661319778408, 1.39047509278453, 1.39047509278453,
1.39047509278453, 1.20016759926097, 1.20016759926097, 1.20016759926097,
0.478302943326443, 0.478302943326443, 0.478302943326443, -0.172353111605864,
-0.172353111605864, -0.172353111605864, -0.0244197503688467,
-0.0244197503688467, -0.0244197503688467, -0.767596839701932,
-0.767596839701932, -0.767596839701932, -0.454680170509054, -0.454680170509054,
-0.454680170509054, -0.454680170509054, -1.04390627035141, -1.04390627035141,
-1.04390627035141, -1.04390627035141, -0.0161455115199964, -0.0161455115199964,
-0.0161455115199964, -0.0161455115199964, 1.04370926466454, 1.04370926466454,
1.04370926466454, 1.04370926466454, 0.579850420107785, 0.579850420107785,
0.579850420107785, 0.579850420107785, -1.08126571242652, -1.08126571242652,
-1.08126571242652, -1.08126571242652, 1.39523904848538, 1.39523904848538,
1.39523904848538, 1.39523904848538, 0.810526169833304, 0.810526169833304,
0.810526169833304, 0.810526169833304, 0.659834728980003, 0.659834728980003,
0.659834728980003, 0.659834728980003, -0.139256156210463, -0.139256156210463,
-0.139256156210463, -0.139256156210463, -0.786652662505345, -0.786652662505345,
-0.786652662505345, -0.786652662505345, 0.0738681777750704, 0.0738681777750704,
0.0738681777750704, 0.0738681777750704, -0.313015172036317, -0.313015172036317,
-0.313015172036317, -0.313015172036317, -0.789410742121628, -0.789410742121628,
-0.789410742121628, -0.789410742121628, 1.39298243789024, 1.39298243789024,
1.39298243789024, 0.301785847884306, 0.301785847884306, 0.301785847884306,
-1.60780818462608, -1.60780818462608, -1.60780818462608, 0.198733964039536,
0.198733964039536, 0.198733964039536, 0.41185829802507, 0.41185829802507,
0.41185829802507, -1.20613149869099, -1.20613149869099, -1.20613149869099,
0.349425404892837, 0.349425404892837, 0.349425404892837, 0.42213841295849,
0.42213841295849, 0.42213841295849, 1.56247896703638, 1.56247896703638,
1.56247896703638, -0.381214958911687, -0.381214958911687, -0.381214958911687,
-0.561994541033535, -0.561994541033535, -0.561994541033535), "`scaled:center`" = 1.67953928571429, "`scaled:scale`" = 0.398828225808178, .Dim = c(143L,
1L)), SNC = structure(c(0.248739188017824, 0.248739188017824,
0.248739188017824, -0.156470857543067, -0.156470857543067, -0.156470857543067,
0.00417693903715141, 0.00417693903715141, 0.00417693903715141,
2.88764474556734, 2.88764474556734, 2.88764474556734, -0.308032697947342,
-0.308032697947342, -0.308032697947342, 0.692282191545496, 0.692282191545496,
0.692282191545496, 0.0974639176599148, 0.0974639176599148, 0.0974639176599148,
-1.05547480711491, -1.05547480711491, -1.05547480711491, -0.426908696004394,
-0.426908696004394, -0.426908696004394, -0.83090503313362, -0.83090503313362,
-0.83090503313362, -1.21694859971112, -1.21694859971112, -1.21694859971112,
-1.10457942741272, -1.10457942741272, -1.10457942741272, -0.848183521223307,
-0.848183521223307, -0.848183521223307, -0.31204467859646, -0.31204467859646,
-0.31204467859646, -0.885285913696871, -0.885285913696871, -0.885285913696871,
-0.448637448343523, -0.448637448343523, -0.448637448343523, -0.496696930825182,
-0.496696930825182, -0.496696930825182, -0.458937112951132, -0.458937112951132,
-0.458937112951132, -0.593203608204169, -0.593203608204169, -0.593203608204169,
-0.593203608204169, 4.07313445619698, 4.07313445619698, 4.07313445619698,
4.07313445619698, -0.554988649668245, -0.554988649668245, -0.554988649668245,
-0.554988649668245, -0.717507580080615, -0.717507580080615, -0.717507580080615,
-0.717507580080615, 0.0712680440097931, 0.0712680440097931, 0.0712680440097931,
0.0712680440097931, -0.0862443391219557, -0.0862443391219557,
-0.0862443391219557, -0.0862443391219557, -0.825139918083207,
-0.825139918083207, -0.825139918083207, -0.825139918083207, -0.448283450050954,
-0.448283450050954, -0.448283450050954, -0.448283450050954, 1.28526304572203,
1.28526304572203, 1.28526304572203, 1.28526304572203, 0.340829315270473,
0.340829315270473, 0.340829315270473, 0.340829315270473, -0.26578890170075,
-0.26578890170075, -0.26578890170075, -0.26578890170075, 0.241389509181626,
0.241389509181626, 0.241389509181626, 0.241389509181626, -0.280488259373148,
-0.280488259373148, -0.280488259373148, -0.280488259373148, 1.74291540976782,
1.74291540976782, 1.74291540976782, 1.74291540976782, 0.544833474159644,
0.544833474159644, 0.544833474159644, -0.179025605898191, -0.179025605898191,
-0.179025605898191, 1.64495902509545, 1.64495902509545, 1.64495902509545,
-0.530107626819095, -0.530107626819095, -0.530107626819095, 0.225392157769807,
0.225392157769807, 0.225392157769807, 0.579339879154367, 0.579339879154367,
0.579339879154367, -0.440006632829455, -0.440006632829455, -0.440006632829455,
-0.135416387665974, -0.135416387665974, -0.135416387665974, -0.762600219729313,
-0.762600219729313, -0.762600219729313, -0.0303126088960203,
-0.0303126088960203, -0.0303126088960203, -0.4224078605703, -0.4224078605703,
-0.4224078605703), "`scaled:center`" = 16.3174214285714, "`scaled:scale`" = 5.93223200247334, .Dim = c(143L,
1L)), Latitude = c(41.05686278, 41.05686278, 41.05686278, 41.11095806,
41.11095806, 41.11095806, 41.04523861, 41.04523861, 41.04523861,
40.95670806, 40.95670806, 40.95670806, 40.99668806, 40.99668806,
40.99668806, 41.04156694, 41.04156694, 41.04156694, 41.09246028,
41.09246028, 41.09246028, 40.99216861, 40.99216861, 40.99216861,
41.03523028, 41.03523028, 41.03523028, 41.02716667, 41.02716667,
41.02716667, 41.01156083, 41.01156083, 41.01156083, 41.06100694,
41.06100694, 41.06100694, 40.94746417, 40.94746417, 40.94746417,
40.900705, 40.900705, 40.900705, 40.87212056, 40.87212056, 40.87212056,
40.90833583, 40.90833583, 40.90833583, 40.82387833, 40.82387833,
40.82387833, 40.99983361, 40.99983361, 40.99983361, 41.17633167,
41.17633167, 41.17633167, 41.17633167, 40.80911056, 40.80911056,
40.80911056, 40.80911056, 40.80239444, 40.80239444, 40.80239444,
40.80239444, 40.82870833, 40.82870833, 40.82870833, 40.82870833,
41.02167088, 41.02167088, 41.02167088, 41.02167088, 40.98107699,
40.98107699, 40.98107699, 40.98107699, 40.98334098, 40.98334098,
40.98334098, 40.98334098, 40.99086151, 40.99086151, 40.99086151,
40.99086151, 41.16152528, 41.16152528, 41.16152528, 41.16152528,
41.16686889, 41.16686889, 41.16686889, 41.16686889, 41.07348806,
41.07348806, 41.07348806, 41.07348806, 41.03278333, 41.03278333,
41.03278333, 41.03278333, 40.97858194, 40.97858194, 40.97858194,
40.97858194, 41.03570917, 41.03570917, 41.03570917, 41.03570917,
41.021529, 41.021529, 41.021529, 41.016319, 41.016319, 41.016319,
41.045005, 41.045005, 41.045005, 41.083288, 41.083288, 41.083288,
41.129119, 41.129119, 41.129119, 41.172374, 41.172374, 41.172374,
40.998956, 40.998956, 40.998956, 40.970129, 40.970129, 40.970129,
40.886755, 40.886755, 40.886755, 40.85327, 40.85327, 40.85327,
40.829648, 40.829648, 40.829648), Longitude = c(80.34026694,
80.34026694, 80.34026694, 80.46016028, 80.46016028, 80.46016028,
80.48630833, 80.48630833, 80.48630833, 80.50068278, 80.50068278,
80.50068278, 80.56087556, 80.56087556, 80.56087556, 80.54815722,
80.54815722, 80.54815722, 80.53416472, 80.53416472, 80.53416472,
80.29715028, 80.29715028, 80.29715028, 80.242545, 80.242545,
80.242545, 80.205635, 80.205635, 80.205635, 80.32743694, 80.32743694,
80.32743694, 80.21906472, 80.21906472, 80.21906472, 80.34813583,
80.34813583, 80.34813583, 80.3566375, 80.3566375, 80.3566375,
80.42242306, 80.42242306, 80.42242306, 80.41108333, 80.41108333,
80.41108333, 80.46019611, 80.46019611, 80.46019611, 80.3918025,
80.3918025, 80.3918025, 80.41081194, 80.41081194, 80.41081194,
80.41081194, 80.56281944, 80.56281944, 80.56281944, 80.56281944,
80.46875, 80.46875, 80.46875, 80.46875, 80.41125278, 80.41125278,
80.41125278, 80.41125278, 80.35851237, 80.35851237, 80.35851237,
80.35851237, 80.39885327, 80.39885327, 80.39885327, 80.39885327,
80.33922402, 80.33922402, 80.33922402, 80.33922402, 80.26167842,
80.26167842, 80.26167842, 80.26167842, 80.47888889, 80.47888889,
80.47888889, 80.47888889, 80.52739444, 80.52739444, 80.52739444,
80.52739444, 80.53371111, 80.53371111, 80.53371111, 80.53371111,
80.557725, 80.557725, 80.557725, 80.557725, 80.57384333, 80.57384333,
80.57384333, 80.57384333, 80.48125, 80.48125, 80.48125, 80.48125,
80.349776, 80.349776, 80.349776, 80.551031, 80.551031, 80.551031,
80.520748, 80.520748, 80.520748, 80.507795, 80.507795, 80.507795,
80.484277, 80.484277, 80.484277, 80.406286, 80.406286, 80.406286,
80.327168, 80.327168, 80.327168, 80.373821, 80.373821, 80.373821,
80.387362, 80.387362, 80.387362, 80.434011, 80.434011, 80.434011,
80.497346, 80.497346, 80.497346)), row.names = c(NA, -143L), class = "data.frame")