[R-sig-ME] glmmTMB with spatial autocorrelation on a large dataset
John Wilson
jhw||@on@nb @end|ng |rom gm@||@com
Sat Aug 28 03:39:30 CEST 2021
Hi all,
I'm running a glmmTMB on a large (~62,000 cases) dataset of animal counts
along transects. Transects are resampled on multiple sampling days across
several years. Some transects change between years. There's a total of
~1,100 unique coordinates in the data. I'm using a glmmTMB model, with a
SampleDate random effect and a set of fixed effects. Moran's I is
significant for 25% of the residuals of a model without spatial
autocorrelation.
When I add spatial autocorrelation following the glmmTMB covariance
structure tutorial, I get an error "Memory allocation fail in function
'MakeADGradObject'". I assume it's due to the large number of unique
coordinates? I checked the memory allocation and it's 48 gb, which is all
the ram I have. What are my options?
A reproducible toy example that is somewhat close to my data is below. The
model doesn't run on the full dataset (same error as I get for my real
data), but runs (without convergence) if I subset the data to only 1,000
rows.
Any help would be appreciated!
John
library(glmmTMB)
library(dplyr)
set.seed(0)
# create a large dataset with transects that are sampled repeatedly within
each year, where x and y are UTM coordinates.
df <- expand.grid(x = seq(392000, 460000, 5000), y = seq(5100000, 5200000,
1000), Year =
2000:2004, DayYear = seq(30, 120, 10)) %>%
# create a Date factor variable
mutate(Date = paste(Year, DayYear, sep = "."),
Date = as.factor(Date),
# calculate distance to a single point - this will be
the fixed effect
Dist = sqrt((x - 400000)^ 2 + (y - 5150000)^2),
# simulate a linear response
Pred = x * 0.01 + 0.1,
Pred = rpois(n(), Pred))
# the model doesn't run on the full dataset (same error as I get for my
actual data). It runs (but does not converge) if I subset the data using
this:
#df <- df[sample(1:nrow(df), 1000, replace = FALSE),]
# create a position variable for the autocorrelation structure
df$pos <- numFactor(round(df$x), round(df$y)) # x and y are UTM coordinates
# run the model
m <- glmmTMB(Pred ~ Dist + exp(pos + 0|Date), family = poisson, data = df)
[[alternative HTML version deleted]]
More information about the R-sig-mixed-models
mailing list