4.2 C
London
Friday, December 20, 2024
HomePythonProbability Distributions in PythonHow to Find a P-Value from a t-Score in Python

How to Find a P-Value from a t-Score in Python

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

Often in statistics we’re interested in determining the p-value associated with a certain t-score that results from a hypothesis test. If this p-value is below some significance level, we can reject the null hypothesis of our hypothesis test.

To find the p-value associated with a t-score in Python, we can use the scipy.stats.t.sf() function, which uses the following syntax:

scipy.stats.t.sf(abs(x), df)

where:

  • x: The t-score
  • df: The degrees of freedom

The following examples illustrate how to find the p-value associated with a t-score for a left-tailed test, right-tailed test, and a two-tailed test.

Left-tailed test

Suppose we want to find the p-value associated with a t-score of -0.77 and df = 15 in a left-tailed hypothesis test.

import scipy.stats

#find p-value
scipy.stats.t.sf(abs(-.77), df=15)

0.2266283049085413

The p-value is 0.2266. If we use a significance level of α = 0.05, we would fail to reject the null hypothesis of our hypothesis test because this p-value is not less than 0.05.

Right-tailed test

Suppose we want to find the p-value associated with a t-score of 1.87 and df = 24 in a right-tailed hypothesis test.

import scipy.stats

#find p-value
scipy.stats.t.sf(abs(1.87), df=24)

0.036865328383323424

The p-value is 0.0368. If we use a significance level of α = 0.05, we would reject the null hypothesis of our hypothesis test because this p-value is less than 0.05.

Two-tailed test

Suppose we want to find the p-value associated with a t-score of 1.24 and df = 22 in a two-tailed hypothesis test.

import scipy.stats

#find p-value for two-tailed test
scipy.stats.t.sf(abs(1.24), df=22)*2

0.22803901531680093

To find this two-tailed p-value we simply multiplied the one-tailed p-value by two.

The p-value is 0.2280. If we use a significance level of α = 0.05, we would fail to reject the null hypothesis of our hypothesis test because this p-value is not less than 0.05.

Related: You can also use this online T Score to P Value Calculator to find p-values.

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories