Skip to content

Probability & Statistics

Quantifying uncertainty — from Bayes’ rule to the Central Limit Theorem, confidence intervals and regression

1. Why uncertainty needs mathematics

Measurements are noisy, components fail at random times, users behave unpredictably, and even a perfectly deterministic simulation is fed uncertain inputs. Engineering without a theory of uncertainty means guessing safety factors. Two subjects supply that theory, and they point in opposite directions:

  • Probability goes from model to data: if this coin is fair, how likely are 7 heads in 10 tosses?
  • Statistics goes from data to model: given 7 heads in 10 tosses, is the coin fair?

2. Probability & Bayes’ rule

A probability assigns a number between 0 and 1 to each event so that P(everything) = 1 and probabilities of mutually exclusive events add. Learning that event B happened changes the odds of A. The conditional probability and its consequences:

Conditional probability, total probability, independence

Rearranging the first formula both ways gives Bayes’ rule, which turns “probability of the evidence given the hypothesis” into “probability of the hypothesis given the evidence”:

Bayes’ rule

Worked example 1: the medical test

Prevalence P(D) = 0.01, sensitivity P(+ | D) = 0.90, false-positive rate P(+ | no D) = 0.09. By total probability P(+) = 0.90 · 0.01 + 0.09 · 0.99 = 0.0981, and then

The same answer by counting 1000 people: 9 true positives and 89 false positives give 9/98. A test that is “90% accurate” can still be wrong about 9 out of 10 positives.

Try it

Roll two fair dice. Is “the first die shows 3” independent of “the sum is 7”? Of “the sum is 8”?

3. Random variables: mean & variance

A random variable X turns outcomes into numbers. If it takes separate values it has a probability mass function p(x); if it is continuous it has a density f(x) whose area gives probabilities. Two numbers summarise it: the mean (centre) and the variance (spread):

Expectation and variance

Two rules do most of the work. Expectation is always linear: E[aX + bY] = aE[X] + bE[Y]. Variance scales with the square and adds for independent variables: Var(aX + b) = a²Var(X), and Var(X + Y) = Var(X) + Var(Y). So the standard deviation of a sum of n independent copies grows only like √n.

Worked example 2: a fair die

E[X] = (1 + 2 + … + 6)/6 = 3.5 and E[X²] = (1 + 4 + 9 + 16 + 25 + 36)/6 = 91/6, so

4. The distributions engineers meet

A handful of distributions cover most situations. Pick by asking what is being counted or measured?

DistributionModelsMeanVariance
Binomial(n, p)successes in n independent trialsnpnp(1 − p)
Poisson(λ)events per unit time/space (rare, independent)λλ
Uniform(a, b)“no preference” on an interval(a + b)/2(b − a)²/12
Exponential(λ)waiting time between Poisson events1/λ1/λ²
Normal(μ, σ²)sums of many small effects; measurement noiseμσ²
Binomial and Poisson probabilities
The normal density

The strange constant 1/√(2π) is exactly what makes the total area 1; it comes from the Gaussian integral ∫e−x²dx = √π computed in polar coordinates in the Multivariable Calculus chapter. The useful rule of thumb: about 68%, 95% and 99.7% of a normal lies within 1, 2 and 3 standard deviations of the mean.

Worked example 3: counting defects (binomial)

A batch of 10 parts, each defective independently with p = 0.1. The chance of at least 2 defects is

The expected number of defects is np = 1, with variance np(1 − p) = 0.9.

Worked example 4: arrivals and waiting times (Poisson and exponential)

A server receives on average λ = 3 requests per second. The probability of no request in a given second is e−3 = 0.0498. The waiting time T until the next request is exponential with mean 1/3 s, and P(T > 1 s) = e−3 is the very same number: “no arrival for a second” has one meaning in two languages.

The exponential is memoryless: having already waited 5 s changes nothing, P(T > 6 | T > 5) = e−3 again. This is why a constant-failure-rate component has no wear-out.

Worked example 5: noise on a sensor (normal)

Sensor error is N(0, 2²) mV. The chance that the error is within ±3 mV is P(|Z| < 1.5) = 2Φ(1.5) − 1 = 2(0.9332) − 1 = 0.866. A reading is “beyond spec” (|error| > 4 mV, i.e. |z| > 2) about 4.6% of the time.

5. The law of large numbers & the Central Limit Theorem

