Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

stats.ttest_ind: extract df value

I am using stats.ttest_ind:

a = list(range(0, 10))
b = list(range(20, 40, 2))
out = stats.ttest_ind(a, b)
print(out)

#Output
TtestResult(statistic=-11.443934479174386, pvalue=1.0790209865144616e-09, df=18.0)

I can extract statistic and pvalue using out[0] and out[1], but when I try to extract df with out[2], I get the following error: IndexError: tuple index out of range. out[-1] also does not work.

I have also tried the following code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

t_stat, pvalue, df = stats.ttest_ind(a,b)

but this resulted in the following error: ValueError: not enough values to unpack (expected 3, got 2)

It seems as if the df value is not in out as soon as I try to extract it. out has length 2 and I can only get the first 2 elements.
Does anyone know what happens here or how I can solve this?

>Solution :

out is a scipy.stats._stats_py.TtestResult object.

You can fetch degrees of freedom by:

out.df
#18.0

If you do:

list(out)

you get:

[-11.443934479174386, 1.0790209865144618e-09]

So, out[2] and out[-1] will not give df.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading