IE 3301 Worked Examples

Teaching · IE 3301 Engineering Probability · Worked examples

Each section has one idea, a short explanation and something to try. The worked example is folded underneath, and it shows its work the same way every time:

  1. Write out the equation.
  2. List the variables: the terms in that equation.
  3. Fill in the equation with the numbers.
  4. Simplify, and box the answer.
  1. Distributions: mean, variance and area
  2. The central limit theorem
  3. Covariance and correlation
  4. Hypothesis tests, errors and power
  5. Linear regression
  6. A designed experiment

1. Distributions: mean, variance and area

  • Calculate the mean, variance and standard deviation of a distribution
  • Find a probability as a sum (discrete) or an area (continuous)
  • Recognize the common distributions and what they model

A discrete variable counts and has a pmf (bars that sum to 1); a continuous one measures and has a pdf (a curve with area 1), where probability is area. The mean is the balance point, μ=∑x p(x)\mu = \sum x\,p(x) or ∫xf(x) dx\int x f(x)\,dx, and the variance is E[X2]−μ2E[X^2] - \mu^2.

Try it. Pick a distribution and move its parameters. Shade a probability, or draw random samples and watch their average settle on the mean.

Worked example: defective parts in a box (discrete)

XX = 0, 1, 2 or 3 defective parts, with probabilities 0.50, 0.30, 0.15 and 0.05.

  1. Equations: μ=∑x p(x)\mu = \sum x\,p(x), σ2=∑x2p(x)−μ2\sigma^2 = \sum x^2 p(x) - \mu^2.
  2. Variables: x=0,1,2,3x = 0, 1, 2, 3; p(x)=0.50,0.30,0.15,0.05p(x) = 0.50, 0.30, 0.15, 0.05 (they sum to 1).
  3. Fill in: μ=0+0.30+0.30+0.15\mu = 0 + 0.30 + 0.30 + 0.15; σ2=(0.30+0.60+0.45)−0.752\sigma^2 = (0.30 + 0.60 + 0.45) - 0.75^2.
  4. Answer: μ=0.75, σ2=0.7875, σ≈0.887\mu = 0.75,\ \sigma^2 = 0.7875,\ \sigma \approx 0.887
01230.00.20.40.6defective parts in a box, xP(X = x)0.500.300.150.05mean 0.75±1 SD
The mean is the balance point; the band is one standard deviation either side.
Worked examples: probability as area (continuous)

A. f(x)=3x2f(x) = 3x^2 on 0 to 1. Equation P(X≤a)=∫0af(x) dxP(X \le a) = \int_0^a f(x)\,dx; fill in ∫00.53x2 dx=0.53\int_0^{0.5} 3x^2\,dx = 0.5^3; answer 0.125. Its mean is ∫013x3 dx=0.75\int_0^1 3x^3\,dx = 0.75.

B. Pump life is exponential with mean 200 h. Equation P(T>t)=e−t/meanP(T > t) = e^{-t/\text{mean}}; fill in e−300/200e^{-300/200}; answer P(T>300)≈0.223P(T > 300) \approx 0.223

00.250.50.7510123xmean 0.75P(X ≤ 0.5) = 0.125f(x) = 3x²02004006008000.00000.00250.0050hours to failure, tmean 200P(T > 300) = 0.223exponential, mean 200 h
The shaded areas are the answers.
The common distributions at a glance
DistributionModelspmf or pdfMeanVariance
Binomial(n,pn, p)successes in nn trials(nx)px(1−p)n−x\binom{n}{x}p^x(1-p)^{n-x}npnpnp(1−p)np(1-p)
Geometric(pp)trials until the first success(1−p)x−1p(1-p)^{x-1}p1/p1/p(1−p)/p2(1-p)/p^2
Poisson(λ\lambda)events in an intervale−λλx/x!e^{-\lambda}\lambda^x/x!λ\lambdaλ\lambda
Uniform(a,ba, b)equally likely in a range1/(b−a)1/(b-a)(a+b)/2(a+b)/2(b−a)2/12(b-a)^2/12
Exponential(λ\lambda)time between random eventsλe−λx\lambda e^{-\lambda x}1/λ1/\lambda1/λ21/\lambda^2
Normal(μ,σ2\mu, \sigma^2)sums and averages1σ2πe−(x−μ)2/2σ2\frac{1}{\sigma\sqrt{2\pi}}e^{-(x-\mu)^2/2\sigma^2}μ\muσ2\sigma^2

