Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate the statistics "t-test" with numpy

I'm looking to generate some statistics about a model I created in python. I'd like to generate the t-test on it, but was wondering if there was an easy way to do this with numpy/scipy. Are there any good explanations around?

For example, I have three related datasets that look like this:

[55.0, 55.0, 47.0, 47.0, 55.0, 55.0, 55.0, 63.0] 

Now, I would like to do the student's t-test on them.

like image 592
Mark Avatar asked Feb 24 '10 07:02

Mark


People also ask

How do you find the t-test statistic in Python?

Typically is set to 0 and the 3rd hypothesis is being tested, i.e. there is no difference between the groups. The test statistic is the t value and can be calculated using the following formula: t = ( x ¯ 1 − x ¯ 2 ) − D 0 s p 1 n 1 + 1 n 2.

How do you find the t-test statistic?

To find the t value: Subtract the null hypothesis mean from the sample mean value. Divide the difference by the standard deviation of the sample. Multiply the resultant with the square root of the sample size.

Which function is used for t-test in Python?

We can calculate the t-test on these samples using the built in SciPy function ttest_ind().


1 Answers

In a scipy.stats package there are few ttest_... functions. See example from here:

>>> print 't-statistic = %6.3f pvalue = %6.4f' %  stats.ttest_1samp(x, m) t-statistic =  0.391 pvalue = 0.6955 
like image 136
van Avatar answered Sep 23 '22 20:09

van