Solved – Paired samples t test in Python

paired-datapythonstatsmodelst-test

I'm trying to conduct a paired samples t-test in Python (statsmodels package), but I don't see a function for it in their documentation. The closest I can find is ttost_paired, but I don't think its correct as their null hypothesis is that the mean difference is > or < some boundary value, whereas for my desired test the null is x1 - x2 = 0

A few questions:

  1. Is there a way to do a paired samples t-test in statsmodels that I'm missing?
  2. Is there a way to use ttost_paired to do what I want?
  3. They do also have an independent samples ttest. What could go wrong if I use an independent ttest on paired data?

I know I can do a paired t-test using scipy but I'm wondering specifically about statsmodels

Best Answer

the function ttost is not a t-test and therefore is not suitable for your purposes. The TTOST is a test of non-equivalence. It employes two one-sided t-tests in order to verify if both samples are equivalent or not. Please, have a look at the function documentation.

There exists the ttest_mean function on the statsmodels package. However, it does not indicate if the test is conducted with paired samples or not. Thus, I recommend you to use the scipy.stats t-test.

And about your last question:

They do also have an independent samples ttest. What could go wrong if I use an independent ttest on paired data?

The paired t-test reduces intersubject variability. Thus, it is theoretically more powerful than the unpaired t-test.