I'm using a Mixed effect model with statsmodel in python and I cannot find a way to plot the results by group level. My goal is to get to this kind of plot:

which is possible in R.
For reference, in my dataframe df I have three columns = metric, experiment_name, country.
This is the code I'm using
import statsmodels.api as sm
import statsmodels.formula.api as smf
formula = "metric ~ experiment_name"
md = smf.mixedlm(formula, df, groups=df["country"])
mdf = md.fit()
print(mdf.summary())
The main problem is that I cannot figure out how to get the group level results. I have googled quite a lot with no luck.
I found a way to get the results at group level, at least for the random effects.
mdf.random_effects
and to plot it a lollipop plot with matplotlib after converting the data to a dataframe and transposing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With