This page on the paired two one-sided t-tests procedure (‘paired TOST’) is a follow-on from this one which introduces the unpaired two one-sided t-tests procedure (‘unpaired TOST’)
We’ll use the same example data that was used on the unpaired TOST page. It comes from the documentation for Pingouin’s tost()
function.
# Example data
a = [4, 7, 8, 6, 3, 2]
b = [6, 8, 7, 10, 11, 9]
Use the tost()
function with paired=True
. For this example, let’s use a bound (region of similarity) of 0.5:
import pingouin as pg
pval = pg.tost(a, b, paired=True, bound=0.5).loc['TOST', 'pval']
print(f'TOST: p = {pval:.3f}')
## TOST: p = 0.955
The two one-sided paired t-tests can be done individually with SciPy (the relevant function is ttest_rel()
):
import numpy as np
from scipy import stats
# Convert data to arrays
a = np.array(a)
b = np.array(b)
#
# TOST
#
# Magnitude of region of similarity
bound = 0.5
# Paired two-sample t-test
_, p_greater = stats.ttest_rel(a + bound, b, alternative='greater')
_, p_less = stats.ttest_rel(a - bound, b, alternative='less')
# Choose the maximum p-value
pval = max(p_less, p_greater)
print(f'TOST: p = {pval:5.3f}')
## TOST: p = 0.955
The name of this test is a mouthful: the one-sample two one-sided t-tests procedure! As it suggests, this test uses one set of data instead of two. However, if that set of data happens to be the differences between two sets of data, then it (the one-sample TOST) becomes identical to the paired TOST. We will be able to see this if we use the exact same data as before:
# Example data
a = [4, 7, 8, 6, 3, 2]
b = [6, 8, 7, 10, 11, 9]
To perform the one-sample TOST with Pingouin’s tost()
function, set the second argument (the y-argument) to a single number, eg 0:
import numpy as np
import pingouin as pg
# Convert data to arrays
a = np.array(a)
b = np.array(b)
# Calculate the differences between the pairs of data points
diffs = b - a
# Perform the TOST
pval = pg.tost(diffs, y=0, bound=0.5).loc['TOST', 'pval']
print(f'TOST: p = {pval:.3f}')
## TOST: p = 0.955
As promised, the answer is the same as for the paired TOST.
The one-sample t-test function (ttest_1samp()
) can be used twice:
import numpy as np
from scipy import stats
# Convert to arrays
a = np.array(a)
b = np.array(b)
# Calculate the differences between the pairs of data points
diffs = b - a
#
# TOST
#
# Magnitude of region of similarity
bound = 0.5
# Two one-sample t-tests
_, p_greater = stats.ttest_1samp(diffs, -bound, alternative='greater')
_, p_less = stats.ttest_1samp(diffs, bound, alternative='less')
# Choose the maximum p-value
pval = max(p_less, p_greater)
print(f'TOST: p = {pval:5.3f}')
## TOST: p = 0.955
Again, we get the same answer.