@mhollanders We used DOY instead of the actual survey date because we wanted to control for when we surveyed the territories within the breeding season as this likely (and does) affects the response variable (e.g., a territory surveyed early in the season (e.g., May 15) is less likely to have chicks than a territory surveyed later in the season (e.g., July 15), regardless of the year these surveys were conducted). Including year as a random effect then accounts for any unexplained year-to-year variation. Exact GPs are possible but I was still running into issues.
@jsocolar is it okay to use ar() even though I am missing all data for 1998 (i.e., time variable jumps from 5 to 7)? I also mistyped and meant my time variable is 0-33, with 0 referring to 1992 and 33 referring to 2025.
I tried ar, but the model is still unhappy (low ESS, crazy high estimates for shape)
pr_gp <- brm(nchicks ~ z_npMHWci + z_npENSOci + z_AHWci + z_PPTci + # climate
ar(p = 1) +
z_doy + I(z_doy^2) + (1|year) + (1|terrID), # base
data = pr_df,
family = negbinomial(link = "log"),
iter = 3000)
# Warning messages:
# 1: There were 24 divergent transitions after warmup. See
# https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
# to find out why this is a problem and how to eliminate them.
# 2: Examine the pairs() plot to diagnose sampling problems
#
# 3: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
# Running the chains for more iterations may help. See
# https://mc-stan.org/misc/warnings.html#bulk-ess
> summary(pr_gp)
Family: negbinomial
Links: mu = log
Formula: nchicks ~ z_npMHWci + z_npENSOci + z_AHWci + z_PPTci + ar(p = 1) + z_doy + I(z_doy^2) + (1 | year) + (1 | terrID)
Data: pr_df (Number of observations: 1185)
Draws: 4 chains, each with iter = 3000; warmup = 1500; thin = 1;
total post-warmup draws = 6000
Correlation Structures:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
ar[1] 0.46 0.42 -0.71 0.98 1.00 494 713
sderr 0.38 0.20 0.02 0.71 1.01 180 793
Multilevel Hyperparameters:
~terrID (Number of levels: 106)
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sd(Intercept) 0.21 0.11 0.02 0.41 1.00 866 1196
~year (Number of levels: 33)
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sd(Intercept) 0.33 0.10 0.14 0.54 1.00 1465 1636
Regression Coefficients:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept -0.85 0.13 -1.11 -0.61 1.00 316 1371
z_npMHWci -0.04 0.09 -0.22 0.15 1.00 3279 3488
z_npENSOci 0.15 0.08 -0.00 0.32 1.00 3174 3664
z_AHWci 0.07 0.09 -0.12 0.24 1.00 2742 2893
z_PPTci 0.00 0.09 -0.18 0.18 1.00 2976 3729
z_doy -0.09 0.08 -0.25 0.07 1.00 3332 4271
Iz_doyE2 -0.14 0.05 -0.23 -0.06 1.00 4575 4473
Further Distributional Parameters:
Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
shape 2752.36 86433.46 1.25 3177.69 1.01 211 1229
Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).
Warning message:
There were 24 divergent transitions after warmup. Increasing adapt_delta above 0.8 may help. See http://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
I am not sure how to check if the temporal autocorrelation is consistent across all islands. Some islands only had one territory and/or were not checked every year. Below is how I tested for temporal autocorrelation by time.
pr_ci <- brm(nchicks ~ z_npMHWci + z_npENSOci + z_AHWci + z_PPTci + # climate
z_doy + I(z_doy^2) + (1|year) + (1|terrID), # base
data = pr_df,
family = negbinomial(link = "log"),
iter = 3000)
res <- createDHARMa(
simulatedResponse = t(posterior_predict(pr_ci)),
observedResponse = pr_df$nchicks,
fittedPredictedResponse = apply(t(posterior_epred(pr_ci)), 1, mean),
integerResponse = TRUE)
plot(res)
res_agg <- recalculateResiduals(res, group = pr_df$t)
testTemporalAutocorrelation(res_agg, time = unique(pr_df$t))
Thank you both so much for replying and providing guidance!