179. One-Sample t-Test

179.0.1. One-sample

Tests if the mean of a single sample differs from a known or hypothesized population mean.

𝑡=𝑥̄𝜇0𝑠𝑛
Example
[78,82,89]

Step 1: State Hypotheses

𝐻0:𝜇=85cm𝐻1:𝜇85cm

Step 2: Summarize Data

  • Sample values:
𝑥1=78,𝑥2=82,𝑥3=89
  • Sample size:
𝑛=3

Step 3: Calculate Sample Mean (𝑥̄)

𝑥̄=𝑥1+𝑥2+𝑥3𝑛=78+82+893=83

Step 4: Calculate Sample Standard Deviation:

𝑠=𝑖=1𝑛(𝑥𝑖𝑥̄)2𝑛1
  • Find the deviations from the mean and square them
(𝑥1𝑥̄)2=(7883)2=(5)2=25(𝑥2𝑥̄)2=(8283)2=(1)2=1(𝑥3𝑥̄)2=(8983)2=(6)2=36
  • Sum of squared deviations
SSD=25+1+36
  • Calculate variance of sample
𝑠2=SSD𝑛1=6231=622=31
  • Calculate Sample Standard Deviation
𝑠=𝑠2=32=5.57

Step 5: Calculate the Test Statistic

𝑡=𝑥̄𝜇0𝑠𝑛=83855.573=33.22=0.62

Step 6: Determine the Degrees of Freedom

𝑑𝑓=𝑛1=151=14

Step 7: Find Critical t-value

  • For a two-tailed test at a significance level (𝛼) of 0.05 and 2 degrees of freedom (𝑑𝑓)
4.303

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

𝑡=4.303and𝑑𝑓=3p-value=0.58
t_test_one_sample.py
from scipy import stats
rvs = stats.uniform.rvs(size=50)
stats.ttest_1samp(rvs, popmean=0.5)