check_overdispersion underestimates dispersion in mixed models
维护者通常 1 天内回复
还没有人认领这个 Issue。
- #949 来自 @IndrajeetPatil —— 已关闭,未合并
评估
调研方向
从 check_overdispersion(m1) 入口开始,使用 200 个随机系数复现所提供的 lme4 混合 Poisson 示例。将报告的 residual_df 和离散度比率与模拟结果进行比较,然后通过回归测试验证其行为;当自由度和离散度估计值适用于此模型时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Hi,
so I was playing around with mixed Poisson models and noticed that for large numbers of random coefficients (also called random effects, i guess) the dispersion ratio from check_overdispersion was too low.
I used code from the Ben Bolker GLMM-FAQ (https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html#overdispersion) and modified it for 200 random coefficients:
library(lme4)
set.seed(101)
d <- data.frame(x=runif(1000),
f=factor(sample(1:200,size=1000,replace=TRUE))) # modified for more random effects
suppressMessages(d$y <- simulate(~x+(1|f), family=poisson,
newdata=d,
newparams=list(theta=1,beta=c(0,2)))[[1]])
m1 <- glmer(y~x+(1|f),data=d, family=poisson)
#overdisp_fun(m1)
performance::check_overdispersion(m1)
Now this should be a perfect model, but the dispersion ratio is only about 0.8 not 1. Looking deeper the assumed residual degrees of freedom are 997, which is widely inconsitent with the result of 814
x <- performance::check_overdispersion(m1)
x$residual_df
pchisq(x$chisq_statistic, df = x$residual_df)
Now I assumed, that the issue is that overdispersion is a phenomenon on the conditional residuals, as the random coefficients have a scaling factor. So they act as fixed coefficients in this analysis and should be subtracted from the degrees of freedom which gives 200 RC the intercept and x makes 798 df. Checking with 200 simulations you have to modify Ben Bolkers code to avoid the issue with lambda < 5, but you get results that look pretty consistent
res <- replicate(200, {
d <- data.frame(x=runif(1000) + log(5), # small lambda(<5) slightly distort the result
f=factor(sample(1:200,size=1000,replace=TRUE)))
suppressMessages(d$y <- simulate(~x +(1|f) , family=poisson,
newdata=d,
newparams=list(theta=1,beta=c(0,2)))[[1]])
m1 <- glmer(y~x+(1|f),data=d, family=poisson)
performance::check_overdispersion(m1)[[1]]
})
# doesn't fit df = 997
qqplot(res, rchisq(10000, 997))
abline(0, 1)
# does fit df = 798
mean(res)
t.test(res, mu = 798)
qqplot(res, rchisq(10000, 798))
abline(0, 1)
Now i wanted to make sure i got it right and used a much larger simulation and here the chisq seem to have a mean closer to 799 which confuses me, but is perhaps explained by remaining imprecision of the pearson residual:
library(parallel)
# 20,000 simulations on 10 cores, took 6 minutes on my machine
res_list <- mclapply(1:20000, function(i) {
d <- data.frame(x=runif(1000) + log(5), # small lambda(<5) slightly distort the result
f=factor(sample(1:200,size=1000,replace=TRUE)))
suppressMessages(d$y <- simulate(~x +(1|f) , family=poisson,
newdata=d,
newparams=list(theta=1,beta=c(0,2)))[[1]])
m1 <- glmer(y~x+(1|f),data=d, family=poisson)
performance::check_overdispersion(m1)[[1]]
}, mc.cores = 10)
res <- unlist(res_list)
mean(res)
t.test(res, mu = 798)
qqplot(res, rchisq(10000, 798))
abline(0, 1)
The same problem exists in the overdisp_fun from the GLMM-FAQ. Do you think I should post there as well?
Session info:
> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.4 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=de_DE.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=de_DE.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=de_DE.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] performance_0.8.0 lme4_1.1-27.1 Matrix_1.2-18
loaded via a namespace (and not attached):
[1] minqa_1.2.4 MASS_7.3-51.6 compiler_3.6.3 tools_3.6.3 Rcpp_1.0.7 splines_3.6.3 nlme_3.1-147
[8] grid_3.6.3 insight_0.14.5 nloptr_1.2.2.3 boot_1.3-25 lattice_0.20-41
- 主要语言
- R
- 星标
- 1.2k
- 派生
- 113
- 平均合并
- 9 小时 8 分钟
- 30 天内合并 PR
- 27
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
easystats/performance 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
easystats/performance#1038 ·
维护者通常 1 天内回复
-
Waiting for response :love_letter:
难度 3/5 1-2 天 新手友好度 62/100
easystats/performance#1005 · 1 条评论 ·
维护者通常 1 天内回复
-
misleading subtitle with check_heteroscedasticity with binomial data?可能已有人在做 @jmgirard 于 26 天前认领。 未关闭Consistency :green_apple: :apple: Docs :books:
easystats/performance#1003 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
`check_outliers()`: Cook's distances land on the wrong rows when the model skips or reorders rows未关闭3 investigators :grey_question::question: Bug :bug:
难度 4/5 3-5 天 新手友好度 22/100
easystats/performance#981 · 1 条评论 ·
维护者通常 1 天内回复
-
Docs :books: Enhancement :boom:
难度 5/5 一周以上 新手友好度 45/100
easystats/performance#901 · 2 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
查看 easystats/performance 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
ThinkR-open/mordew#89 ·
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
epiforecasts/EpiNow2#1694 · 2 个 reaction ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
easystats/correlation#403 ·
-
难度 1/5 1 小时以内 新手友好度 85/100
mitchelloharawild/mixtime#111 ·
-
难度 2/5 1-3 小时 新手友好度 62/100
conda-forge/xgboost-feedstock#313 ·