2. The central limit theorem

  • State the central limit theorem
  • Find the standard error of a sample mean, σ/√n
  • Explain when to use t instead of z

Average enough independent observations and the average is approximately normal, whatever the population looks like, with mean μ\mu and standard error σ/n\sigma/\sqrt n. That is why the normal is everywhere, and why z=(xˉ−μ)/(σ/n)z = (\bar x - \mu)/(\sigma/\sqrt n) works. When σ\sigma is estimated from the sample, use t instead: it has heavier tails, and approaches the normal as nn grows (try it in the explorer above).

Try it. Pick a population that is nothing like a bell curve, then raise the sample size. The averages turn normal anyway.

Worked example: bolts longer than 50.8 mm

Lengths are normal, mean 50 mm, SD 0.4 mm.

  1. Equation: z=(x−μ)/σz = (x - \mu)/\sigma.
  2. Variables: x=50.8, μ=50, σ=0.4x = 50.8,\ \mu = 50,\ \sigma = 0.4.
  3. Fill in: z=0.8/0.4=2z = 0.8/0.4 = 2; look up P(Z>2)P(Z > 2).
  4. Answer: about 2.3% of bolts
-4-3-2-1012340.00.10.20.30.4z or tstandard normalt, 9 degrees of freedomt, 2 degrees of freedom: heavier tails
The t distribution's heavier tails: its 95% critical value is 2.26 at 9 degrees of freedom, against 1.96 for z.

3. Covariance and correlation

  • Find marginal distributions from a joint table
  • Calculate covariance and correlation
  • Check whether two variables are independent

A joint table gives the probability of each pair of values. Add up a row or column for one variable on its own (the marginal). Cov⁡(X,Y)=E[XY]−E[X]E[Y]\operatorname{Cov}(X,Y) = E[XY] - E[X]E[Y] is positive when the two tend to be high together; correlation ρ=Cov⁡/(σXσY)\rho = \operatorname{Cov}/(\sigma_X\sigma_Y) scales it to between −1 and 1. Independent means every cell equals its row total times its column total.

Try it. Move probability around the table and watch the covariance and correlation respond. Can you make them independent?

Y = 0Y = 1Y = 2total
X = 0 no overtime
X = 1 overtime
total1
Worked example: overtime and defects

The explorer starts on this table: X=1X = 1 for an overtime shift, YY = defects found.

  1. Equations: Cov⁡=E[XY]−E[X]E[Y]\operatorname{Cov} = E[XY] - E[X]E[Y], ρ=Cov⁡/(σXσY)\rho = \operatorname{Cov}/(\sigma_X\sigma_Y).
  2. Variables: E[X]=0.5, σX2=0.25E[X] = 0.5,\ \sigma_X^2 = 0.25; E[Y]=0.85, σY2=1.35−0.852=0.6275E[Y] = 0.85,\ \sigma_Y^2 = 1.35 - 0.85^2 = 0.6275; E[XY]=(1)(1)(0.20)+(1)(2)(0.20)=0.60E[XY] = (1)(1)(0.20) + (1)(2)(0.20) = 0.60.
  3. Fill in: Cov⁡=0.60−(0.5)(0.85)\operatorname{Cov} = 0.60 - (0.5)(0.85); ρ=0.175/0.25×0.6275\rho = 0.175/\sqrt{0.25 \times 0.6275}.
  4. Answer: Cov⁡=0.175, ρ≈0.44\operatorname{Cov} = 0.175,\ \rho \approx 0.44. Not independent: 0.30≠0.5×0.40.30 \ne 0.5 \times 0.4.

Correlation is not causation: overtime might cause defects, or a rush order might cause both. A designed experiment (section 6) is how to tell.

4. Hypothesis tests, errors and power

  • State the hypotheses and find the critical value
  • Decide with the test statistic or the confidence interval
  • Explain Type I and Type II errors, the p-value and power

The critical values are the bounds of the confidence interval; the rejection region is everything outside. Reject H0H_0 if the test statistic falls outside them, or, the same thing, if the confidence interval misses μ0\mu_0. For a two-sided test, put α/2\alpha/2 in each tail.

H₀ is trueH₀ is false
Reject H₀Type I error (probability α)correct: power, 1 − β
Fail to reject H₀correctType II error (probability β)

Try it. Move the true mean away from 50 and watch the power grow. Then see what a bigger sample or a looser α does.

