Hypothesis Testing with t-Tests

Master one-sample and two-sample t-tests for comparing means when population variance is unknown

Try these examples:

Hypothesis Testing with tt-Tests

The tt-test compares population means when σ\sigma is unknown and must be estimated from the sample. Pick a test type, enter your data, and watch the decision update live.

Test Type

One-Sample tt-Test

Compares a sample mean to a hypothesized value μ0\mu_0.

Hypotheses:

  • H0 ⁣:μ=μ0=H_0\colon \mu = \mu_0 = 100
  • H1 ⁣:μ≠μ0H_1\colon \mu \neq \mu_0

Sample data:

  • xˉ=\bar{x} = 105
  • s=s = 15
  • n=n = 25

Test Statistic

t=xˉ−μ0s/n=0−00/0=0t = \frac{\bar{x} - \mu_0}{s / \sqrt{n}} = \frac{{\cmv{computed}{mean1}} - {\cmv{computed}{mu0}}}{{\cmv{computed}{sd1}} / \sqrt{{\cmv{computed}{n1}}}} = {\cmv{computed}{tStat}}

df=n−1=df = n - 1 = 24

Statistical Decision

α=\alpha = 0.05 | Direction:

t-Distribution with Test Statistic

-4-2024t-valueReject H0Reject H0t-statistic = 1.7

Two-sided at α=\alpha = 0.05: critical values t∗=±t^* = \pm 2.0639. Reject when ∣t∣>|t| > 2.0639.

Result

t=t = 1.6667, df=df = 24

Fail to reject H0H_0. Insufficient evidence at α=\alpha = 0.05. Try increasing the sample mean with 105 or raising α\alpha with 0.05 to explore what it would take to reject.

Assumptions Check

The one-sample tt-test requires:

  1. Random sampling
  2. Normality (or large nn via CLT -- drag 25 above 30 for safety)
  3. Independent observations

If normality is suspect with small nn, consider a nonparametric alternative (e.g., Wilcoxon signed-rank).

Effect Size (Cohen's dd)

Statistical significance depends on sample size; effect size measures practical importance independently.

d=0d = {\cmv{computed}{cohenD}}

Small (0.2≤∣d∣<0.50.2 \leq |d| < 0.5). A real but modest difference. Increase 15 and watch dd shrink -- more noise obscures the signal.

| Benchmark | ∣d∣|d| | |-----------|-------| | Small | 0.2 | | Medium | 0.5 | | Large | 0.8 |

Try it in Code

# One-sample and two-sample t-tests
from scipy import stats
import math

# One-sample t-test
x_bar, s, n, mu0 = 105, 15, 25, 100
se = s / math.sqrt(n)
t_stat = (x_bar - mu0) / se
p_val = 2 * stats.t.sf(abs(t_stat), df=n - 1)
print(f"One-sample t-test:\n  t = {t_stat:.4f}, df = {n - 1}, p = {p_val:.4f}")

# Two-sample Welch's t-test
x2, s2, n2 = 98, 12, 30
se_w = math.sqrt(s**2 / n + s2**2 / n2)
t_welch = (x_bar - x2) / se_w
print(f"Welch two-sample t:\n  t = {t_welch:.4f}")

What to explore next

You might also like