Likelihood Ratio Test?

Hey everyone,

I am looking for a way to do Likelihood Ratio Tests in Julia. I have found a function in MixedModels.jl (which is also what I am using to fit my models), but it doesn’t seem to work for Generalized Linear Mixed models … ?

This is the error message I am getting:

MethodError: no method matching likelihoodratiotest(::GeneralizedLinearMixedModel{Float64})
Closest candidates are:
  likelihoodratiotest(!Matched::LinearMixedModel...) at C:\Users\bjoer\.julia\packages\MixedModels\ALNok\src\linearmixedmodel.jl:412

I have found a post back from 2017 by the creator of the MixedModels.jl package, saying that they implemented the LRT for Linear Mixed Models upon request. Has anything happened in the mean time to make the LRT available for GLMMs, too?

The implementation of MixedModels.likelihoodratiotest() doesn’t look hyper complicated, so I might be able to adapt it myself for GLMMs, but I’m kind of bad at stuff and it would probably take me ages, so if there’s anything out there, I’d rather rely on preexisting code:)

See Docs: HypothesisTests package · HypothesisTests.jl
@Nosferican brought up this issue in 2017: Tests for RegressionModel · Issue #121 · JuliaStats/HypothesisTests.jl · GitHub

1 Like

This should work in the current development version.

1 Like

Thanks for the responses!

I looked into it and I’m not sure this is what I am looking for. I want to compare two statistical models (GeneralizedMixedModels) in terms of their goodness of fit (much like anova(GLM1,GLM2) in R). The test to which you are linking me seems to be a significance test between two distributions? I don’t see how I would apply this test to already fitted statistical models.

In the development version of MixedModels, there is a (non-exported) function MixedModels.likelihoodratiotest that will work for GLMMs. It’s incompatible with the proposal for StatsModels.lrtest in terms of the internal structure of the result, but that’s irrelevant if you’re just looking at the printed output. (This incompatibility is one of the reasons why it’s not exported and uses a slightly different name – we wanted to have this functionality, but didn’t want to constrain ourselves to an ‘externa’ format until that format was finalized.) Non-exported just means that you have to specify the package name when invoking it, i.e. MixedModels.likelihoodratiotest, not that it’s private or off-limits.

Since you seem to be getting into GLMM code: GLMMs have been getting a lot of love in recent development versions, so if something doesn’t work in the release version, do try out the development version! For a casual user, most changes are just improvements, but if you start manipulating results structures directly, then you’ll discover that we are reworking various structures. So, the display won’t change much, but if you manipulate results programmatically, things might break. :confused:

Okay great, MixedModels.likelihoodratiotest works like a charm, and that was exactly what I was looking for. (Also thanks for the help over on GitHub!)

For context: I am working on recommendations for power analyses for a specific type of data, and I am looking into the best configuration of the different parameters in Julia. I got way too many false positives for the z score based pvalue for a fixed effects interaction, so I wanted to see how I fare with the LRT.

Thanks for letting me know about the work on GLMM, I’ll be careful!

Anyway, the question is solved, thanks again!

1 Like

is there a timeline for this to make it into the release version?

1 Like

It’s been in the current release version for a few months now, for both StatsModels.lrtest and MixedModels.likelihoodratiotest.

3 Likes

That’s nice. I’ll be able to compare the results to the one i hacked together :wink:

There is a stagnant PR in GLM here that should help with likelihood ratio tests in GLM. But I ran into some roadblocks and haven’t persisted through.

2 Likes