Hypothesis Tests, p-values, Errors & Power

Statistics
Hypothesis Testing
Inference
Understand hypothesis testing as a decision framework, visualize p-values, and simulate Type I error, Type II error and power.
Author

MLStation

Published

October 1, 2026

Hypothesis testing is often taught as a ritual:

calculate p → compare with 0.05 → declare significance

That hides the real structure.

A test asks:

If a specified null model were true, how surprising would data like these be?

TipWhat you will learn
  • Null and alternative hypotheses
  • Test statistics and p-values
  • Type I and Type II errors
  • Statistical power
  • Why statistical significance is not practical importance

The p-value

A p-value is the probability, under the null model, of observing a test statistic at least as incompatible with the null as the one observed.

It is not P(H_0\mid\text{data}).

Interactive: move the observed z-statistic

Errors are defined across repeated decisions

Reality Do not reject H_0 Reject H_0
H_0 true Correct Type I error (\alpha)
H_1 true Type II error (\beta) Correct; power =1-\beta

Animation: power rises with effect size and sample size

Show the code
import numpy as np, pandas as pd
import plotly.express as px
from scipy.stats import norm

rows=[]
alpha=.05
crit=norm.ppf(1-alpha/2)
for n in [20,50,100,200,500]:
    for d in np.linspace(0,0.6,61):
        mu=d*np.sqrt(n)
        power=norm.sf(crit-mu)+norm.cdf(-crit-mu)
        rows.append({"n":n,"effect":d,"power":power})
df=pd.DataFrame(rows)
fig=px.line(df,x="effect",y="power",animation_frame="n",range_y=[0,1],
            labels={"effect":"Standardized effect size","power":"Power"})
fig.add_hline(y=.8,line_dash="dash")
fig.update_layout(height=380)
fig.show()

DS/ML Bridge

Hypothesis testing appears in:

  • feature experiments,
  • model comparison,
  • uplift measurement,
  • regression coefficient tests,
  • monitoring shifts,
  • controlled online experiments.

But with huge datasets, tiny effects can become statistically significant. Always pair inference with an effect size and domain relevance.

Warning“Not significant” does not mean “no effect”

It can mean the study had too little information to distinguish the effect from noise.

Summary

  • A p-value is computed assuming the null model.
  • Type I error is a false positive; Type II error is a false negative.
  • Power is the probability of detecting an effect under a specified alternative.
  • Larger samples detect smaller effects.
  • Statistical significance and practical importance are different questions.

Next: A/B Testing — Statistics as a Product Decision System

Back to top