Hugely different R2 values for slightly different models
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
首先复现 issue 中的四模型 MWE,并阅读用于 GLM 和混合模型计算的 performance::r2 入口点。比较报告中的 R2 定义以及针对 glmmTMB 模型的警告。完成的标准是解释清楚其中的差异,并在适当的情况下记录相关限制或可比性指导。
由索引模型根据 Issue 内容生成。
描述
I've been fitting some mixed models to genomic (transcriptomic) count data, and wanted to assess model fit. I've tried out a few models and a few options for R2, however they give wildly different R2 values.
I have a couple of questions:
- Could this be a bug? I kind of expect not, but worth checking.
- Are there reasons why this data is not appropriate for the Nakagawa R2 calculation? If so, are there general principles that could be added to the documentation?
- Are these different ways of calculating R2 just not comparable in this way? If so, hopefully this could be a useful case study.
Thanks!
Will
MWE
The data has 8 different celltypes, across 196 individuals (for almost all individuals we have all 8 possible values). counts corresponds to how many times we observe a given gene, libsize is the offset for this observation, and logcpm = log( counts / libsize * 1e6 + 1) i.e. log values slightly pushed away from 0 and normalized to the expected range.
Plotting these log values indicates that we expect both celltype and invididual to be relevant:


I fit 4 models and calculate R2 for each:
## model 1: negative binomial with random effect
fit_glmm = glmmTMB::glmmTMB(counts ~ celltype + (1|individual),
offset = log(libsize), data = data_dt, family = glmmTMB::nbinom2)
performance::r2(fit_glmm)
# # R2 for Mixed Models
# Conditional R2: 0.084
# Marginal R2: 0.054
# 4: mu of 0.0 is too close to zero, estimate of random effect variances may be
# unreliable.
## model 2: negative binomial without random effect
fit_glm = glm(counts ~ celltype,
offset = log(libsize), data = data_dt, family = glmmTMB::nbinom2)
performance::r2(fit_glm)
# # R2 for Generalized Linear Regression
# Nagelkerke's R2: 0.738
## model 3: log CPM with random effect
fit_lmer = lme4::lmer(logcpm ~ celltype + (1 | individual), data = data_dt)
performance::r2(fit_lmer)
# # R2 for Mixed Models
# Conditional R2: 0.444
# Marginal R2: 0.215
## model 4: log CPM without random effect
fit_lm = lm(logcpm ~ celltype, data = data_dt)
performance::r2(fit_lm)
# # R2 for Linear Regression
# R2: 0.214
# adj. R2: 0.211
The main thing I don't understand is why there is such a large difference between models 1 and 2. An R2 of 8% just doesn't seem plausible when the distributions are so tight (while an R2 of 74% for model 2 seems about right). The coefficient estimates are pretty similar, so it seems more likely that the difference comes from how the R2 is calculated, rather the fits being wildly different.
Does the warning for model 1 indicate that there are issues here? If so, what could they be? To me it doesn't seem like an unreasonably complex model for the data...
I've half-read the Nakagawa paper, so could it be that for model 1 the R2 is based on log values, while for R2 it uses deviance? Could that explain the huge difference?
(The differences between the GLM and log-linear models seem to make sense, as with many zeros present the GLM should better capture the data.)
- 主要语言
- 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 ·