Curriculum
Course: SCIPY
Login
Text lesson

T-Test

T-tests are used to assess if there is a significant difference between the means of two variables and determine if they belong to the same distribution.

It is a two-tailed test.

The ttest_ind() function takes two samples of the same size and returns a tuple containing the t-statistic and p-value.

Example

Determine if the given values, v1 and v2, come from the same distribution.

import numpy as np
from scipy.stats import ttest_ind

v1 = np.random.normal(size=100)
v2 = np.random.normal(size=100)

res = ttest_ind(v1, v2)

print(res)

Result:

Ttest_indResult(statistic=0.40833510339674095, pvalue=0.68346891833752133)

To return only the p-value, use the pvalue property.

Example


res = ttest_ind(v1, v2).pvalue

print(res)

Result:

0.68346891833752133