partida
partida

Reputation: 501

Why ttest_ind in Scipy a little different from Excel TTest?

Scipy(Python):

from scipy import stats
a=[3,4,5,8,9,1,2,4,5,3,8]
b=[6,19,3,2,14,4,5,17,1,2,4]
stats.ttest_ind(a,b, equal_var=True)

Ttest_indResult(statistic=-1.0810463365416798, pvalue=0.29254014390233507)

Excel: enter image description here

The result of Scipy is 0.292540, Excel is 0.293487. What the correct grammar to make the result of Scipy like the TTEST(a, b, 2, 1)?

Upvotes: 1

Views: 799

Answers (1)

user6655984
user6655984

Reputation:

There is a difference between paired and unpaired two-sample t-tests: see Wikipedia. The last parameter of Excel's TTEST chooses between them:

=TTEST(A1:K1,A2:K2,2,1)   # paired, returns   0.293487072
=TTEST(A1:K1,A2:K2,2,2)   # unpaired, returns 0.292540144

In SciPy, these are done by

  • ttest_rel (paired; "rel" stands for related)
  • ttest_ind (unpaired, "ind" stands for independent)

With your a, b

stats.ttest_rel(a, b)                   # pvalue=0.2934870715776284
stats.ttest_ind(a, b, equal_var=True)   # pvalue=0.29254014390233507

Upvotes: 3

Related Questions