Hugely different R2 values for slightly different models
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
まず、issue にある4モデルの 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分
- マージ済み PR(30日)
- 27
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 1週間以上 初心者へのやさしさ 45/100
easystats/performance#901 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 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 件 ·
メンテナーはふだん 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 ·