pythonexcelscipyt-test

Why scipy and Excel generate slightly different p-value for two-sample t-test?


For python, it is two-side test by default:

from scipy import stats
import numpy as np
wt = np.array([71.93636,71.34689,72.2162])
mut = np.array([71.58995,70.82698,70.89562])
t, p = stats.ttest_ind(wt, mut, equal_var=False)
print(t,p)

I got

2.06163943002 0.108425721876

In Excel, Data tab - Data Analysis - t-Test: Two-Sample Assuming Unequal Variances, I got same value for t, but slightly different value for p (0.1084... vs 0.1082...)

Can I ask why?

enter image description here


Solution

  • If you use

    from scipy import stats
    stats.ttest_rel(wt,mut)
    

    it should match the same calculations in Excel.

    rel is for related samples and ind is for independent samples.