Solved – How to interpret results of two-sample, one-tailed t-test in Scipy

hypothesis testinginferencescipyt-testtwo-sample

I want to perform a two-sample, one-tailed t-test to compare two means. For the specific problem I am looking, I want the comparison to only be in one direction. I would like the null hypothesis to be that mu_2 > mu_1 and the alternative hypothesis to be mu_1 <= mu_2. Or should the null hypothesis still be that mu_1 – mu_2 = 0, even for the one-tailed case?

I am working with a large dataset, but if I were to extract and round the parameters, for data_1 it is mu_1 = 4.3, s_1 = 4.8, and n_1 = 40000 and data_2 it is mu_2 = 4.9, s_2 = 4.4, n_2 = 30000. I am using scipy to perform a two-sample t-test:

stats.ttest_ind(data1,
                data2,
                equal_var = False)

Given that scipy only takes into account a two-tail test, I am not sure how to interpret the values. Ttest_indResult(statistic=-19.51646312898464, pvalue=1.3452106729078845e-84). The alpha value is 0.05, and the p-value is much much smaller than that which would mean the null hypothesis is rejected. However, my intuition tells me that the null hypothesis should not be rejected, because mu_2 is clearly larger than mu_1 (at the very minimum I would expect the p-value to be larger). Therefore, I feel like I'm either interpreting the results incorrectly or need to additional calculations to get the correct answer.

I would appreciate any additional help and guidance. Thanks!

python scipy statistics inference t-test

Best Answer

The default is a two-sided test. Look at the documentation for how to set the alternative hypothesis you want.

If, however, you want to test a one-sided hypothesis, but what you observe is in the opposite direction (e.g. testing $H_a: \mu_1>\mu_2$ but observing $\bar{x}_1<\bar{x}_2$), your p-value is going to exceed $0.50$. Running the hypothesis test in that case is unnecessary; you know you won’t be able to reject.