Implementing P-value in Python
Let’s consider a scenario where a tutor believes that the average exam score of their students is equal to the national average (85). The tutor collects a sample of exam scores from their students and performs a one-sample t-test to compare it to the population mean (85).
- The code performs a one-sample t-test to compare the mean of a sample data set to a hypothesized population mean.
- It utilizes the scipy.stats library to calculate the t-statistic and p-value. SciPy is a Python library that provides efficient numerical routines for scientific computing.
- The p-value is compared to a significance level (alpha) to determine whether to reject the null hypothesis.
Python3
import scipy.stats as stats # exam scores sample_data = [ 78 , 82 , 88 , 95 , 79 , 92 , 85 , 88 , 75 , 80 ] # Population mean population_mean = 85 # One-sample t-test t_stat, p_value = stats.ttest_1samp(sample_data, population_mean) print ( "t-statistic:" , t_stat) print ( "p-value:" , p_value) # Conditions alpha = 0.05 if p_value < alpha: print ( "Reject the null hypothesis. There is enough evidence to suggest a significant difference." ) else : print ( "Fail to reject the null hypothesis. The difference is not statistically significant." ) |
Output:
t-statistic: -0.3895364838967159
p-value: 0.7059365203154573
Fail to reject the null hypothesis. The difference is not statistically significant.
Since, 0.7059>0.05, we would conclude to fail to reject the null hypothesis. This means that, based on the sample data, there isn’t enough evidence to claim a significant difference in the exam scores of the tutor’s students compared to the national average. The tutor would accept the null hypothesis, suggesting that the average exam score of their students is statistically consistent with the national average.
P-Value: Comprehensive Guide to Understand, Apply, and Interpret
A p-value is a statistical metric used to assess a hypothesis by comparing it with observed data.
This article delves into the concept of p-value, its calculation, interpretation, and significance. It also explores the factors that influence p-value and highlights its limitations.
Table of Content
- What is P-value?
- How P-value is calculated?
- How to interpret p-value?
- P-value in Hypothesis testing
- Implementing P-value in Python
- Applications of p-value