如何在glmmTMB中为关系型数据定义相关结构?
No, glmmTMB does not natively support the MLPE (Modular Linear Predictor Expansion) correlation structure provided by the corMLPE package. However, you can model the non-independence of pairs sharing populations using random effects for individual populations, which achieves a similar goal of accounting for shared population effects.
Alternative Approach: Node-level Random Effects
Since your dyadic data (population pairs) exhibit dependence when pairs share a common population, you can add random intercepts for each population in both the main and zero-inflation components of the glmmTMB model. This will create covariance between pairs that share either P1 or P2, mirroring the correlation structure captured by corMLPE.
Modified glmmTMB Code
library(glmmTMB) # Fit zero-inflated binomial model with population random effects fit3 <- glmmTMB( m ~ pred + (1|P1) + (1|P2), # Main model: fixed effect of pred + random intercepts for P1 and P2 zi = ~pred + (1|P1) + (1|P2), # Zero-inflation component: same structure (adjust if needed) data = d, family = binomial, weights = N.pair ) summary(fit3)
Key Notes:
- The terms
(1|P1)and(1|P2)add random intercepts for each population in both the main (success probability) and zero-inflation (excess zero probability) parts of the model. This ensures that pairs sharing a population have correlated residuals, accounting for non-independence. - If you don't expect the zero-inflation component to depend on population-level variation, you can simplify the zero-inflation formula to
zi = ~pred(without random effects). Adjust based on your biological hypotheses. - Check model convergence using
convergence(fit3)or by inspecting the random effects variances (if variances are estimated as near-zero, you may need to simplify the model). - Use the
DHARMapackage to simulate residuals and verify that the model adequately accounts for non-independence:library(DHARMa) sim_res <- simulateResiduals(fit3) plot(sim_res)
Why This Works
The random effects approach models the dependence between pairs by assigning each population a random deviation from the overall mean. Pairs sharing a population will inherit that population's random effect, leading to correlation between those pairs. This is a standard method for handling dyadic dependence in mixed-effects models and is compatible with glmmTMB's zero-inflated binomial framework.
Alternative: brms (if flexible)
If you're open to using Bayesian models, the brms package supports custom correlation structures (including MLPE via the cor_mlpe function) alongside zero-inflated binomial models. However, this requires a Bayesian workflow rather than frequentist inference.
内容的提问来源于stack exchange,提问作者Tobias Naaf

