Giter VIP home page Giter VIP logo

Comments (4)

strengejacke avatar strengejacke commented on June 18, 2024 1

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.

bbolker avatar bbolker commented on June 18, 2024 1

@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.

strengejacke avatar strengejacke commented on June 18, 2024 1

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.

julian-wittische avatar julian-wittische commented on June 18, 2024

Thank you very much for the clarification and the fix.

from performance.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.