You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在glmmTMB中为关系型数据定义相关结构?

Can glmmTMB handle MLPE-style correlation for zero-inflated binomial models?

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 DHARMa package 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 01:50:57