Lesson 10 of 15

Hypothesis Testing (t-test)

Hypothesis Testing: t-test

A t-test tests whether an observed difference is statistically significant or could be due to random chance.

One-sample t-statistic tests whether a sample mean differs from a hypothesized value μ0\mu_0: t=xˉμ0s/nt = \frac{\bar{x} - \mu_0}{s / \sqrt{n}}

where ss is the sample standard deviation and nn is the sample size. Large t|t| values indicate the sample mean is unlikely to come from a distribution with mean μ0\mu_0.

Two-sample t-statistic (Welch's) tests whether two independent samples have different means: t=xˉ1xˉ2s12n1+s22n2t = \frac{\bar{x}_1 - \bar{x}_2}{\sqrt{\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}}}

Welch's version is preferred because it does not assume equal variances.

Your Task

Implement:

  • t_statistic(sample, mu0) — one-sample t-statistic
  • two_sample_t(xs, ys) — Welch's two-sample t-statistic
Python runtime loading...
Loading...
Click "Run" to execute your code.