The normal distribution — theory with a gofio filling machine, the bell curve, standardising and quantiles (and the 39 % that wasn’t)

At a gofio mill in the north of the island I took my phone out to show off and told the manager that 39 % of his packets weighed less than a kilo. He had told us that his filling machine fills one-kilo packets with a mean of 1010 grams and a variance of 36, and I had typed pnorm(1000, 1010, 36), which gave 0.39. He looked at me the way you look at someone who has just called your boss a thief. The mistake was mine: R wants the standard deviation, not the variance. With pnorm(1000, 1010, 6) you get 0.048, less than 5 %. One wrong number and the conclusion goes from “the machine is fine” to “the machine is a scam”.

This topic is about the normal distribution, the bell curve: the one you will use most in ME1, in ME2 and in everything that comes after, because sums and averages of almost anything end up looking like it. We carry on from continuous random variables: a density, its distribution function, its moments and R’s d, p, q and r functions. The difference is that the normal has no distribution function you can write as a formula, so here you learn to standardise, to read quantiles and to combine normals. All of it with the filling machine of a gofio cooperative (gofio is the toasted grain flour of the Canary Islands), with made-up but realistic data. The proofs, step by step, are in the normal distribution proofs.

Before you start. For this topic you need topic 4, continuous random variables: that in a continuous variable probability is an area under the density, that the distribution function F(x) F(x) is the area up to x x , that a quantile is the value that leaves a given probability to its left, and R’s d, p, q and r functions. You need no new calculus: nothing is integrated by hand here. The topic has four big ideas, in this order: what the bell looks like and what its two parameters do (the density); why its area has no formula and how you ask R or the table for it (pnorm and standardising, with symmetry for negative tails); the way back, from an area to a weight (qnorm); and what happens when you change units, add or subtract normals. We use the same example all the way through: the gofio filling machine, X∼N(1010,6) X \sim N(1010, 6) . If you get lost, draw the bell, mark the weight and shade the area you are asked for: almost every mistake in this topic shows up in that drawing.

The bell that shows up everywhere

Why so many things are normal

Think about what decides how much gofio falls into a packet: the moisture of the grain that day, how compact it comes out of the hopper, a vibration of the belt, the exact instant the gate closes, the temperature of the motor… Each one pushes a few grams up or down, and none of them dominates the rest. When a result is the sum of many small, independent effects, its distribution gets close to a symmetric bell. That is what the central limit theorem says, which you will see in topic 7, and it is why the normal appears in the weight of packets, in people’s height, in the measurement errors of a sensor, in the marks of a large exam or in the time a task repeated a thousand times takes.

The normal is also called the Gaussian distribution or Gaussian bell curve, after Carl Friedrich Gauss, who used it for the errors of astronomical measurements at the start of the 19th century.

The example for the whole topic

The cooperative has a machine that fills 1 kg packets of gofio. It does not always put in the same amount: if you weigh many packets, most are close to 1010 g, a few go to 995 or 1025 and almost none go beyond that. We call XX the weight of a packet, in grams, and the model we will use is

X∼N(1010, 6) X \sim N(1010,\ 6)

that is, a mean of 1010 grams and a standard deviation of 6 grams. The label says “1 kg”, so the question the cooperative cares about is how many packets weigh less than 1000 g. Throughout the topic we will also adjust the machine, put the packets into boxes of 12 and compare two machines.

Before the formula: what shape the bell has to have

Before seeing the density with all its symbols, let’s work out what it has to satisfy from what we already know about the filling machine. The question is simple: if you weigh lots of packets, how are the weights spread out?

  • There is a center. Most packets land near 1010 g, so the density has to peak there.
  • The side doesn’t matter. The machine has no preference for overfilling or underfilling: a 1004 g packet is as likely as a 1016 g one. The curve has to be symmetric about 1010.
  • Far away drops fast. There are few packets of 995 g or 1025 g, and almost none of 1040 g. It is not enough for the curve to go down: it has to go down faster and faster.
  • Distance is measured in standard deviations. “Far” depends on the machine. 12 grams is a lot for a precise machine and not much for a shaky one. The natural thing is to count distance in standard deviations: 12 g with σ=6 \sigma = 6 is 2 standard deviations.
  • The total area is 1, as for any density.

The function that does all of that is e−z2/2 e^{-z^2/2} , where z z is the distance from the center counted in standard deviations. Look at how the height, compared with the peak, falls as you move away from the center of the filling machine:

Weight (g)Distance in standard deviations, z z Relative height, e−z2/2 e^{-z^2/2} Why
101001It is the peak: e0=1 e^0 = 1
1016 or 100410.61The square makes z=1 z = 1 and z=−1 z = -1 give the same value: that is the symmetry
1022 or 99820.14Twice as far does not give half the height (0.30), but much less: the exponent is −22/2=−2 -2^2/2 = -2
1028 or 99230.01With −9/2 -9/2 in the exponent there is almost nothing left
1034 or 98640.0003That is why a packet 4 standard deviations away makes you suspect the machine

All that is left is making the total area 1. The curve e−z2/2 e^{-z^2/2} has area 2π \sqrt{2\pi} (it is the Gaussian integral), and going from z z to grams stretches it sideways by σ \sigma . So you have to divide by σ2π \sigma\sqrt{2\pi} . With z=x−μσ z = \frac{x – \mu}{\sigma} , what comes out is the normal density coming up next. It is not a formula that falls from the sky: it is “a bell that falls with the square of the distance in standard deviations, adjusted so that the area is 1”.

The normal density

What it is

A continuous random variable XX, taking values on the whole real line, follows a normal distribution with parameters μ\mu and σ\sigma, written X∼N(μ,σ)X \sim N(\mu, \sigma), if its density function is f(x)=1σ2π e−(x−μ)22σ2f(x) = \dfrac{1}{\sigma\sqrt{2\pi}}\, e^{-\frac{(x-\mu)^2}{2\sigma^2}} for every real xx, with real μ\mu and σ>0\sigma > 0. The case μ=0\mu = 0, σ=1\sigma = 1 is the standard normal.

f(x)=1σ2π exp⁡{−12 (x−μ)2σ2},−∞<x<+∞ f(x) = \frac{1}{\sigma\sqrt{2\pi}}\ \exp\left\{-\frac{1}{2}\,\frac{(x-\mu)^2}{\sigma^2}\right\}, \qquad -\infty < x < +\infty

