177. One-Sample t-Test
177.0.1. One-sample
Tests if the mean of a single sample differs from a known or hypothesized population mean.
- : sample mean
- : hypothesized population mean
- : sample standard deviation
- : sample size
Example
Step 1: State Hypotheses
Step 2: Summarize Data
- Sample values:
- Sample size:
Step 3: Calculate Sample Mean ()
Step 4: Calculate Sample Standard Deviation:
- Find the deviations from the mean and square them
- Sum of squared deviations
- Calculate variance of sample
- Calculate Sample Standard Deviation
Step 5: Calculate the Test Statistic
Step 6: Determine the Degrees of Freedom
Step 7: Find Critical t-value
- For a two-tailed test at a significance level () of 0.05 and 2 degrees of freedom ()
Step 8: Compare the t-Value to the Critical t-Value
- If the absolute value of the test statistic is greater than the critical t-value, reject the null hypothesis.
- If the absolute value of the test statistic is less than the critical t-value, fail to reject the null hypothesis.
Step 8: Find the p-Value
t_test_one_sample.py
from scipy import stats
rvs = stats.uniform.rvs(size=50)
stats.ttest_1samp(rvs, popmean=0.5)