Skip to content

Lesson 56 ยท Practice and Review

Statistics Formula Cheat Sheet

A compact statistics and probability cheat sheet: descriptive formulas, probability rules, distributions, confidence intervals, test choice, regression and Python equivalents.

This page collects the formulas and decisions you will use most, with the Python call that does each job, so you can check your hand calculations. Treat it as a map: for the reasoning behind any line, go back to the lesson on that topic. Bookmark it for exam revision and day-to-day analysis.

Descriptive statistics

Quantity Formula Python
Mean xฬ„ = ฮฃxแตข / n np.mean(x)
Median middle of sorted data np.median(x)
Sample variance sยฒ = ฮฃ(xแตข โˆ’ xฬ„)ยฒ / (n โˆ’ 1) np.var(x, ddof=1)
Sample sd s = โˆšsยฒ np.std(x, ddof=1)
Range / IQR max โˆ’ min / Q3 โˆ’ Q1 np.ptp(x), np.subtract(*np.percentile(x, [75, 25]))
z-score z = (x โˆ’ ฮผ) / ฯƒ stats.zscore(x)
Outlier fences Q1 โˆ’ 1.5ยทIQR, Q3 + 1.5ยทIQR
Covariance ฮฃ(xแตข โˆ’ xฬ„)(yแตข โˆ’ ศณ) / (n โˆ’ 1) np.cov(x, y)
Correlation r = cov(x, y) / (sโ‚“ s_y) np.corrcoef(x, y)

Rules of thumb: for skewed data prefer median and IQR; for symmetric data, mean and sd. The empirical rule for normal data: about 68%, 95% and 99.7% lie within 1, 2 and 3 standard deviations of the mean.

Probability rules

Rule Formula
Complement P(Aแถœ) = 1 โˆ’ P(A)
Addition P(A โˆช B) = P(A) + P(B) โˆ’ P(A โˆฉ B)
Conditional P(AโˆฃB) = P(A โˆฉ B) / P(B)
Multiplication P(A โˆฉ B) = P(AโˆฃB)ยทP(B)
Independence P(A โˆฉ B) = P(A)ยทP(B)
Total probability P(B) = ฮฃ P(BโˆฃAแตข)ยทP(Aแตข)
Bayes P(AโˆฃB) = P(BโˆฃA)ยทP(A) / P(B)
Permutations / combinations n!/(nโˆ’k)! and n!/(k!(nโˆ’k)!)
Expectation / variance E[X] = ฮฃ xยทp(x), Var(X) = E[Xยฒ] โˆ’ (E[X])ยฒ
Linear transform E[aX + b] = aE[X] + b, Var(aX + b) = aยฒVar(X)

Common distributions

Distribution Use Mean Variance SciPy
Bernoulli(p) one yes/no trial p p(1โˆ’p) stats.bernoulli(p)
Binomial(n, p) successes in n trials np np(1โˆ’p) stats.binom(n, p)
Poisson(ฮป) events per interval ฮป ฮป stats.poisson(lam)
Geometric(p) trials until first success 1/p (1โˆ’p)/pยฒ stats.geom(p)
Uniform(a, b) equally likely on an interval (a+b)/2 (bโˆ’a)ยฒ/12 stats.uniform(a, b-a)
Exponential(ฮป) waiting time 1/ฮป 1/ฮปยฒ stats.expon(scale=1/lam)
Normal(ฮผ, ฯƒ) bell curve, sums and averages ฮผ ฯƒยฒ stats.norm(mu, sigma)

Central limit theorem: for large n the sample mean is approximately N(ฮผ, ฯƒยฒ/n) whatever the shape of the population (with finite variance). The standard error of the mean is ฯƒ/โˆšn.

Estimation and tests