Look at the formula piece by piece, because each piece explains something in the picture:

  • (x−μ)2(x – \mu)^2 measures how far xx is from the center. Because it is squared, moving away to the left is the same as moving away to the right: hence the symmetry.
  • The minus sign and the exponential make the density smaller the further away you go, and very fast: going twice as far does not halve the height, it divides it by a huge amount.
  • Dividing by σ2\sigma^2 turns the distance into “number of standard deviations”. Being 12 grams from the center with σ=6\sigma = 6 is being 2 deviations away; with σ=3\sigma = 3 it would be 4, and that is already very far.
  • 1σ2π\frac{1}{\sigma\sqrt{2\pi}} is the constant that makes the total area 1. That 2π\sqrt{2\pi} appears is not obvious: it is the Gaussian integral, proved in proof 1.

The ME1 notes and R write N(μ,σ)N(\mu, \sigma), with the standard deviation. Many books (and other courses) write N(μ,σ2)N(\mu, \sigma^2), with the variance. Before using a figure, check what you are being given: if the statement says “variance 36”, R gets a 6. It is exactly the 39 % mistake from the beginning.

The shape of the bell

The filling machine bell, N(1010, 6)Normal density with mean 1010 and standard deviation 6 between 985 and 1035 grams. The peak, 0.0665, is at 1010, where mean, median and mode coincide. Coral dots at 1004 and 1016, the inflection points, one standard deviation from the center. Coral tail left of 1000, with area 0.0478.0.000.020.040.06986992998100410101016102210281034Packet weight, in gramsf(x)μ = 1010: mean,median and modeμ − σμ + σinflectionσ = 6P(X < 1000)= 0.0478
Symmetric about 1010, with the curvature changing one σ from the center. The coral tail is the packets under one kilo.

Look at the drawing of the filling machine, N(1010,6)N(1010, 6). Everything important can be read from it:

  • It is symmetric about μ\mu. The density at 1004 is the same as at 1016, because both are 6 g from the center.
  • Mean, median and mode coincide at μ\mu. The peak is at 1010 (mode), half the area lies on each side of 1010 (median) and the balance point is also 1010 (mean).
  • The inflection points are at μ−σ\mu – \sigma and μ+σ\mu + \sigma, at 1004 and 1016: there the curve stops “bending down” and starts “bending up”. It is a way to see σ\sigma in the picture.
  • The maximum height is 1σ2π\frac{1}{\sigma\sqrt{2\pi}}, which with σ=6\sigma = 6 is 0.0665. It is not a probability: it is a density, just like in the previous topic.
  • It never touches zero. Mathematically, a 950 g packet has a positive density, even if it is a number with many zeros. In practice, beyond 3 or 4 deviations there is hardly anything.

That the normal allows any real value, negative ones too, does not mean a packet can weigh −20 g. The model is an approximation: for the gofio weight the probability of a negative value is so small (it is 168 deviations from the center) that it does not matter. Where it does matter, you will see further down that the normal does not work.

How μ\mu and σ\sigma change it

The two parameters do different things, and it is worth seeing in R. We compare the cooperative’s machine with a new machine, N(1004,4)N(1004, 4), which puts in a bit less but is more precise:

x <- seq(980, 1040, length = 300)   # grid of weights, in grams
par(mfrow = c(1, 2))                # two plots, side by side
# Densities: the old one (violet) and the new one (coral)
plot(x, dnorm(x, 1010, 6), type = "l", lwd = 2, col = "purple",
     ylim = c(0, 0.11), xlab = "grams", ylab = "f(x)")
lines(x, dnorm(x, 1004, 4), lwd = 2, col = "tomato")
# Distribution functions of both
plot(x, pnorm(x, 1010, 6), type = "l", lwd = 2, col = "purple",
     xlab = "grams", ylab = "F(x)")
lines(x, pnorm(x, 1004, 4), lwd = 2, col = "tomato")
c(dnorm(1010, 1010, 6), dnorm(1004, 1004, 4))   # heights of the peaks

Output:

[1] 0.06649038 0.09973557
Two filling machines: densities and distribution functionsOn the left, the densities of the old machine, normal 1010 6 in violet, peak 0.0665, and the new one, normal 1004 4 in coral, taller and narrower, peak 0.0997. On the right, their distribution functions, two S curves crossing height 0.5 at 1010 and 1004 and crossing each other at 992.0.000.050.10980100010201040gramsf(x)0.06650.09970.00.51.0980100010201040gramsF(x)cross at 992old, N(1010, 6)new, N(1004, 4)
What the code with par(mfrow = c(1, 2)) draws: μ moves the bell, σ narrows and raises it.

How to read it

  • [1] 0.06649038 0.09973557 are the heights of the two peaks: 162π=0.0665\frac{1}{6\sqrt{2\pi}} = 0.0665 and 142π=0.0997\frac{1}{4\sqrt{2\pi}} = 0.0997. The new one has a taller bell because it is narrower: the area under each curve is still 1, so if it shrinks sideways it has to grow upwards.
  • In the left-hand plot, μ\mu moves the bell along the axis without changing its shape: the coral one is 6 grams further left.
  • σ\sigma widens or narrows it. The violet one (σ=6\sigma = 6) is lower and wider; the coral one (σ=4\sigma = 4), taller and tighter.
  • On the right, the two distribution functions are S curves rising from 0 to 1. Each crosses height 0.5 exactly at its mean (1004 and 1010), because in the normal the mean is the median. The coral one is steeper: since the new machine is more precise, probability builds up over a shorter stretch.
  • The two S curves cross at 992 g (where x−10106=x−10044\frac{x – 1010}{6} = \frac{x – 1004}{4}): to the left of that point, the new one has more accumulated probability. We will use this when comparing the two machines.

The distribution function

No formula: it is computed

The distribution function is, as always, the area of the density up to xx:

F(x)=P(X≤x)=∫−∞x1σ2π e−(t−μ)22σ2 dt F(x) = P(X \le x) = \int_{-\infty}^{x} \frac{1}{\sigma\sqrt{2\pi}}\, e^{-\frac{(t-\mu)^2}{2\sigma^2}}\, dt