Two theorems explain why statistics works. The law of large numbers says the sample mean X̄ homes in on the true mean μ as n grows. The Central Limit Theorem says how it homes in: the error is eventually a bell curve whose width shrinks like 1/√n, no matter what the original distribution looked like:

Central Limit Theorem
Try it

Sum 100 fair dice. Use the CLT to estimate P(sum > 380). (Each die has mean 3.5 and variance 35/12.)

6. Estimation & confidence intervals

We rarely know μ. We estimate it by x̄ and attach an error bar. The CLT says x̄ is within about two standard errors σ/√n of μ about 95% of the time, which can be turned around into an interval for μ:

Confidence interval for a mean

Worked example 6: an interval and a sample size

n = 36 measurements with known σ = 6 have mean x̄ = 50.2. The standard error is 6/√36 = 1, so the 95% interval is

To shrink the margin of error to ±0.5, solve 1.96·6/√n = 0.5: n = (1.96·6/0.5)² ≈ 553.2, so n = 554. Halving the margin costs four times the data — the price of the √n.

If σ is unknown and the sample is small (say n = 9, x̄ = 10, s = 3) use the t distribution: t8,0.025 = 2.306, giving 10 ± 2.306 · 1 = (7.69, 12.31) — wider than the normal-based interval, to pay for having to estimate σ.

Try it

A 95% interval for a mean is computed as (48.2, 52.2). Is it correct to say “there is a 95% probability that μ is in (48.2, 52.2)”?

7. Hypothesis testing & regression

Hypothesis testing

To test a claim, assume the boring explanation H₀ (“nothing is going on”) and ask how surprising the data would be. The p-value is the probability, if H₀ is true, of a result at least as extreme as the one observed. A small p-value (below a preset level α, often 0.05) is evidence against H₀. For a mean with known σ:

z-test

Worked example 7: is the mean still 100?

H₀: μ = 100, with σ = 10 and n = 25 (so SE = 2). The sample gives x̄ = 104:

Since 0.0455 < 0.05 we reject H₀ at the 5% level — but only just; at x̄ = 103 (z = 1.5, p = 0.134) we would not. Remember the two kinds of mistake: rejecting a true H₀ (type I, probability α) and failing to reject a false one (type II). A p-value is not the probability that H₀ is true, and a tiny p for a tiny effect can still be practically irrelevant.

Regression

Regression models a response as a line plus noise, y = β₀ + β₁x + ε with ε ~ N(0, σ²). Maximising the likelihood under Gaussian noise is exactly minimising the sum of squared errors — the least-squares problem of the Subspaces & Least Squares chapter, whose normal equations give closed forms:

Simple linear regression

Worked example 8: fit a line to five measurements

Data: x = 1, 2, 3, 4, 5 and y = 2.1, 3.9, 6.2, 7.8, 10.1. Then x̄ = 3, ȳ = 6.02, Sxx = 10, Sxy = 19.9, so

The residuals are 0.06, −0.13, 0.18, −0.21, 0.10, with residual standard deviation s = 0.189. The standard error of the slope is s/√Sxx = 0.060, so a 95% interval for β₁ (t3 = 3.182) is 1.99 ± 0.19 = (1.80, 2.18). The data are consistent with a true slope of 2.

8. Practice & where it shows up

Try it: memorylessness

Requests arrive as a Poisson process with rate 3 per second. You have already waited 5 seconds with no request. What is the chance you wait at least another second?

Try it: which error is worse?

A smoke detector tests H₀: “no fire”. What are type I and type II errors here, and why can’t you drive both to zero?

Reliability & maintenance

Component lifetimes are modelled with exponential and Weibull distributions; the memoryless property of the exponential is why a constant failure rate has no “wear-out”.

Signals & communications

Receiver noise is Gaussian. Bit-error rates come from normal tail probabilities, and detection thresholds trade false alarms (type I) against misses (type II).

Quality control

Control charts flag a process when x̄ leaves μ ± 3 standard errors — a hypothesis test run continuously. Six-sigma targets are statements about normal tails.

Machine learning & A/B tests

Naive Bayes is Bayes’ rule with an independence assumption; least squares and cross-entropy are maximum likelihood; an A/B test is a two-sample hypothesis test.

9. Resources

This chapter follows MIT 18.05 (Bayes’ rule, distributions, the CLT, confidence intervals, tests, regression) and the engineering flavour of MIT 6.041 and Stanford’s CME 106. Seeing Theory is a lovely interactive companion.

Site soundtrack