We can calculate the p-value from the t-statistic using the following Python code:
from scipy import stats degrees_of_freedom = 19 # p_value for left-tailed test t_score = -1.0017194659421818 p_value = stats.t.sf(abs(t_score), df=degrees_of_freedom) print("p-value for left-tailed test: ", p_value) # p_value for right-tailed test t_score = 1.0017194659421818 p_value = stats.t.sf(abs(t_score), df=degrees_of_freedom) print("p-value for right-tailed test: ", p_value) # p_value for two-tailed test t_score = 1.0017194659421818 p_value = stats.t.sf(abs(t_score), df=degrees_of_freedom)*2 print("p-value for two-tailed test: ", p_value)
Here, we are using the t.sf() function from the scipy.stats module to calculate the p-value from the t-statistic for a particular degrees of freedom. Please note that for a one-sample t-test and paired t-test, the degrees of freedom is (sample size – 1). And for a two-sample t-test, the degrees of freedom is (sample size of the first group + sample size of the second group – 2).
t.sf() function is called the survival function. It is also defined as (1 – cdf), where cdf is the cumulative distribution function. Please note that sf is sometimes more accurate than (1 – cdf). So, it is recommended to use the SF function to calculate the p-values.
For a left tailed t-test, the p_value can be calculated as: …






0 Comments