Python中双向方差分析的Holm方法(事后检验)

2024-04-23 21:40:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个双向方差分析模型,我想在上面运行Holm的方法。我希望看到所有的比较。每个IV有2个级别

import statsmodels.api as sm
from statsmodels.formula.api import ols

model_z = ols('z_esti ~ C(control) + C(agent) + C(control):C(agent)', data=alldata).fit()
z = sm.stats.anova_lm(model_z, typ=2)

z_esti是响应变量,controlagent是预测因子,每个具有2个水平。我知道如何用一个变量执行Holm的方法:

from statsmodels.stats.multicomp import (pairwise_tukeyhsd, MultiComparison)
agentComp = multicomp(alldata['z_esti'], alldata['agent'])
def Holm_Bonferroni(multiComp):
    # Instead of the Tukey's test, we can do pairwise t-test     
    # First, with the "Holm" correction
    rtp = multiComp.allpairtest(stats.ttest_rel, method='Holm')
    print((rtp[0]))
      
    # and then with the Bonferroni correction
    print((multiComp.allpairtest(stats.ttest_rel, method='b')[0]))
      
    # Any value, for testing the program for correct execution
    checkVal = rtp[1][0][0,0]
    return checkVal

Holm_Bonferroni(agentComp)

我不知道如何处理两个变量。本质上,我不知道如何为多个变量在allpairtest方法中编写groupskwrg。感谢您的帮助


Tags: the方法importapistatscontrolagentstatsmodels