The surprise is that this integral has no antiderivative you can write with elementary functions (polynomials, exponentials, logarithms, sines…). It is not that it is hard: it has been proved that none exists. That is why FF is evaluated numerically, and for the standard normal it has its own name:

Φ(z)=P(Z≤z),Z∼N(0,1) \Phi(z) = P(Z \le z), \qquad Z \sim N(0, 1)

People used to look it up in a printed table of Φ\Phi; in ME1 you use pnorm. In the exam you are not asked to integrate the normal; you are asked to know which area to compute and how to ask R for it.

The probability that a packet weighs less than a kilo

pnorm(1000, mean = 1010, sd = 6)        # P(X <= 1000)
1 - pnorm(1000, 1010, 6)                # P(X > 1000)
pnorm(1000, 1010, 6, lower.tail = FALSE)   # the same, without subtracting
pnorm(1020, 1010, 6) - pnorm(1000, 1010, 6)  # P(1000 < X < 1020)

Output:

[1] 0.04779035
[1] 0.9522096
[1] 0.9522096
[1] 0.9044193

How to read it

  • 0.04779035: 4.78 % of the packets weigh less than 1 kg. With two decimals, as in the exam, 0.05. It is the area of the left tail you see in the bell drawing.
  • 0.9522096 and again 0.9522096: what is left up to 1. Both lines say the same; lower.tail = FALSE asks directly for the right tail, and for very small tails it is more accurate than subtracting.
  • 0.9044193: 90.4 % of the packets weigh between 1 and 1.02 kg. The probability of an interval is the FF of the right end minus that of the left end, the same rule as in the previous topic.
  • For a continuous variable << and ≤\le are the same: P(X=1000)=0P(X = 1000) = 0, so P(X<1000)=P(X≤1000)P(X < 1000) = P(X \le 1000). In the discrete variables of topic 3 that was not the case, and it is a source of mistakes when you switch topics.

Writing pnorm(1000, 1010, 6) when you are asked about weighing more than 1000. pnorm always gives the area on the left. Before typing, draw the bell and shade what you are asked for: if it is the right tail, put 1 - in front.

Standardising: the standard normal

The idea

All normals are the same bell, stretched and shifted. If you subtract the mean from a weight and divide by the standard deviation, what is left is how many standard deviations it is above or below the center. That is standardising:

X∼N(μ,σ)⟹Z=X−μσ∼N(0,1) X \sim N(\mu, \sigma) \quad\Longrightarrow\quad Z = \frac{X – \mu}{\sigma} \sim N(0, 1)

And the way back, which matters just as much:

Z∼N(0,1)⟹X=μ+σZ∼N(μ,σ) Z \sim N(0, 1) \quad\Longrightarrow\quad X = \mu + \sigma Z \sim N(\mu, \sigma)

Both results are theorem 5 in the notes and are proved in proof 2.

Standardising is changing rulerThe filling machine bell with two rulers below: grams on top, from 986 to 1034, and z values below, from minus 4 to 4, lined up so that 1010 sits on 0 and every 6 grams is one unit. The 1000 gram packet falls at z equals minus 1.67, and the coral tail is worth 0.0478 on both rulers.986992998100410101016102210281034x (g)-4-3-2-101234zz = (1000 − 1010)/6 = −1.67same area: 0.0478x = μ + σzz = (x − μ)/σN(1010, 6)N(0, 1)
Every 6 grams is one standard deviation. The tail area does not change from one ruler to the other.

In the drawing, the top ruler is in grams and the bottom one in zz. A 1000 g packet is 1000−10106=−1.67\frac{1000 – 1010}{6} = -1.67 standard deviations away: a bit more than one and a half below the center. Areas do not change when you move from one ruler to the other:

P(X≤1000)=P(X−10106≤1000−10106)=P(Z≤−1.67)=Φ(−1.67) P(X \le 1000) = P\left(\frac{X – 1010}{6} \le \frac{1000 – 1010}{6}\right) = P(Z \le -1.67) = \Phi(-1.67)
z <- (1000 - 1010) / 6     # how many standard deviations below
z
pnorm(z)                   # Phi(z): standard normal, no need for 0 and 1
pnorm(1000, 1010, 6)       # without standardising: the same number

Output:

[1] -1.666667
[1] 0.04779035
[1] 0.04779035

How to read it

  • -1.666667 is the zz of the one-kilo packet. The sign tells you the side: negative, below the mean.
  • The last two lines give 0.04779035. Standardising does not change the probability, only the ruler it is measured with. When pnorm gets a single number, it uses the standard normal (its defaults are mean = 0 and sd = 1).
  • In the exam, if you have the data and R, you can compute without standardising. But proofs and paper questions are done by standardising, and in topics 8 to 11 almost everything starts with a ZZ.

Going back from ZZ to XX with the wrong algebra. If z=x−μσz = \frac{x – \mu}{\sigma}, then x=μ+zσx = \mu + z\sigma, not μ−zσ\mu – z\sigma nor z−μσ\frac{z – \mu}{\sigma}. Quick check: with z=0z = 0 you must get the mean, and with a negative zz, something below it.

Standardising, step by step

The formula above does four things in one line. Here they are separately, with the one-kilo packet, because it is the move you will repeat in almost every exercise of the topic:

StepCalculationWhy
1P(X≤1000) P(X \le 1000) It is what is being asked: the proportion of packets under one kilo
2P(X−1010≤−10) P(X – 1010 \le -10) Subtracting the same thing (the mean) from both sides of an inequality does not change it: now we measure from the center
3P(X−10106≤−106) P\left(\frac{X – 1010}{6} \le \frac{-10}{6}\right) Dividing by a positive number (σ=6 \sigma = 6 ) does not flip it either: now we measure in standard deviations
4P(Z≤−1.67) P(Z \le -1.67) The left-hand side is Z Z , which is N(0,1) N(0, 1) by theorem 5. On the right, z z rounded to two decimals
5Φ(−1.67)=0.0475 \Phi(-1.67) = 0.0475 It is an area to the left in the standard normal: pnorm(-1.67), or the table with the symmetry in the next section

Why 0.0475 and not the 0.04779 from before? Because z z was rounded. pnorm(z) with z=−1.666667 z = -1.666667 gives 0.0478, and with −1.67 -1.67 it gives 0.0475. With two decimals, both are 0.05. The underlying idea is that the inequality is transformed in the same way on both sides, so the event is the same and so is the probability. The only thing that changes is the ruler you measure with.

