-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Deviances to LRT output #806
base: main
Are you sure you want to change the base?
Conversation
R/test_likelihoodratio.R
Outdated
p <- stats::pchisq(chi2, abs(dfs_diff), lower.tail = FALSE) | ||
|
||
out <- data.frame( | ||
Dev = devs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd call it Deviance
no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
While we're at it, could we add a couple of sentences to the function description about what it does, what it's comparing etc. (because its documentation is pretty bare bones for now) |
It is pulling in the docs from |
No I meant for the general docs. I forgot it took some from the general function, up to you then if there's any details you think are worth mentioning if not it's good to go |
I think we can push it then. |
hm, why are snapshots removed? I can add them back later. |
Not sure. I cloned the main branch and just got those errors. I can write a few tests tonight or tomorrow. |
I added deviance and tests for MLMs. We can probably do the same thing for OLS models but it's a bit tricky because "deviance" has a different meaning there. The chi-square is still based on -2*logLik but it isn't called a deviance in that context. |
It's not? I've always heard it called deviance in that context too |
I believe in OLS "deviance" is defined as the residual sum of squares. # Fit model in OLS
fit <- lm(Sepal.Width ~ 1 + Species, data = iris)
# Get deviance in base R
deviance(fit)
#> [1] 16.962
# Get deviance in easystats
insight::get_deviance(fit)
#> [1] 16.962
# Get RSS for comparison
sum(resid(fit)^2)
#> [1] 16.962
# Get -2logLik in base R
-2 * logLik(fit)
#> 'log Lik.' 98.7326 (df=4)
# Get -2logLik in easystats
-2 * insight::get_loglikelihood(fit)
#> 'log Lik.' 98.7326 (df=4) |
Do we think it would be clearer to call this column (a) Deviance for GLM and MLM but -2LL or N2LL for OLS or (b) -2LL or N2LL for all models? |
How about something more generic like |
Difference would work well for GLM where the deviance is a comparison to a saturated model, but that doesn't fit as well for OLS or MLM. I think I personally prefer -2LL with a definition in the documentation, but maybe |
I also just found an edge-case where base R disagrees with insight: when fitting a fixed effects model in glmmTMB. Might be worth discussing if this is desired (or I could open a new issue on insight - just let me know): fit <- glmmTMB::glmmTMB(Sepal.Length ~ 1 + Species, data = iris)
# Base R deviance = RSS
deviance(fit)
#> [1] 38.9562
# Insight deviance = -2LL
insight::get_deviance(fit)
#> [1] 223.452
logLik(fit)*-2
#> 'log Lik.' 223.452 (df=4) |
Why not "Criterion", but "N2LL" seems a bit too cryptic |
Thanks, look good! I'll review the next days and then we can merge it. |
I'll be adding a little bit more soon. Maybe best to wait before final merge. |
This helps make it clearer which model is best and aids in teaching. Could put the Log Likelihood in there instead, but it is the deviances that the LRT is comparing. Could also move the column left of Chi2 to emphasize that the Chi2 are the differences in deviances.