Lesson 9 of 18
One-Sample t-Test
Hypothesis Testing
The one-sample t-test checks whether the mean of your data is significantly different from a hypothesized value.
Hypotheses:
- (null): (the mean equals the hypothesized value)
- (alternative):
import math, statistics
data = [2.1, 2.5, 2.3, 2.8, 2.4]
mu_0 = 2.0 # hypothesized mean
n = len(data)
t_stat = (statistics.fmean(data) - mu_0) / (statistics.stdev(data) / math.sqrt(n))
print(round(t_stat, 4)) # 4.0
The t-Statistic
t = rac{ar{x} - mu_0}{s / sqrt{n}}
A large means the sample mean is far from relative to the data's variability.
The p-value
The -value is the probability of observing a -statistic this extreme (or more) if were true.
- → statistically significant (reject at 5% significance level)
- → insufficient evidence to reject
Special Case: Testing Against the Sample Mean
When equals the sample mean exactly, and .
Your Task
Implement ttest_one_sample(data, mu) that prints the -statistic (rounded to 4 decimal places) and whether the result is significant ().
Pyodide loading...
Loading...
Click "Run" to execute your code.