在Python中按组绘制混合效果模型结果

问题描述 投票:0回答:1

我正在python中使用带有statsmodel的混合效果模型,但我找不到找到按组级别绘制结果的方法。我的目标是获得这种情节:

enter image description here

possible in R

作为参考,在我的数据帧df中,我有三列= metricexperiment_namecountry

这是我正在使用的代码

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())

主要问题是我无法弄清楚如何获得小组水平的结果。我用Google搜索了很多,没有运气。

python statsmodels mixed-models
1个回答
0
投票

[我找到了一种至少在随机效果上可以在小组级别获得结果的方法。

mdf.random_effects

并在将数据转换为数据帧并转置后将其绘制为lollipop plot with matplotlib

© www.soinside.com 2019 - 2024. All rights reserved.