Task Formula
CI for a mean (ฯƒ unknown) xฬ„ ยฑ t*ยทs/โˆšn, df = n โˆ’ 1
CI for a proportion pฬ‚ ยฑ z*ยทโˆš(pฬ‚(1โˆ’pฬ‚)/n)
One-sample t t = (xฬ„ โˆ’ ฮผโ‚€)/(s/โˆšn)
Two-sample (Welch) t t = (xฬ„โ‚ โˆ’ xฬ„โ‚‚)/โˆš(sโ‚ยฒ/nโ‚ + sโ‚‚ยฒ/nโ‚‚)
Paired t one-sample t on the differences
One proportion z z = (pฬ‚ โˆ’ pโ‚€)/โˆš(pโ‚€(1โˆ’pโ‚€)/n)
Two proportions z z = (pฬ‚โ‚ โˆ’ pฬ‚โ‚‚)/โˆš(pฬ‚(1โˆ’pฬ‚)(1/nโ‚ + 1/nโ‚‚))
Chi-square ฯ‡ยฒ = ฮฃ (O โˆ’ E)ยฒ/E
ANOVA F = MS_between / MS_within
Sample size, mean n = (zยทฯƒ/E)ยฒ for margin of error E
Sample size, proportion n = zยฒยทp(1โˆ’p)/Eยฒ
Cohen's d (xฬ„โ‚ โˆ’ xฬ„โ‚‚)/s_pooled

Common critical values: z* = 1.645 (90%), 1.96 (95%), 2.576 (99%).

flowchart TD
  A["What is your outcome?"] --> B{"Numeric"}
  A --> C{"Categories"}
  B --> D{"How many groups?"}
  D -->|"1 vs a value"| E["One-sample t"]
  D -->|"2 independent"| F["Welch t / Mann-Whitney"]
  D -->|"2 paired"| G["Paired t / Wilcoxon"]
  D -->|"3 or more"| H["ANOVA / Kruskal-Wallis"]
  B -->|"two numeric variables"| I["Correlation / regression"]
  C -->|"1 proportion"| J["z-test / binomial test"]
  C -->|"2 proportions"| K["Two-proportion z / chi-square"]
  C -->|"2 categorical variables"| L["Chi-square independence"]

Regression

Item Formula
Line ลท = bโ‚€ + bโ‚x
Slope / intercept bโ‚ = rยทs_y/sโ‚“, bโ‚€ = ศณ โˆ’ bโ‚xฬ„
Rยฒ 1 โˆ’ SSE/SST
Residual standard error โˆš(SSE/(n โˆ’ k โˆ’ 1))
Slope t-test t = bโ‚/SE(bโ‚), df = n โˆ’ k โˆ’ 1
Adjusted Rยฒ 1 โˆ’ (1 โˆ’ Rยฒ)(n โˆ’ 1)/(n โˆ’ k โˆ’ 1)
Logistic model ln(p/(1โˆ’p)) = ฮฒโ‚€ + ฮฒโ‚x, odds ratio e^ฮฒ
VIF 1/(1 โˆ’ Rยฒโฑผ)

Bayesian and resampling

  • Posterior โˆ likelihood ร— prior.
  • Beta(ฮฑ, ฮฒ) prior with k successes in n trials gives Beta(ฮฑ + k, ฮฒ + n โˆ’ k).
  • Bootstrap: resample with replacement, recompute the statistic, take percentiles.
  • Permutation test: shuffle labels, compute the statistic, p = share at least as extreme.
  • Multiple tests: Bonferroni ฮฑ/m; Holm step-down; Benjamini-Hochberg for FDR.

A runnable toolbox

The code below wraps several of the formulas so that you can verify answers quickly.

Python A small statistics toolbox

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Distribution lookups in one place

SciPy distributions all share the same methods: pdf/pmf (density or mass), cdf (probability up to x), sf (the upper tail, 1 โˆ’ cdf), ppf (the inverse of the cdf, giving quantiles) and rvs (random draws). Learn these five and you can answer almost every table-lookup question.

Python The five SciPy methods

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which formula gives the standard error of the sample mean?

    SE = s/sqrt(n): it shrinks as the sample grows.
  2. 2. You want P(X > 130) for a normal variable in SciPy. Which method is the most direct?

    sf is the survival function, 1 - cdf, the upper-tail probability.
  3. 3. A comparison of the means of 4 independent groups of numeric data with roughly normal errors calls for:

    ANOVA compares means of three or more independent groups; Kruskal-Wallis is the rank-based alternative.
  4. 4. Using the sample-size formula for a mean, what happens if you want half the margin of error?

    n is proportional to 1/E squared, so halving E multiplies n by four.

Summary

  • Descriptive formulas, probability rules, distributions and test statistics fit on a page; the hard part is choosing the right one.
  • Choose the test from the outcome type, the number of groups and whether groups are paired.
  • SciPy distributions share pdf/pmf, cdf, sf, ppf, rvs.
  • Always accompany a test with an interval and an effect size.

Next: Common Statistical Mistakes