The sign of z z already gives you half the answer. If z z is negative, the weight is below the mean and Φ(z) \Phi(z) has to come out below 0.5. With z=−1.67 z = -1.67 , a probability of 0.95 would be the wrong tail.

Symmetry saves calculations

Since the standard normal is symmetric about 0:

Φ(−z)=1−Φ(z) \Phi(-z) = 1 – \Phi(z)

Why it holds, in words: the standard bell is a mirror with the glass at 0. The tail to the left of −1.67 -1.67 is the exact reflection of the tail to the right of +1.67 +1.67 , and that right tail is everything (1) minus what lies to the left of +1.67 +1.67 . With that idea you get the four cases that come up in the exercises, with a>0 a > 0 :

You are asked forYou turn it intoWhyWith a=1.67 a = 1.67
P(Z≤−a) P(Z \le -a) 1−Φ(a) 1 – \Phi(a) Mirror: the left tail of −a -a is the right tail of a a 0.0475
P(Z>−a) P(Z > -a) Φ(a) \Phi(a) Mirror again: what lies to the right of −a -a is what lies to the left of a a 0.9525
P(Z>a) P(Z > a) 1−Φ(a) 1 – \Phi(a) It is the complement of Φ(a) \Phi(a) : everything minus the left0.0475
P(−a<Z<a) P(-a < Z < a) 2Φ(a)−1 2\Phi(a) – 1 The middle is 1 minus two equal tails: 1−2 (1−Φ(a)) 1 – 2\,(1 – \Phi(a)) 0.9050

Writing Φ(−1.67)=−Φ(1.67) \Phi(-1.67) = -\Phi(1.67) , or 1−Φ(−1.67) 1 – \Phi(-1.67) for the left tail. A probability is never negative, and 1−Φ(−1.67) 1 – \Phi(-1.67) is the tail to the right of −1.67 -1.67 , not the left one. Quick check: if z z is negative, Φ(z) \Phi(z) has to come out below 0.5.

The area to the left of −1.67-1.67 is the same as to the right of +1.67+1.67. And for absolute values:

P(∣Z∣≤z)=Φ(z)−Φ(−z)=2Φ(z)−1 P(|Z| \le z) = \Phi(z) – \Phi(-z) = 2\Phi(z) – 1

With the filling machine: what proportion of packets is less than 5 grams away from the mean?

P(∣X−1010∣<5)=P(∣Z∣<56)=2 Φ(0.83)−1 P(|X – 1010| < 5) = P\left(|Z| < \tfrac{5}{6}\right) = 2\,\Phi(0.83) – 1
2 * pnorm(5 / 6) - 1                           # with the formula
pnorm(1015, 1010, 6) - pnorm(1005, 1010, 6)    # with the interval

Output:

[1] 0.5953432
[1] 0.5953432

Both give 0.5953: a little under 60 % of the packets are less than 5 grams from 1010. The absolute value is always solved the same way: ∣X−μ∣<c|X – \mu| < c is the interval (μ−c,μ+c)(\mu – c, \mu + c).

“Shifted” absolute values, like P(∣X∣≥1)P(|X| \ge 1) when μ≠0\mu \ne 0, are not symmetric about the mean. Do not use the 2Φ−12\Phi – 1 formula: write the interval and subtract with pnorm.

If you are given the table instead of R

In ME1 you work with pnorm, but it is worth knowing how to read the Φ \Phi table: it appears in books and in many old exams, and it is the best way to understand what pnorm returns. The usual table gives Φ(z) \Phi(z) only for z≥0 z \ge 0 and with two decimals: the row gives the units and the first decimal digit, and the column gives the second. With the one-kilo packet:

  1. Round z z to two decimals. −1.666… -1.666\ldots becomes −1.67 -1.67 .
  2. Drop the sign. The table has no negatives: you look up 1.67 1.67 and then use symmetry.
  3. Row and column. Row 1.6 and column 0.07: it says 0.9525. That is Φ(1.67) \Phi(1.67) , the area to the left of 1.67 1.67 .
  4. Put the sign back. Φ(−1.67)=1−0.9525=0.0475 \Phi(-1.67) = 1 – 0.9525 = 0.0475 .

It is the same as pnorm(-1.67). Think of pnorm as an infinite table, with every decimal of z z : that is why pnorm(1000, 1010, 6), which uses the unrounded z z , gives 0.0478 and not 0.0475. With two decimals both give 0.05, which is what counts in the exam.

The same goes for the packets less than 5 grams from the mean. 5/6=0.83 5/6 = 0.83 ; row 0.8 and column 0.03 give Φ(0.83)=0.7967 \Phi(0.83) = 0.7967 , and 2⋅0.7967−1=0.5934 2 \cdot 0.7967 – 1 = 0.5934 . R gave 0.5953 because it uses 0.8333… 0.8333\ldots : once again, the difference is only the rounding of z z .

When you use the table, write z z with two decimals before looking it up and say in your answer that you rounded it. If you compare with pnorm and see a difference in the third decimal, that is why; it is not a mistake.

Check you’ve got it: using only the table, what proportion of packets weigh more than 1020 g?

About 0.05. First you standardise: z=1020−10106=1.67 z = \frac{1020 – 1010}{6} = 1.67 . You are asked for the right tail, so P(Z>1.67)=1−Φ(1.67)=1−0.9525=0.0475 P(Z > 1.67) = 1 – \Phi(1.67) = 1 – 0.9525 = 0.0475 . It comes out the same as for the packets under 1000 g, and that is no coincidence: 1000 and 1020 are both 10 g from the mean, one on each side, and the two tails are reflections of each other. With pnorm, 1 – pnorm(1020, 1010, 6) gives 0.0478; with two decimals, 0.05 both.

The 68-95-99.7 rule

There are three numbers worth knowing by heart, because they hold for any normal:

