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

Data is a valuable asset that plays a crucial part in today's society, as everything is strongly dependent on data. Today, all technologies are data-driven, and massive volumes of data are generated on a regular basis. Data is unprocessed information that...

Data is a valuable asset that plays a crucial part in today's society, as everything is strongly dependent on data. Today, all technologies are data-driven, and massive volumes of data are generated on a regular basis. Data is unprocessed information that data scientists learn to exploit. A data scientist is a professional who analyses data sources, cleans and processes the data in order to understand why and how the data was created, in order to provide insights to support business choices, and hence profits for the company. To detect patterns and trends in data, data scientists employ a mix of statistical formulae and computer algorithms. In this post, we will look closely at P-value and t-Score, as well as how to find a P-Value from a t-Score in Python.

What is P-value?

In statistics, the p-value is the chance of generating outcomes at least as severe as the observed results of a statistical hypothesis test, provided that the null hypothesis is valid. The p-value is used in place of rejection points to show the least level of significance at which the null hypothesis would be rejected. A lower p-value indicates that there is more evidence in f**or of the alternative hypothesis.

What is the t-score?

The number of standard deviations from the t-mean distribution is the same as a t-score, also known as a t-value. In t-tests and regression analyses, the test statistic employed is the t-score. When data follow a t-distribution, it can also be used to indicate how distant an observation is from the mean.

Figuring out P-value from t-score in Python

The scipy.stats.t.sf() function in Python has the following syntax, and it can be used to obtain the p-value corresponding to a given t-score −scipy.stats.t.sf(abs(x), df)

where −

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

1. Left-tailed test

Let's say we wish to get the p-value for a left-tailed hypothesis test with a t-score of −0.77 and df = 15.

Example

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

Output

0.2266283049085413

A 0.2266 p-value is used. As this p-value is not less than 0.05, we would not be able to reject the null hypothesis of our hypothesis test if we applied a significance threshold of = 0.05.

2. Right-tailed test

Let's say we wish to get the p-value for a right-tailed hypothesis test with a t-score of 1.87 and df = 24.

Example

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

Output

0.036865328383323424

0.0368 is the p-value. The null hypothesis of our hypothesis test would be rejected if we applied a significance threshold of = 0.05 because this p-value is less than 0.05.

3. Two-tailed test

Let's say we wish to get the p-value for a two-tailed hypothesis test with a t-score of 1.24 and df = 22.

Example

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

Output

0.22803901531680093

0.2280 is the p-value. As this p-value is not less than 0.05, we would not be able to reject the null hypothesis of our hypothesis test if we applied a significance threshold of = 0.05.

Conclusion

P-value and t-score were addressed here. Both of these are used in statistics to glean insights from data and aid in more accurate forecasting. Furthermore, using Python, we can calculate P-Value from a t-Score.

评论0

首页 导航 会员 客服