Worked example: is the bolt machine off target?

Ten bolts (mm): 50.3, 49.8, 50.6, 50.9, 50.2, 50.7, 49.9, 50.5, 50.8, 50.4. Target 50 mm, α = 0.05.

  1. Hypotheses: H0:μ=50H_0: \mu = 50, H1:μ≠50H_1: \mu \ne 50.
  2. Equation: t=(xˉ−μ0)/(s/n)t = (\bar x - \mu_0)/(s/\sqrt n) (σ unknown, so t).
  3. Variables: xˉ=50.41, s=0.3665, n=10\bar x = 50.41,\ s = 0.3665,\ n = 10; critical value t0.025, 9=2.262t_{0.025,\,9} = 2.262.
  4. Fill in: t=0.41/(0.3665/10)=0.41/0.1159t = 0.41/(0.3665/\sqrt{10}) = 0.41/0.1159.
  5. Answer: t=3.54>2.262t = 3.54 > 2.262: reject H₀ (p ≈ 0.006). Same by the interval: 50.41±2.262(0.1159)=(50.15,50.67)50.41 \pm 2.262(0.1159) = (50.15, 50.67) misses 50.
-4−2.26202.26240.00.20.4t statistic (9 degrees of freedom)reject H₀: 2.5% in each tailfail to rejectobserved t = 3.54
The rejection region holds 5% of the t distribution; the observed t lands inside it.

5. Linear regression

  • Fit a least-squares line
  • Interpret the slope and R²
  • Check the residuals
  • Read the confidence band for the mean and the prediction band for one new point

Least squares picks the line that makes the squared vertical distances to the points (the residuals) as small as possible: b1=Sxy/Sxxb_1 = S_{xy}/S_{xx}, b0=yˉ−b1xˉb_0 = \bar y - b_1\bar x. R2R^2 is the share of the variation the line explains.

Try it. Click the chart to add points. Then try to beat least squares with your own slope.

Worked example: reactor temperature and yield
  1. Equations: b1=Sxy/Sxxb_1 = S_{xy}/S_{xx}, b0=yˉ−b1xˉb_0 = \bar y - b_1\bar x, R2=1−SSE/SSTR^2 = 1 - \text{SSE}/\text{SST}.
  2. Variables: xˉ=185, yˉ=69.61, Sxx=4200, Sxy=873.5\bar x = 185,\ \bar y = 69.61,\ S_{xx} = 4200,\ S_{xy} = 873.5.
  3. Fill in: b1=873.5/4200b_1 = 873.5/4200; b0=69.61−0.208(185)b_0 = 69.61 - 0.208(185).
  4. Answer: y^=31.14+0.208x, R2=0.987\hat y = 31.14 + 0.208x,\ R^2 = 0.987. The slope test gives t≈21>2.447t \approx 21 > 2.447: temperature matters.
  5. Error bands at 185 °C (s=SSE/(n−2), t0.025,6=2.447s = \sqrt{\text{SSE}/(n-2)},\ t_{0.025,6} = 2.447): the mean yield is y^±t s1/n+(x−xˉ)2/Sxx\hat y \pm t\,s\sqrt{1/n + (x-\bar x)^2/S_{xx}} = 69.06 to 70.17; one new run is y^±t s1+1/n+(x−xˉ)2/Sxx\hat y \pm t\,s\sqrt{1 + 1/n + (x-\bar x)^2/S_{xx}} = 67.94 to 71.28. The extra 1 under the root is the new run's own scatter.
1501701902106065707580temperature (°C)yield (%)ŷ = 31.14 + 0.208 x, R² = 0.987residuals (orange) are whatleast squares makes small
The line and its residuals; use it only inside the data, 150 to 220 °C.

6. A designed experiment

  • Lay out a 2×2 factorial design
  • Calculate main effects and the interaction
  • Read the same results as a regression, and say why each coefficient is half its effect
  • Use replicates to estimate the noise and test each effect
  • Add a third level to see whether a factor's effect bends

Regression on data you happened to collect shows association; a designed experiment sets the factors, so it can show cause. Run every combination of two factors at two levels (coded −1 and +1), and lay the runs out as a table of signs before collecting anything: that table is the data-collection plan, and every run feeds every estimate. An effect is the average at + minus the average at −, and the interaction is the same for the product column. One run per cell gives the effects but no way to test them; replicates (repeat runs of each cell) measure the noise. A third level of a factor shows whether its effect is a straight line or bends.