P(∣X−μ∣≤σ)≈0.68P(∣X−μ∣≤2σ)≈0.95P(∣X−μ∣≤3σ)≈0.997 P(|X – \mu| \le \sigma) \approx 0.68 \qquad P(|X – \mu| \le 2\sigma) \approx 0.95 \qquad P(|X – \mu| \le 3\sigma) \approx 0.997
The 68-95-99.7 rule for the filling machineThe filling machine bell with three shaded bands: between 1004 and 1016 lies 68.27 percent of the packets, between 998 and 1022 95.45, and between 992 and 1028 99.73. Below, three bars with those intervals, at one, two and three standard deviations.0.000.020.040.0699299810041010101610221028Packet weight, in gramsf(x)68.27 % (μ ± 1σ)95.45 % (μ ± 2σ)99.73 % (μ ± 3σ)
The percentages are the same for any normal: only the grams at the ends change.

With the filling machine, in the drawing: 68 % of the packets weigh between 1004 and 1016 g, 95 % between 998 and 1022 g, and 99.7 % between 992 and 1028 g. A 985 g packet is more than 4 deviations away: if one turns up, the sensible thing is to suspect the machine before bad luck.

k <- 1:3
round(pnorm(k) - pnorm(-k), 4)    # P(|Z| <= k) for k = 1, 2, 3

Output:

[1] 0.6827 0.9545 0.9973

0.6827 0.9545 0.9973: these are the exact values. They do not depend on μ\mu or σ\sigma, because standardising turns every normal into the same ZZ. It is the same empirical rule you saw in descriptive statistics for bell-shaped data: there it was an approximate rule for data; here it is an exact property of the model.

Use it to sanity-check any pnorm result. If you get that 30 % of the packets are more than 3 deviations from the center, you have typed something wrong (probably the variance where the standard deviation should go).

Check you’ve got it: without calculating anything, what proportion of packets weigh more than 1022 g?

Roughly 2.5 %. 1022 is 1010+2⋅6 1010 + 2 \cdot 6 : it is two standard deviations above the mean. Between μ−2σ \mu – 2\sigma and μ+2σ \mu + 2\sigma lies 95 %, so 5 % lies outside. That 5 % is split into two equal tails by symmetry, and the upper one gets half: 2.5 %. The exact value is 1 – pnorm(2) = 0.0228, 0.02 with two decimals; it comes out a little lower because the rule rounds 0.9545 to 0.95.

Quantiles: qnorm

From the area to the value

pnorm goes from a value to an area; qnorm goes the other way: you give it a probability pp and it returns the value xpx_p that leaves that probability to its left.

P(X≤xp)=p⟺xp=μ+zp σ P(X \le x_p) = p \qquad\Longleftrightarrow\qquad x_p = \mu + z_p\,\sigma

where zpz_p is the standard quantile. These five quantiles come back again and again (in the confidence intervals of topic 11, above all):

round(qnorm(c(0.90, 0.95, 0.975, 0.99, 0.995)), 4)

Output:

[1] 1.2816 1.6449 1.9600 2.3263 2.5758
pp0.900.950.9750.990.995
zpz_p1.28161.64491.96002.32632.5758

The 1.96 is the “2” of the 68-95-99.7 rule, sharpened: between −1.96-1.96 and 1.961.96 lies exactly 95 %.

“More than” becomes “less than”

The typical statement is: “what weight do only 10 % of the packets exceed?”. You are given an area on the right, and qnorm works with areas on the left:

P(X>x)=0.10  ⟺  P(X≤x)=0.90  ⟺  x=x0.90 P(X > x) = 0.10 \iff P(X \le x) = 0.90 \iff x = x_{0.90}
The top 10 % and the bottom 10 %The filling machine bell with two 10 percent tails: the right one, in coral, from 1017.69, which is qnorm of 0.90; the left one, in violet, up to 1002.31, which is qnorm of 0.10. Between them lies 90 percent.0.000.020.040.069901002.3110101017.691030Packet weight, in gramsf(x)10 %10 %90 %only 10 % exceed itqnorm(0.90, 1010, 6)leaves 10 % belowqnorm(0.10, 1010, 6)
qnorm always leaves its probability to the left: "what only 10 % exceed" is the 0.90 quantile.
qnorm(0.90, 1010, 6)          # what only 10 % exceed
1010 + qnorm(0.90) * 6        # the same, standardising backwards
qnorm(0.10, 1010, 6)          # what it is NOT: leaves 10 % on the left
qnorm(0.10, 1010, 6, lower.tail = FALSE)   # this also works

Output:

[1] 1017.689
[1] 1017.689
[1] 1002.311
[1] 1017.689

How to read it

  • 1017.689: only 10 % of the packets weigh more than 1017.69 g. With two decimals, 1017.69.
  • The second line gives the same: it is xp=μ+zpσ=1010+1.2816⋅6x_p = \mu + z_p\sigma = 1010 + 1.2816 \cdot 6. It is standardising in reverse.
  • 1002.311 is the 0.10 quantile: the weight below which 10 % lie. It is the same distance from the center (7.69 g) but on the other side: symmetry again.
  • lower.tail = FALSE tells qnorm that the probability you give it is the one on the right. It gives 1017.689, like the first line.

Answering qnorm(0.10, 1010, 6) to “what only 10 % exceed”. You get a weight below the mean, and the question is about the heaviest packets. If the result lands on the wrong side of the center, check the tail.

A quantile, step by step

Quantile questions are pnorm in reverse, and that is why you solve them in the opposite order: first the area, then z z , and finally the grams. With “what weight do only 10 % of the packets exceed?”:

StepWhat you doWhy
1Draw the bell and shade the right-hand 10 %The question is about the heaviest packets: it is the right tail
2Turn it into the left: P(X≤x)=0.90 P(X \le x) = 0.90 qnorm and the table work with the area to the left
3Find z0.90=1.2816 z_{0.90} = 1.2816 In R, qnorm(0.90). With the table, you look for 0.90 inside the table: it lies between Φ(1.28)=0.8997 \Phi(1.28) = 0.8997 and Φ(1.29)=0.9015 \Phi(1.29) = 0.9015 , closer to 1.28
4Undo the standardisation: x=1010+1.2816⋅6=1017.69 x = 1010 + 1.2816 \cdot 6 = 1017.69 From z=x−μσ z = \frac{x – \mu}{\sigma} you solve x=μ+zσ x = \mu + z\sigma
5Check: 1017.69 is above 1010, and pnorm(1017.69, 1010, 6) gives 0.90A quantile of the right tail has to fall to the right of the center

