Menu

Z-Tests and T-Tests

Z-Tests and T-Tests

Both tests compare a sample mean with a hypothesized population mean. The only difference is whether the population standard deviation is known.

z = (x̄ − μ₀) / (σ / √n)

t = (x̄ − μ₀) / (s / √n)

  • x̄: the sample mean.
  • μ₀: the population mean claimed by H₀.
  • σ: the known population standard deviation, used in the z-test.
  • s: the sample standard deviation, used in the t-test when σ is unknown.
  • n: the sample size.
  • Denominator: the standard error, so the result is the distance between x̄ and μ₀ measured in standard errors.

The t statistic follows a t-distribution with n − 1 degrees of freedom. For small samples, this distribution has heavier tails than the normal curve, making the test more conservative. As n grows, it becomes almost identical to the normal curve.

Test

Use when

One-sample z-testσ is known, or n is large
One-sample t-testσ is unknown, and n is small
Two-sample t-testComparing the means of two separate groups
Paired t-testComparing two measurements on the same subjects

Example: A battery is advertised to last 50 hours. A sample of 16 batteries has a mean life of 48 hours and s = 8 hours. Test H₀: μ = 50 against H₁: μ ≠ 50 at α = 0.05.

  1. SE = 8 / √16 = 2
  2. t = (48 − 50) / 2 = −1
  3. Degrees of freedom = 16 − 1 = 15, and the critical values for a two-tailed test at 0.05 are ±2.131.
  4. Since −1 lies between −2.131 and 2.131, we fail to reject H₀.
from scipy import stats

t = -1
p = 2 * stats.t.sf(abs(t), df=15)
print(p)

Code Explanation:

  • t holds the test statistic calculated above.
  • stats.t.sf(abs(t), df=15) gives the area in one tail beyond |t| for a t-distribution with 15 degrees of freedom.
  • Multiplying by 2 adds the other tail, because the test is two-tailed.
  • The result is about 0.33, well above 0.05, which agrees with the decision to fail to reject.

Probability and Statistics for Data Science

AP

Abhishek Pati



Learn via Video Course

Probability and Statistics for Data Science Logo

Probability and Statistics for Data Science

4 hrs



Get in Touch For Details