Calculates the T-test for the means of TWO INDEPENDENT samples of scores.
This is a two-sided test for the null hypothesis that 2 independent samples have identical average (expected) values.
a, b : sequence of ndarrays
axis : int, optional
t : float or array
prob : float or array
We can use this test, if we observe two independent samples from the same or different population, e.g. exam scores of boys and girls or of two ethnic groups. The test measures whether the average (expected) value differs significantly across samples. If we observe a large p-value, for example larger than 0.05 or 0.1, then we cannot reject the null hypothesis of identical average scores. If the p-value is smaller than the threshold, e.g. 1%, 5% or 10%, then we reject the null hypothesis of equal averages.
>>> from scipy import stats >>> import numpy as np
>>> #fix seed to get the same result >>> np.random.seed(12345678)
test with sample with identical means
>>> rvs1 = stats.norm.rvs(loc=5,scale=10,size=500) >>> rvs2 = stats.norm.rvs(loc=5,scale=10,size=500) >>> stats.ttest_ind(rvs1,rvs2) (0.26833823296239279, 0.78849443369564765)
test with sample with different means
>>> rvs3 = stats.norm.rvs(loc=8,scale=10,size=500) >>> stats.ttest_ind(rvs1,rvs3) (-5.0434013458585092, 5.4302979468623391e-007)