For left tails, symmetry gives a shortcut: z1−p=−zp z_{1-p} = -z_p . The lightest 5 %, for example, lies below z0.05=−1.6449 z_{0.05} = -1.6449 , which is the 1.6449 from the quantile table with the sign changed. In grams, 1010−1.6449⋅6=1000.13 1010 – 1.6449 \cdot 6 = 1000.13 .

Check you’ve got it: what weight do 95 % of the packets exceed?

1000.13 g. “95 % exceed it” leaves 95 % to the right, so 5 % is left to the left: it is the 0.05 quantile, not the 0.95 one. With z0.05=−1.6449 z_{0.05} = -1.6449 , x=1010−1.6449⋅6=1000.13 x = 1010 – 1.6449 \cdot 6 = 1000.13 . In R, qnorm(0.05, 1010, 6). Check: it falls below the mean, as it must if almost every packet exceeds it. If you got qnorm(0.95, 1010, 6) = 1019.87, that is the weight that only 5 % exceed.

Adjusting the machine

Now the question the cooperative really asks: where should the mean be set so that only 1 % of the packets weigh less than a kilo, without changing the machine’s precision (σ=6\sigma = 6)? We want P(X<1000)=0.01P(X < 1000) = 0.01, with X∼N(μ,6)X \sim N(\mu, 6) and μ\mu unknown. Standardising:

P(Z<1000−μ6)=0.01  ⟹  1000−μ6=z0.01=−2.3263  ⟹  μ=1000+2.3263⋅6=1013.96 P\left(Z < \frac{1000 – \mu}{6}\right) = 0.01 \;\Longrightarrow\; \frac{1000 – \mu}{6} = z_{0.01} = -2.3263 \;\Longrightarrow\; \mu = 1000 + 2.3263 \cdot 6 = 1013.96
mu <- 1000 - qnorm(0.01) * 6   # solving for mu
mu
pnorm(1000, mu, 6)             # check: it must give 0.01

Output:

[1] 1013.958
[1] 0.01

1013.958 and 0.01: with the mean at 1013.96 g, one packet in a hundred weighs less than 1 kg. Watch the sign: z0.01z_{0.01} is negative, so subtracting it adds 13.96 grams. Every packet carries almost 14 grams of gofio “given away” to meet the label; the other way to comply is to improve the machine (lower σ\sigma), which is what the new machine does.

Put into words: 1000 g has to sit exactly at the point that leaves 1 % to its left. In any normal, that point is 2.33 standard deviations below the mean. So the mean has to be 2.33 standard deviations above 1000, that is, 2.3263⋅6=13.96 2.3263 \cdot 6 = 13.96 grams above. The whole calculation above is that sentence written in symbols.

Check you’ve got it: with the new filling machine (σ=4 \sigma = 4 ), where do you have to set the mean so that only 1 % of the packets weigh less than 1 kg?

At 1009.31 g. The sentence is the same: the mean has to be 2.3263 standard deviations above 1000, but now each standard deviation is 4 g. So μ=1000+2.3263⋅4=1009.31 \mu = 1000 + 2.3263 \cdot 4 = 1009.31 ; in R, 1000 – qnorm(0.01) * 4. You give away 9.31 g per packet instead of 13.96: about 4.65 g less per packet, just from having a more precise machine.

Mean, variance and mgf

The parameters of the normal are its mean and its standard deviation, and that is not a coincidence of notation:

E(X)=μ,Var(X)=σ2,φX(t)=E(etX)=eμt+12σ2t2 E(X) = \mu, \qquad \mathrm{Var}(X) = \sigma^2, \qquad \varphi_X(t) = E\left(e^{tX}\right) = e^{\mu t + \frac{1}{2}\sigma^2 t^2}

It is theorem 6 in the notes. The mgf comes from “completing the square” in the integral and, differentiating it at t=0t = 0, the mean and the variance appear; they can also be obtained without differentiating, using X=μ+σZX = \mu + \sigma Z and linearity. Both routes are in proof 3.

The normal mgf exists for every real tt, unlike that of the exponential or the gamma in the previous topic, which only existed for t<λt < \lambda. And since the mgf characterises the distribution, it is the tool for proving that a combination of normals is normal: if its mgf has the form eat+12bt2e^{at + \frac{1}{2}bt^2}, it is an N(a,b)N(a, \sqrt{b}).

Linear combinations of normals

This is the part that pays off most in the exam, because it lets you go from a packet to a box, from grams to kilos or from one machine to the difference between two.

Changing scale: aX + b

X∼N(μ,σ)  ⟹  aX+b∼N(aμ+b, ∣a∣ σ) X \sim N(\mu, \sigma) \;\Longrightarrow\; aX + b \sim N\big(a\mu + b,\ |a|\,\sigma\big)

A change of units takes nobody out of the normal. If you convert the weight to kilos, Y=X/1000∼N(1.010, 0.006)Y = X / 1000 \sim N(1.010,\ 0.006). If you subtract the 1000 grams on the label to keep only the “gift”, X−1000∼N(10,6)X – 1000 \sim N(10, 6): the standard deviation does not change when you add a constant, because shifting does not widen. It is proved with the mgf in proof 5.

Multiplying the variance by aa instead of a2a^2, or the standard deviation by a2a^2. The rule is: the mean times aa, the variance times a2a^2, the standard deviation times ∣a∣|a|. In kilos: σ=6/1000=0.006\sigma = 6/1000 = 0.006 and σ2=36/106=0.000036\sigma^2 = 36/10^6 = 0.000036.

Adding independent normals

If X1,…,XnX_1, \dots, X_n are independent normals, Xi∼N(μi,σi)X_i \sim N(\mu_i, \sigma_i), then

X1+⋯+Xn∼N(μ1+⋯+μn, σ12+⋯+σn2) X_1 + \cdots + X_n \sim N\left(\mu_1 + \cdots + \mu_n,\ \sqrt{\sigma_1^2 + \cdots + \sigma_n^2}\right)

The means add and the variances add, not the standard deviations. A box with 12 packets from the machine weighs

