Python pyvttbl ANOVA error

Viewed 760

I am trying to perform ANOVA with pyvttbl over my dataset but I get a strange error.

Here is my code:

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'])

The output is:

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

I really don't understand where is a float object in my dataset. Can you help with this? Actually when I then apply this to my real table I get a out of range error. Weirdly with a MWE where only the in_file change I get this.

Thanks for any suggestion.

1 Answers

I cannot make pyvttbl working, but I am now using statsmodels' ANOVA and multiple comparison modules, and I am happy because I get all I need:

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

And then I complete with a Bonferroni correction.

Related