【问题标题】:printing and storing results of t-test loop打印和存储 t-test 循环的结果
【发布时间】:2018-07-31 07:35:24
【问题描述】:

我有一个包含几个自变量和几个因变量的数据集,我想用它来运行多个 t 检验。我所有的独立变量都是假人,而我的依赖变量是数字。

我写了以下循环:

for ind in df[['ind1','ind2', 'ind3','ind4','ind5']]:
    for dep in df[['dep1', 'dep2', 'dep3', 'dep4']]:
        cat1 = df[df[ind]==1][dep]
        cat2 = df[df[ind]==0][dep]
        print(ttest_ind(cat1, cat2, equal_var=False))

我运行了代码,但脚本没有打印结果(不知道为什么..)。另外,我想将差异和 p 值存储在数据框中,以便稍后绘制它们.. 怎么做?谢谢!

【问题讨论】:

    标签: pandas iteration t-test


    【解决方案1】:

    我做到了!

    pvalue = []
    ttest = []
    deplist = []
    indlist =[] 
    
    for ind in monthly[['indvar1', 'indpvar2', 'indpvar3'...]]:
        for dep in monthly[['depvar1', 'depvar2'....]]:
            cat1 = monthly[monthly[ind]==1][dep]
            cat2 = monthly[monthly[ind]==0][dep]
            a, b = ttest_ind(cat1, cat2, equal_var=False)
            indlist.append(ind)
            deplist.append(dep)
            ttest.append(a)
            pvalue.append(b)
    

    【讨论】:

      猜你喜欢
      • 2013-02-28
      • 1970-01-01
      • 1970-01-01
      • 2017-05-20
      • 2022-10-06
      • 2010-12-21
      • 1970-01-01
      • 1970-01-01
      • 2018-07-02
      相关资源
      最近更新 更多