S=X1+⋯+X12∼N(12⋅1010, 12⋅36)=N(12120, 20.78) S = X_1 + \cdots + X_{12} \sim N\left(12 \cdot 1010,\ \sqrt{12 \cdot 36}\right) = N(12120,\ 20.78)
One packet and a box of 12On the left, the bell of one packet, normal 1010 6, with a bar measuring its standard deviation, 6. On the right, that of a box of 12 independent packets, normal 12120 20.78: its standard deviation is 6 times root 12, not 72.0.0000.0350.07099010101030one packet (g)fσ = 60.0000.0110.02212,06012,12012,180box of 12 (g)σ√12 = 20.78N(1010, 6)N(12120, 20.78)× 12Mean × 12; variance × 12; standard deviation × √12 ≈ 3.46 (not × 12 = 72).
Twelve packets together compensate each other: the box is 12 times heavier but only 3.46 times more uncertain.

In the drawing, the box has its bell 12 times further right but only 12≈3.46\sqrt{12} \approx 3.46 times wider. The errors of the packets partly cancel out: one goes over, another falls short. If you added the standard deviations (12⋅6=7212 \cdot 6 = 72), you would be assuming that all the packets get it wrong at the same time and in the same direction, and that is not independence.

Subtracting independent normals

The case people get wrong most: the difference. We compare a packet from the old machine, XA∼N(1010,6)X_A \sim N(1010, 6), with one from the new machine, XB∼N(1004,4)X_B \sim N(1004, 4):

D=XA−XB∼N(1010−1004, 62+42)=N(6, 7.21) D = X_A – X_B \sim N\left(1010 – 1004,\ \sqrt{6^2 + 4^2}\right) = N(6,\ 7.21)

When subtracting, the variances also add: Var(XA−XB)=Var(XA)+(−1)2 Var(XB)\mathrm{Var}(X_A – X_B) = \mathrm{Var}(X_A) + (-1)^2\,\mathrm{Var}(X_B). The difference is more uncertain than each packet on its own. What is the probability that the old machine’s packet weighs more than the new one’s?

mD <- 1010 - 1004; sD <- sqrt(6^2 + 4^2)
c(mD, sD)
1 - pnorm(0, mD, sD)            # P(XA - XB > 0)
set.seed(2026)                  # checking by simulation
mean(rnorm(1e5, 1010, 6) > rnorm(1e5, 1004, 4))

Output:

[1] 6.000000 7.211103
[1] 0.7973097
[1] 0.79734

How to read it

  • 6.000000 7.211103: the difference has mean 6 g and standard deviation 7.21 g, more than either machine.
  • 0.7973097: in 79.73 % of the pairs, the old machine’s packet is heavier. It is not 100 %, even though its mean is 6 g higher: the bells overlap.
  • The simulation gives 0.79734, practically the same. A hundred thousand pairs of simulated packets with rnorm and the proportion in which the old one wins: that is how you check a paper result with R. With another seed it would differ in the fifth decimal: that is the randomness of simulating.

Computing the standard deviation of the difference as 6−4=26 – 4 = 2, or as 36−16\sqrt{36 – 16}. Subtracting the variables does not subtract their uncertainty: it adds it.

The difference, by hand

Without R, the same question is solved with everything in the topic in four steps:

StepCalculationWhy
1P(XA>XB)=P(XA−XB>0)=P(D>0) P(X_A > X_B) = P(X_A – X_B > 0) = P(D > 0) Comparing two variables means looking at the sign of their difference, and we do know the distribution of the difference
2D∼N(6, 7.21) D \sim N(6,\ 7.21) The means subtract; the variances add: 36+16=52=7.21 \sqrt{36 + 16} = \sqrt{52} = 7.21
3P(Z>0−67.21)=P(Z>−0.83) P\left(Z > \frac{0 – 6}{7.21}\right) = P(Z > -0.83) Standardise: subtract the mean and divide by the standard deviation on both sides
4P(Z>−0.83)=Φ(0.83)=0.7967 P(Z > -0.83) = \Phi(0.83) = 0.7967 Symmetry: what lies to the right of −0.83 -0.83 is what lies to the left of 0.83 0.83

With two decimals, 0.80, the same as pnorm’s 0.7973: the difference in the third decimal is again the rounding of z z , which is really −0.832 -0.832 . Notice that almost every idea in the topic has come up together here: combining normals, standardising and using symmetry for a negative tail.

The mean of n packets

A special case you will see in every remaining topic: if X1,…,XnX_1, \dots, X_n are independent and N(μ,σ)N(\mu, \sigma), their mean is

Xˉ=X1+⋯+Xnn∼N(μ, σn) \bar{X} = \frac{X_1 + \cdots + X_n}{n} \sim N\left(\mu,\ \frac{\sigma}{\sqrt{n}}\right)

It is the sum (nμn\mu, σn\sigma\sqrt{n}) multiplied by 1/n1/n. The mean of 9 packets from the machine is N(1010,2)N(1010, 2): three times more precise than a single packet. In topic 8 this will be the distribution of the sample mean.

R’s d, p, q and r functions

The four letters as always, now with norm and the arguments mean and sd (0 and 1 by default):

R's four letters on the same bellThe filling machine bell. In coral, the peak height at 1010, 0.0665: that is d. In violet, the area left of 1000, 0.0478: that is p. A dashed line at 1017.69 marks the 0.9 quantile: that is q. Green dots on the axis, closer together near 1010: that is r.0.000.020.040.06990100010101017.691030Weight, N(1010, 6)f(x)pd: a heightdnorm(1010, 1010, 6) = 0.0665p: an areapnorm(1000, 1010, 6) = 0.0478q: from area 0.9 to the pointqnorm(0.9, 1010, 6) = 1017.69r: random weightsrnorm(10, 1010, 6)
d measures heights, p measures areas to the left, q undoes p and r simulates weights following the bell.
FunctionWhat it returnsWith the filling machineResult
dnorm(x, mu, sigma)the density f(x)f(x), a heightdnorm(1010, 1010, 6)0.0665
pnorm(x, mu, sigma)F(x)=P(X≤x)F(x) = P(X \le x), an areapnorm(1000, 1010, 6)0.0478
qnorm(p, mu, sigma)the value leaving pp to its leftqnorm(0.9, 1010, 6)1017.69
rnorm(n, mu, sigma)nn simulated valuesrnorm(5, 1010, 6)five random weights

In the drawing, all four on the same bell. Two details that save trouble:

  • The third argument is sd, the standard deviation. If you write the arguments by name (mean = 1010, sd = 6), you cannot get the order wrong and it is clear what each number is.
  • pnorm and qnorm are inverses: qnorm(pnorm(1000, 1010, 6), 1010, 6) returns 1000.

