Comments (4)
r2_nakagawa()
is indeed not useful when you don't have random effects. See following example, which also compares to ordinary lm()
.
library(performance)
library(glmmTMB)
library(MuMIn)
data(Owls)
m_NORAND <- glmmTMB(NegPerChick ~ BroodSize + ArrivalTime, data = Owls)
r2(m_NORAND)
#> Random effect variances not available. Returned R2 does not account for random effects.
#> # R2 for Mixed Models
#>
#> Conditional R2: NA
#> Marginal R2: 0.127
r.squaredGLMM(m_NORAND)
#> Warning: 'r.squaredGLMM' now calculates a revised statistic. See the help page.
#> Warning in r.squaredGLMM.glmmTMB(m_NORAND): the effects of zero-inflation and
#> dispersion model are ignored
#> R2m R2c
#> [1,] 0.05606123 0.05606123
m_easy <- lm(NegPerChick ~ BroodSize + ArrivalTime, data = Owls)
r.squaredGLMM(m_easy)
#> R2m R2c
#> [1,] 0.05579612 0.05579612
r2(m_easy)
#> # R2 for Linear Regression
#> R2: 0.056
#> adj. R2: 0.053
Created on 2023-11-21 with reprex v2.0.2
Conclusion: For non-mixed models, don't use r2_nakagawa()
. I think we can, however, automatically fall back to manual r2-calculations, so that r2_nakagawa()
also works for your example:
r <- residuals(m_NORAND)
f <- fitted(m_NORAND)
rss <- sum(r^2)
mss <- sum((f - mean(f))^2)
mss / (mss + rss)
#> [1] 0.05597288
from performance.
@julian-wittische , I'd highly recommend that in future you post code/output examples as text (in a code block, which you can delimit with triple-backticks -- you can also click the "<>" icon in the graphical options in the compose window) rather than as an image. It makes life easier for readers in many ways. (Good question though.)
from performance.
This is what is (quickly) implemented in PR #653 for now:
library(performance)
library(glmmTMB)
library(MuMIn)
data(Owls)
m_NORAND <- glmmTMB(NegPerChick ~ BroodSize + ArrivalTime, data = Owls)
r2(m_NORAND)
#> # R2 for Linear Regression
#> R2: 0.056
r.squaredGLMM(m_NORAND)
#> Warning: 'r.squaredGLMM' now calculates a revised statistic. See the help page.
#> Warning in r.squaredGLMM.glmmTMB(m_NORAND): the effects of zero-inflation and
#> dispersion model are ignored
#> R2m R2c
#> [1,] 0.05606123 0.05606123
Needs some testing, though, and I have to look which type of residuals are the most appropriate here.
from performance.
Thank you very much for the clarification and the fix.
from performance.
Related Issues (20)
- difficult-to-diagnose errors using "difftime" response in a linear model HOT 9
- `check_singularity` doesn't work for `glmmTMB` HOT 9
- `icc` doesn't work for `glmmTMB` HOT 4
- R-squared for Dirichlet regression (`r2`)
- QQ plot blank in check model for glmmTMB with tweedie distribution HOT 4
- Error checking normality for t.test HOT 1
- spurious(?) viewport-too-small error with new ggplot2 version 3.5.0 HOT 11
- incorrect warning with old `ggplot2`/failure to load `see` HOT 2
- check_model "Error in match.arg" HOT 5
- Error in performance::check_distribution(): in call bw.SJ() HOT 2
- Revising `check_model()` HOT 1
- check_model failing on logistic regression HOT 2
- Check_model in version 0.11.0 no longer produces qq plot residuals HOT 19
- r2_nakagawa and glmmTMB with beta_family HOT 4
- Outlier detection in Linear mixed models failed? HOT 5
- cannot apply check_model title with patchwork::plot_annotation HOT 4
- check_model error suggestions are not complete HOT 4
- Error and Incomplete Output Using performance::check_collinearity with Cox Models HOT 1
- Normality of Residuals of check_model is abnormal. HOT 2
- Revise compare_models() for Bayesian models HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from performance.