gpt4 book ai didi

Python pyvttbl方差分析错误

转载 作者:行者123 更新时间:2023-11-28 19:08:12 25 4
gpt4 key购买 nike

我正在尝试使用 pyvttbl 对我的数据集执行方差分析,但出现了一个奇怪的错误。

这是我的代码:

import pyvttbl

df = pyvttbl.DataFrame()
df.read_tbl("ANOVA_MWE_input.csv")

print df
print type(df)

AN = df.anova('len', sub='id', bfactors=['p1', 'p2'])

输出是:

id   name   len   p1   p2 
=========================
0 AAA 32 1 0
1 BBB 33 2 0
2 CCC 29 3 0
3 DDD 22 4 0

<class 'pyvttbl.base.DataFrame'>

Traceback (most recent call last):File "/home/stefano/ownCloud/PycharmProjects/Stockh_cours/ANOVA_MWE.py", line 15, in <module>
AN = df.anova('len', sub='id', bfactors=['p1', 'p2'])
File "/usr/local/lib/python2.7/dist-packages/pyvttbl/base.py", line 1975, in anova
measure=measure, transform=transform, alpha=alpha)
File "/usr/local/lib/python2.7/dist-packages/pyvttbl/stats/_anova.py", line 713, in run
self._between()
File "/usr/local/lib/python2.7/dist-packages/pyvttbl/stats/_anova.py", line 751, in _between
cw = self._num2binvec(e,Nf)
File "/usr/local/lib/python2.7/dist-packages/pyvttbl/stats/_anova.py", line 1240, in _num2binvec
return list(array(list(zeros((p-len(b))))+b)+1.)
TypeError: 'float' object cannot be interpreted as an index

我真的不明白我的数据集中哪里有浮点对象。你能帮忙吗?实际上,当我将它应用到我的真实表时,我得到了一个超出范围的错误。奇怪的是,对于只有 in_file 更改的 MWE,我得到了这个。

感谢任何建议。

最佳答案

我无法让 pyvttbl 工作,但我现在正在使用 statsmodels 的方差分析和多个比较模块,我很高兴,因为我得到了我需要的一切:

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

model = ols('weight ~ group', data=data).fit() # OLS regression
#print(model.summary()) # print F-stat, eta², P value but also test indicators for assumptions

anova_table = sm.stats.anova_lm(model, typ='II') # here we prepare a proper ANOVA table
print(anova_table)

sum_sq df F PR(>F)
group 3.76634 2.0 4.846088 0.01591
Residual 10.49209 27.0 NaN NaN

# we then prepare a multiple comparison set:
mult_comp = sm.stats.multicomp.MultiComparison(data['weight'], data['group'])
print(mult_comp.tukeyhsd()) # Tukey post-hoc testing, for example

Multiple Comparison of Means - Tukey HSD,FWER=0.05
============================================
group1 group2 meandiff lower upper reject
--------------------------------------------
ctrl trt1 -0.371 -1.0621 0.3201 False
ctrl trt2 0.494 -0.1971 1.1851 False
trt1 trt2 0.865 0.1739 1.5561 True
--------------------------------------------

然后我完成 Bonferroni 校正。

关于Python pyvttbl方差分析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44157465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com