1

我正在尝试使用时空相关结构来拟合混合效应模型lme {nlme}
数据包括 37936 lon ( x ) + lat ( y ) 网格单元(18968 男性 + 18968 女性),密度 (kde)、高于/低于长期平均降雨量 ( rainAB ) 和到水的距离 ( wDist ) 每年重复从 2001 年到 2010 年(年F =10)。
我想模拟kde如何受rainABwDist对雄性动物和雌性动物的影响,同时允许每个sexF有自己的截距和自己的yearF斜率,而这些又在空间上是相关的(x+y)和时间(yearF)。
该模型在较小的数据集 (n=3780) 上运行良好,但Too large groups in the correlation structure在较大的数据集 (n=379360) 上运行良好。我将不胜感激有关如何处理此问题的任何建议 - 请参阅下面的可重现示例。

# LOAD LIBRARIES
library(nlme)
library(car)
library(dplyr)
library(ggstatsplot)
#----------------------------------------------------------------------------------------------

# SMALL DATASET
set.seed(1)
(nGrid_s = 189) #Number of 1km grid cells in study area
(nYrs = 10) #Number of years
(nGrps = 2) #Number of groups i.e. male and female

dat_s = data.frame(x=rep(seq(from=283, to=401, length.out=nGrid_s),each=nYrs),
                   y=rep(seq(from=7176, to=7529, length.out=nGrid_s),each=nYrs),
                   yearF=as.factor(rep(2001:2010, nGrid_s)),
                   sexF=as.factor(rep(c('male','female'), each=nGrid_s*nYrs)),
                   kde=runif(nGrid_s*nYrs, 0, 8),
                   rainAB=runif(nGrid_s*nYrs, -70, 247),
                   wDist=runif(nGrid_s*nYrs, 0, 14))
str(dat_s)

# LME WITH SMALL DATASET (n=3780)
lmeS = lme(kde~rainAB/sexF+wDist/sexF, #What about how rainAB affects wDist
           # random=~y+x|yearF,
           random=~yearF|sexF,
           correlation=corSpatial(form=~x+y|sexF/yearF),
           control=lmeControl(maxIter=50, msMaxIter=50, niterEM=50, opt='optim',msVerbose=TRUE),
           method="REML",
           data=dat_s)
summary(lmeS)
Anova(lmeS, type=c("III")) 
ggcoefstats(x = lmeS, title = "Small LME mixed-effects model")
##############################################################################################

# GENERATE LARGE DATASET
set.seed(2)
(nGrid_l = 18968) #Number of 1km grid cells in study area

dat_l = data.frame(x=rep(seq(from=283, to=401, length.out=nGrid_l),each=nYrs),
                   y=rep(seq(from=7176, to=7529, length.out=nGrid_l),each=nYrs),
                   yearF=as.factor(rep(2001:2010, nGrid_l)),
                   sexF=as.factor(rep(c('male','female'), each=nGrid_l*nYrs)),
                   kde=runif(nGrid_l*nYrs, 0, 8),
                   rainAB=runif(nGrid_l*nYrs, -70, 247),
                   wDist=runif(nGrid_l*nYrs, 0, 14))

# LME WITH LARGE DATASET (n=379360)
lmeL = lme(kde~rainAB/sexF+wDist/sexF, #What about how rainAB affects wDist
           # random=~y+x|yearF,
           random=~yearF|sexF,
           correlation=corSpatial(form=~x+y|sexF/yearF),
           control=lmeControl(maxIter=50, msMaxIter=50, niterEM=50, opt='optim',msVerbose=TRUE),
           method="REML",
           data=dat_l)
# Error: 'sumLenSq := sum(table(groups)^2)' = 1.43914e+10 is too large.
# Too large or no groups in your correlation structure?
#-------------------------------------------------------------------------------
4

0 回答 0