How can I perform a likelihood ratio test on a linear mixed-effect model?
Asked Answered
C

1

11

The documentation for Statsmodels' linear mixed-effect models claims that

The Statsmodels LME framework currently supports post-estimation inference via Wald tests and confidence intervals on the coefficients, profile likelihood analysis, likelihood ratio testing, and AIC. [emphasis added]

I've noted the MixedLM.loglike method, but I can't seem to find a function/method for running a likelihood ratio test.

Could somebody kindly point me in the right direction?

Contravallation answered 30/5, 2015 at 2:18 Comment(0)
E
6

I'm running a development branch so things may have changed, but the results class returned by MixedLM.fit() should have an attribute called 'llf'. That is the value of the log-likelihood function at the estimated parameters. If you have two nested models and take -2 times the difference in their llf values, under the null hypothesis where the simpler model is true, this will be a chi^2 random variable with degrees of freedom equal to the difference in degrees of freedom for the two models.

Note that many people feel that you should switch the estimator to ML (not the default REML) when using LR tests.

Encratis answered 4/6, 2015 at 1:58 Comment(3)
To be more precise, llf is the value of the REML criterion if you are using reml=True in fit, and is the value of the log-likelihood function if you are using reml=False in fit.Encratis
Thank you very much! How should I go about changing the estimator to ML? [The source](statsmodels.regression.mixed_linear_model.MixedLM) doesn't seem to have any arguments for specifying an estimator. Should I manually set MixedLM.reml to False?Contravallation
@blz You should do, model.fit(reml=False)Marbles

© 2022 - 2024 — McMap. All rights reserved.