SciPy

scipy.stats.ttest_ind_from_stats

scipy.stats.ttest_ind_from_stats(mean1, std1, nobs1, mean2, std2, nobs2, equal_var=True)[source]

T-test for means of two independent samples from descriptive statistics.

This is a two-sided test for the null hypothesis that two independent samples have identical average (expected) values.

Parameters
mean1array_like

The mean(s) of sample 1.

std1array_like

The standard deviation(s) of sample 1.

nobs1array_like

The number(s) of observations of sample 1.

mean2array_like

The mean(s) of sample 2

std2array_like

The standard deviations(s) of sample 2.

nobs2array_like

The number(s) of observations of sample 2.

equal_varbool, optional

If True (default), perform a standard independent 2 sample test that assumes equal population variances [1]. If False, perform Welch’s t-test, which does not assume equal population variance [2].

Returns
statisticfloat or array

The calculated t-statistics

pvaluefloat or array

The two-tailed p-value.

Notes

New in version 0.16.0.

References

1(1,2)

https://en.wikipedia.org/wiki/T-test#Independent_two-sample_t-test

2(1,2)

https://en.wikipedia.org/wiki/Welch%27s_t-test

Examples

Suppose we have the summary data for two samples, as follows:

                 Sample   Sample
           Size   Mean   Variance
Sample 1    13    15.0     87.5
Sample 2    11    12.0     39.0

Apply the t-test to this data (with the assumption that the population variances are equal):

>>> from scipy.stats import ttest_ind_from_stats
>>> ttest_ind_from_stats(mean1=15.0, std1=np.sqrt(87.5), nobs1=13,
...                      mean2=12.0, std2=np.sqrt(39.0), nobs2=11)
Ttest_indResult(statistic=0.9051358093310269, pvalue=0.3751996797581487)

For comparison, here is the data from which those summary statistics were taken. With this data, we can compute the same result using scipy.stats.ttest_ind:

>>> a = np.array([1, 3, 4, 6, 11, 13, 15, 19, 22, 24, 25, 26, 26])
>>> b = np.array([2, 4, 6, 9, 11, 13, 14, 15, 18, 19, 21])
>>> from scipy.stats import ttest_ind
>>> ttest_ind(a, b)
Ttest_indResult(statistic=0.905135809331027, pvalue=0.3751996797581486)

Previous topic

scipy.stats.ttest_ind

Next topic

scipy.stats.ttest_rel