scipy.stats.mstats.ttest_ind

scipy.stats.mstats.ttest_ind(a, b, axis=0)

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.

Parameters :

a, b : sequence of ndarrays

The arrays must have the same shape, except in the dimension corresponding to axis (the first, by default).

axis : int, optional

Axis can equal None (ravel array first), or an integer (the axis over which to operate on a and b).

Returns :

t : float or array

t-statistic

prob : float or array

two-tailed p-value

Notes

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.

Examples

>>> 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)

Previous topic

scipy.stats.mstats.ttest_onesamp

Next topic

scipy.stats.mstats.ttest_onesamp

This Page