'How to fit a mixed model with a skew normal distribution in python?

I am not sure if this is the best place to ask this so if not, please let me know,

however I am using StatsModels to create a mixed effects model that assesses the relationship between a factored predictor and continuous dependent variable, taking into account group effects.

model = smf.mixedlm("continuous_dv ~ factored_predictor", df, groups=df['group'])

The challenge is that the underlying data has a skewed normal distribution, and I am not sure how to fit a mixed model with that distribution in Python?

In R there is a package skewlmm which allows for this, and I am wondering what the counterpart would be in Python (if it exists?).

I have seen the following links

SciPy skewnormal fitting

and similar which show how to fit data INTO a skew normal distribution by using skewnormfit()

Any advice or direction would be greatly appreciated!



Solution 1:[1]

Looks like there is some potential with this - a Python interface for the R package brms which can fit Bayesian mixed effects models with a skew normal distribution (and more).

https://github.com/adamhaber/pybrms

Solution 2:[2]

The challenge is that the underlying data has a skewed normal distribution, and I am not sure how to fit a mixed model with that distribution in Python?

The distribution of the data is not a concern.

There is no requirement for the response variable itself to be normally distributed in a linear mixed model (LMM). It is the distribution of the response, conditional on the random effects, that is assumed to be normally distributed. This means that the residuals should be (approximately) normally distributed. Therefore, you can proceed with fitting an LMM and then check the residuals to see if they are normally distributed.


Edit:

If you find that you actually do need do need to hande skewed residuals, then this can sometimes be achieved by transforming the data, or fitting a GLMM. If all that fails then your self-answer, about using the python interface for the the R brms package, pybrms is a very good one.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user
Solution 2