Skip to content
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

Fix lrtest for model families with dispersion #261

Merged
merged 3 commits into from
Aug 5, 2022
Merged

Fix lrtest for model families with dispersion #261

merged 3 commits into from
Aug 5, 2022

Conversation

nalimilan
Copy link
Member

@nalimilan nalimilan commented Aug 2, 2022

lrtest relied on the deviance rather than the log-likelihood, which is not correct for model families where a dispersion parameter needs to be taken into account. Scaling the deviance would be more efficient than computing the log-likelihood via loglikelihood, but there is currently no generic API for this and this may not work for non-GLM models.
We could imagine defining a likelihoodratio(m1, m2) = loglikelihood(m1) - loglikelihood(m2) method that packages could override for performance, but this may not be worth it.

Also make the check that more complex models have a strictly better fit than simpler nested ones less strict. The more complex model may have the same deviance, and due to approximations it may even have a slightly higher deviance.

Fixes JuliaStats/GLM.jl#490, #260.

`lrtest` relied on the deviance rather than the log-likelihood, which is
not correct for model families where a dispersion parameter needs to be
taken into account. Scaling the deviance would be more efficient than
computing the log-likelihood, but there is currently no generic API for this
and this may not work for non-GLM models, so simply call `loglikelihood`.
We could imagine defining a
`likelihoodratio(m1, m2) = loglikelihood(m1) - loglikelihood(m2)` method
that packages could override for performance, but this may not be worth it.

Also make the check that more complex models have a strictly better fit than
simpler nested ones less strict. The more complex model may have the same
deviance, and due to approximations it may even have a slightly higher deviance.
src/lrtest.jl Outdated Show resolved Hide resolved
src/lrtest.jl Outdated Show resolved Hide resolved
src/lrtest.jl Outdated Show resolved Hide resolved
@nalimilan
Copy link
Member Author

nalimilan commented Aug 5, 2022

@palday I've noticed that MixedModels.jl uses the deviance for likelihoodratiotest, except for linear models where -2loglikelihood is used. AFAICT this doesn't give correct results for GLMs with a dispersion parameter, such as Gamma, like for lrtest, right? Do you also plan to switch to using loglikelihood?

src/lrtest.jl Outdated
for i in 2:length(ll)
if ((forward && ll[i-1] > ll[i]) ||
(!forward && ll[i-1] < ll[i])) &&
ll[i-1] ≉ ll[i]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was actually part of my earlier comment but got lost because the remainder of the comment was beefy. Should we allow the user to provide a tolerance for this check? We already have an atol argument used for checking whether the models are nested, perhaps it would make sense to reuse that here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah why not. I've pushed a commit to do that. BTW I discovered that the condition was backwards!

@palday
Copy link
Member

palday commented Aug 5, 2022

@nalimilan we should change (and will 😉), although currently we don't support GLMMs with a dispersion parameter:

https://github.com/JuliaStats/MixedModels.jl/blob/ea9b86eb816f4047e59aaa1a3d78a390c268ee3f/src/generalizedlinearmixedmodel.jl#L373-L377

and so we don't have to worry about the comparison to the GLM deviance. (The problem here with deviance vs. loglikelihood is actually deeply intertwined with the problem of fitting GLMMs with a dispersion parameter.)

For LMM, it doesn't matter since the "deviance" is indeed just the objective, which is -2 loglikelihood. (In practice, we can actually compute -2 loglikelihood directly and then use that to compute the loglikelihood.)

@nalimilan
Copy link
Member Author

Can you make a release if you're OK with the PR? I won't be on my computer for the next two weeks.

@ararslan ararslan merged commit 24a4e47 into master Aug 5, 2022
@ararslan ararslan deleted the nl/lrtest branch August 5, 2022 22:10
@kleinschmidt kleinschmidt mentioned this pull request Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lrtest gives incorrect results
4 participants