In hypothesis testing, what does the p-value tell us about the claim we are testing?
Think about what the p-value measures under the assumption that the null hypothesis holds.
The p-value measures how likely it is to get the observed data (or more extreme) if the null hypothesis is true. It does not directly tell us the probability that the null or alternative hypothesis is true.
Given the following Python code using scipy.stats, what is the output of the t-statistic and p-value?
from scipy import stats sample = [5, 7, 8, 6, 9, 7, 5] # Test if the sample mean is different from 6 result = stats.ttest_1samp(sample, 6) print(round(result.statistic, 2), round(result.pvalue, 3))
Calculate the sample mean and standard deviation, then apply the t-test formula or run the code.
The t-test compares the sample mean to the population mean 6. The calculated t-statistic is about 1.26 and the p-value about 0.250, meaning no strong evidence to reject the null hypothesis.
Two groups have the following data:
Group A: [12, 15, 14, 10, 13]
Group B: [8, 9, 7, 6, 10]
Using a two-sample t-test, what is the t-statistic and p-value?
from scipy import stats group_a = [12, 15, 14, 10, 13] group_b = [8, 9, 7, 6, 10] result = stats.ttest_ind(group_a, group_b) print(round(result.statistic, 2), round(result.pvalue, 3))
Calculate the means and variances of both groups, then apply the two-sample t-test or run the code.
The t-statistic is about 4.31 with a p-value of 0.002, indicating strong evidence that the two groups have different means.
Below is a plot showing the distribution of p-values from many hypothesis tests under the null hypothesis. What does the uniform distribution of p-values indicate?
import matplotlib.pyplot as plt import numpy as np np.random.seed(0) p_values = np.random.uniform(0, 1, 1000) plt.hist(p_values, bins=20, edgecolor='black') plt.title('Distribution of p-values under Null Hypothesis') plt.xlabel('p-value') plt.ylabel('Frequency') plt.show()
Think about what the p-value distribution looks like if the null hypothesis is true for all tests.
When the null hypothesis is true, p-values are uniformly distributed between 0 and 1, meaning any p-value is equally likely.
What error will this code raise when running a one-sample t-test?
from scipy import stats sample = [2, 4, 6, 8] result = stats.ttest_1samp(sample) print(result)
Check the required arguments for ttest_1samp function.
The function ttest_1samp requires two arguments: the sample and the population mean to test against. Omitting the population mean causes a TypeError.