When to use the normal (and when not)

The normal is a good model when the variable is the sum of many small effects, is symmetric and has no limit nearby. Before using it with data, draw the histogram and the quantile-quantile plot (qqnorm), which you will see in the practice.

The variableNormal?Why
The weight of a gofio packetYesmany small effects, symmetric, no limit nearby
The mean weight of 9 packetsYesthe mean of normals is normal (and by the CLT, almost always)
The time until the next customer arrivesNoskewed, starts at 0: exponential (topic 4)
The proportion of a dish that comes out hotNobounded between 0 and 1: beta (topic 4)
The number of faulty packets in a boxNodiscrete: binomial (topic 3)
The marks of a 40-person exam, with many zerosNolimits at 0 and at 10 and a long tail

Data that “look” normal are not proof that they are. In ME2 you will learn to test it; in ME1 the histogram and the quantile-quantile plot are enough, as long as you can explain what you see.

What is proved in this topic

Here you have seen the results. The normal distribution proofs show, step by step, why they are true, with the same filling machine:

ResultProof
The normal density integrates to 1: the Gaussian integral, ∫e−x2/2dx=2π\int e^{-x^2/2}dx = \sqrt{2\pi}Proof 1
Standardising both ways: Z=X−μσZ = \frac{X – \mu}{\sigma} and X=μ+σZX = \mu + \sigma Z (theorem 5)Proof 2
The mgf, the mean and the variance (theorem 6), with the mgf and without itProof 3
Symmetry: median and mode at μ\mu, inflection points at μ±σ\mu \pm \sigmaProof 4
aX+baX + b is normal, with the mgfProof 5
The sum and difference of independent normals, and the mean of nnProof 6

Common mistakes

Putting the variance where the standard deviation goes: pnorm(1000, 1010, 36) instead of pnorm(1000, 1010, 6). It gives 0.39 instead of 0.05.

Computing a right tail without the 1 -. pnorm always returns the area on the left.

Answering with qnorm(0.1) to “the value only 10 % exceed”. What leaves 10 % on the right leaves 90 % on the left: qnorm(0.9).

Adding standard deviations when adding normals, or subtracting them when subtracting. What adds, always, is the variances (and only if the variables are independent).

Reading dnorm(1010, 1010, 6) = 0.0665 as “6.65 % of the packets weigh 1010 g”. It is a height; the probability of an exact value is 0.

Try it in the R playground

Open the site’s R playground (or RStudio) and paste this script. It brings together the bell, the tail of light packets, adjusting the machine and the box of 12:

# The filling machine: X ~ N(1010, 6), in grams
curve(dnorm(x, 1010, 6), from = 985, to = 1035, lwd = 2, ylab = "f(x)")
abline(v = c(1004, 1010, 1016), lty = 2)   # mu - sigma, mu, mu + sigma
pnorm(1000, 1010, 6)                       # packets under 1 kg
qnorm(0.90, 1010, 6)                       # what only 10 % exceed
1000 - qnorm(0.01) * 6                     # mean for 1 % below
# A box of 12 independent packets
box <- replicate(10000, sum(rnorm(12, 1010, 6)))
c(mean(box), sd(box), sqrt(12) * 6)        # the box sd is 6 * sqrt(12)
hist(box, freq = FALSE, breaks = 40)
curve(dnorm(x, 12120, sqrt(12) * 6), add = TRUE, lwd = 2, col = "tomato")

What to look at:

  1. In the first plot, the three lines: the middle one goes through the peak and the other two through the points where the curve changes curvature.
  2. Change the 6 in pnorm to 36 and run it again: it is the 39 % from the beginning. That is how much this mistake weighs.
  3. Change 0.01 to 0.001: how many more grams have to be given away so that only one packet in a thousand falls short?
  4. In the box, compare sd(box) with sqrt(12) * 6: almost equal. Now compare it with 12 * 6, which is what adding standard deviations would give.
  5. Type ?Normal in the console and read the arguments of the four functions in Help; notice that the third one is called sd.

Summary

ConceptFormulaIn R
Densityf(x)=1σ2πe−(x−μ)22σ2f(x) = \frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{(x-\mu)^2}{2\sigma^2}}dnorm(x, mu, sigma)
Distribution functionF(x)=Φ(x−μσ)F(x) = \Phi\left(\frac{x – \mu}{\sigma}\right), no closed formpnorm(x, mu, sigma)
StandardiseZ=X−μσ∼N(0,1)Z = \frac{X – \mu}{\sigma} \sim N(0, 1); X=μ+σZX = \mu + \sigma Z(x - mu) / sigma
Quantilexp=μ+zpσx_p = \mu + z_p \sigmaqnorm(p, mu, sigma)
MomentsE(X)=μE(X) = \mu, Var(X)=σ2\mathrm{Var}(X) = \sigma^2—
mgfeμt+12σ2t2e^{\mu t + \frac{1}{2}\sigma^2 t^2}, for every tt—
Change of scaleaX+b∼N(aμ+b,∣a∣σ)aX + b \sim N(a\mu + b, \lvert a\rvert\sigma)—
Sum or difference of independentsmeans with their sign, variances always added—
68-95-99.7 ruleP(∣X−μ∣≤kσ)P(\lvert X – \mu\rvert \le k\sigma) = 0.6827; 0.9545; 0.9973pnorm(k) - pnorm(-k)

Three ideas to take away:

  1. All normals are the same bell: standardising turns it into the standard one and μ+σZ\mu + \sigma Z brings it back. A probability or a quantile of any normal comes down to Φ\Phi and zpz_p.
  2. R wants the standard deviation. Read the statement twice when you are given a variance, and draw the tail before typing pnorm or qnorm.
  3. The variances of independents add, also when subtracting. That is why a box of 12 packets is only 12\sqrt{12} times more uncertain than a packet, and why the mean of nn narrows with n\sqrt{n}.

If you want to see why all this is true, carry on with the proofs. To do it with R, with 10,000 simulated packets, data from a scale and boxes of 12, there is the normal distribution practice. And to check you have got it, the normal distribution exercises have exam-style exercises with commented solutions.

Next step: proofsThe normal distribution — step-by-step proofs with the Gaussian integral, the mgf and variances that add up (and the mean of −1010 grams)

Did this article help you? Here is how you can support SergioLearns →