Try it. Set each cell's average, then add replicates. With one run per cell, can any effect be tested? With two?

Design Replicates per cell
Worked example: temperature and time
  1. Equation: effect = (average where the column is +) − (average where it is −).
  2. Variables: yields 60, 72, 64, 84 at (A, B) = (−, −), (+, −), (−, +), (+, +).
  3. Fill in: A: (72+84)/2−(60+64)/2(72+84)/2 - (60+64)/2; B: (64+84)/2−(60+72)/2(64+84)/2 - (60+72)/2; AB: (60+84)/2−(72+64)/2(60+84)/2 - (72+64)/2.
  4. Answer: A = 16, B = 8, AB = 4; as a regression, y^=70+8x1+4x2+2x1x2\hat y = 70 + 8x_1 + 4x_2 + 2x_1x_2.
  5. Why 8 and not 16: the effect is the rise from x1=−1x_1 = -1 to x1=+1x_1 = +1, a run of 2, so the slope is 16/2=816/2 = 8. It is section 5's b1=Sxy/Sxxb_1 = S_{xy}/S_{xx} too: coded x1x_1 has mean 0, so Sxy=−60+72−64+84=32S_{xy} = -60 + 72 - 64 + 84 = 32, Sxx=4S_{xx} = 4, and 32/4=832/4 = 8.
−1+160708090temperature (coded: −1 = 150 °C, +1 = 200 °C)average yield (%)60726484time long (+1)time short (−1)
Parallel lines would mean no interaction; these spread apart.

With one run per cell, the four runs are used up by four estimates (the mean, A, B and AB), leaving no degrees of freedom for error. Is AB = 4 real or noise? This design cannot say.

Worked example: the same experiment, replicated
  1. Data: two runs per cell, (58, 62), (70, 74), (63, 65), (83, 85); N = 8. The cell averages are still 60, 72, 64, 84, so the effects are still A = 16, B = 8, AB = 4.
  2. Equations: pooled s2s^2 = the average of the four cells' variances, with 4(n−1)4(n-1) df; each effect is an average of N/2 runs minus another, so SE=2s/NSE = 2s/\sqrt{N}, and t=effect/SEt = \text{effect}/SE.
  3. Fill in: cell variances 8, 8, 2, 2, so s2=20/4=5s^2 = 20/4 = 5, s=2.236s = 2.236, 4 df; SE=2(2.236)/8=1.581SE = 2(2.236)/\sqrt 8 = 1.581; t = 10.12, 5.06 and 2.53, against t0.025,4=2.776t_{0.025,4} = 2.776.
  4. Answer: A (p < 0.001) and B (p = 0.007) are real; AB (p = 0.065) is not distinguishable from noise. A two-way ANOVA gives the same tests: each F is t², 102.4, 25.6 and 6.4.
Worked example: a third level of time (2×3)

Temperature (A) at two levels and time (B) at three, two runs per cell (N = 12, 6 error df):

B lowB midB highrow mean
A low59, 61 → 6065, 69 → 6763, 65 → 6463.67
A high70, 74 → 7280, 82 → 8183, 85 → 8479.00
column mean66747471.33
  1. Curvature: the middle level against the straight line between the ends, yˉmid−(yˉlow+yˉhigh)/2=74−(66+74)/2=4\bar y_{mid} - (\bar y_{low} + \bar y_{high})/2 = 74 - (66 + 74)/2 = 4. Two levels of time could not have shown it.
  2. Split B's 2 df with the contrasts (−1, 0, 1) and (1, −2, 1): SS=a n (∑jcjyˉj)2/∑jcj2SS = a\,n\,(\textstyle\sum_j c_j \bar y_j)^2 / \sum_j c_j^2, giving 128 (linear) and 42.67 (curvature), which add to B's 170.67.
SourceSSdfMSFp
A (temperature)705.331705.33176.33< 0.001
B (time)170.67285.3321.330.002
  linear128.001128.0032.000.001
  curvature42.67142.6710.670.017
AB34.67217.334.330.068
Error24.0064.00

Answer: temperature and time both matter, time's effect bends (p = 0.017), and the interaction is not significant at 5% (p = 0.068). Checked against statsmodels' anova_lm.

More worked material: statistics basics and linear regression and the basics of simulation, in Python and R side by side, with an R and Python cheat sheet.

← IE 3301 Engineering Probability