Module 2, topic 17, week 9, Tuesday
Probability distributions (normal, binomial, Poisson) and sampling
From single events to whole quantities: random variables with their mean and spread, the binomial, Poisson and normal distributions, z-scores and the normal table, then samples, the standard error and the central limit theorem. Worked by hand.
Introduction: from single events to whole quantities
The fifth lesson of Module 2, and the second one on probability. The last lesson gave a probability to a single event: "the sum of two dice is 7", "the email is spam". Real questions are about a quantity: how many customers will buy, how many calls will come in an hour, how tall a person is, how long a delivery takes. Such a quantity has many possible values, and each value has its own probability. All these probabilities together are a probability distribution. This guide teaches the three distributions that appear most often in data science: the binomial distribution (how many successes in a fixed number of tries), the Poisson distribution (how many events in a period of time) and the normal distribution (the bell curve of measurements). Then it turns to sampling: what happens when we see only a part of the whole, how much a sample can be trusted, and why the average of a large sample is so reliable. Every idea comes as a definition and worked examples calculated by hand. Then the guide walks through 26 solved problems from the easiest to the hardest, and at the end there are 40 practice problems with a hint and a full solution for each.
You need the last lesson (probability rules, combinations , independent events, the expected value) and a calculator with the keys for powers and square roots. As in the whole module, the work is done by hand; Python appears only in one short part near the end.
What you will learn
- 1.What a random variable is, and the difference between discrete and continuous quantities
- 2.A probability distribution as a table, and the cumulative probability "at most"
- 3.The expected value, the variance and the standard deviation of a random variable, and the rules for calculating with them
- 4.The Bernoulli and the binomial distribution: the conditions, the formula, the mean and the spread
- 5.The Poisson distribution for counts in time or space, and how it replaces the binomial for rare events
- 6.Other distributions worth knowing: uniform, geometric, hypergeometric and exponential
- 7.Continuous distributions: a probability as an area under a curve
- 8.The normal distribution, the 68-95-99.7 rule, z-scores and the table of the standard normal distribution
- 9.The normal curve as an approximation of the binomial, and sums of normal quantities
- 10.Populations and samples, the ways of choosing a sample, and bias
- 11.The sampling distribution of the mean, the standard error, the law of large numbers and the central limit theorem
- 12.Where distributions and sampling appear in machine learning
| Written | Meaning |
|---|---|
| , | random variables (quantities whose value depends on chance) |
| the probability that takes the value | |
| the probability that is at most (a cumulative probability) | |
| or | the expected value (the mean) of ; is the Greek letter mu |
| or | the variance of |
| the standard deviation, the square root of the variance; is the Greek letter sigma | |
| , | the number of trials and the probability of success in one trial |
| the average number of events in a period (the Greek letter lambda) | |
| the number | |
| the standard normal variable: mean 0, standard deviation 1 | |
| , the area under the standard normal curve to the left of (the Greek letter phi) | |
| the mean of a sample ("x bar") | |
| the proportion in a sample ("p hat") |
1Why distributions and sampling?
1.1From one event to a whole quantity
A shop owner does not ask "will exactly 12 customers buy today?". The owner asks: how many will buy on a usual day, how much can that number change, and how likely is a very bad day? One probability cannot answer this. A distribution can: it says how likely every possible value is.
The good news is that a few distributions describe most situations. Quantities that arise in the same way have the same distribution, whatever they are about:
| The quantity counts or measures | Examples | Distribution |
|---|---|---|
| successes in a fixed number of independent tries | buyers among 20 visitors, right answers among 10 guesses, defective parts in a box of 50 | binomial |
| events in a period of time or a piece of space | calls in an hour, orders in a minute, typing mistakes on a page | Poisson |
| a measurement that is the sum of many small influences | heights, weights, measurement errors, exam marks | normal |
Learn these three and you can calculate with a large part of the real world.
1.2Why sampling?
We almost never see everything. A company asks 1,000 customers, not all 2 million. A model is trained on the rows that were collected, not on all rows that exist. A test set of 500 photos stands for all photos the model will ever see. A part that stands for the whole is a sample, and the question of this lesson is: how far can a number from a sample be from the true number? The answer, the standard error, is one of the most useful formulas in statistics.
1.3Where you will meet these ideas again
| Later topic | The idea it takes from this lesson |
|---|---|
| Descriptive statistics (Topic 18) | mean, variance and standard deviation, now calculated from data |
| Hypothesis testing (Topic 19) | "how likely is a result like this by chance?": an area under a normal curve |
| Confidence intervals (Topic 20) | the sample mean plus or minus about two standard errors |
| Linear regression | the errors of the model are assumed to follow a normal distribution |
| Logistic regression and classification | every label is a Bernoulli variable with its own |
| Feature scaling | the z-score: the value minus the mean, divided by the standard deviation |
| Random forests and bagging | every tree is trained on a random sample of the rows |
| Neural networks | the weights start as random numbers from a normal distribution; training uses small random samples of the data |
| Model evaluation | an accuracy measured on a test set is a sample proportion and has a standard error |
2Random variables and their distributions
2.1A random variable
A random variable is a quantity whose value depends on the outcome of an experiment. It is written with a capital letter: . Its possible values are written with small letters.
Toss a coin three times. The sample space has 8 equally likely outcomes (last lesson). Let be the number of heads:
| Outcome | HHH | HHT | HTH | THH | HTT | THT | TTH | TTT |
|---|---|---|---|---|---|---|---|---|
| 3 | 2 | 2 | 2 | 1 | 1 | 1 | 0 |
turns every outcome into a number. The event "exactly two heads" is now simply .
2.2Discrete and continuous
| Discrete | Continuous | |
|---|---|---|
| Values | separate values that can be listed: 0, 1, 2, ... | every value in an interval |
| It answers | "how many?" | "how much?", "how long?" |
| Examples | heads in 3 tosses, buyers among 20 visitors, calls in an hour | a height, a waiting time, a temperature |
| Probabilities | every value has its own probability | only intervals have probabilities (Part 7) |
2.3The distribution as a table
The probability distribution of a discrete random variable lists every value with its probability. For the number of heads in three tosses, count the outcomes:
| 0 | 1 | 2 | 3 | |
|---|---|---|---|---|
Two rules hold for every such table, and they are the first check of any calculation:
- every probability lies between 0 and 1
- all probabilities together are exactly 1: here
2.4"At most" and "at least": cumulative probabilities
Many questions ask for a range of values. Add the probabilities of the values in the range.
At most one head:
At least two heads:
At least one head (complement rule):
The probability is called the cumulative probability. Read the words of a problem carefully:
| Words | Meaning |
|---|---|
| at most 2, no more than 2 | |
| fewer than 2, less than 2 | , which is for a count |
| at least 2, 2 or more | |
| more than 2 | , which is for a count |
| between 2 and 5 (inclusive) |
Try it yourself
Show a hint
Show the solution
Answer: and .
The numbers of girls in BB, BG, GB, GG are 0, 1, 1, 2. So the distribution is:
| 0 | 1 | 2 | |
|---|---|---|---|
3The mean, the variance and the standard deviation of a random variable
3.1The expected value
The last lesson ended with the expected value: every value times its probability, added. It is also called the mean of the random variable and written :
For the number of heads in three tosses:
The expected value is the average over a very long run of repetitions. It need not be a possible value: nobody tosses 1.5 heads.
3.2The variance and the standard deviation
Two games can have the same expected value and still feel very different. Game A pays 10 for sure. Game B pays 0 or 20, each with the probability . Both have the mean 10, but only B is risky. We need a number for the spread.
Game A
always 10
Game B
0 or 20, each with the probability 1/2
The variance is the expected squared distance from the mean:
The standard deviation is its square root. It has the same unit as itself (the variance has the unit squared), so it is the number we interpret: a typical distance of a value from the mean.
For the number of heads ():
For the two games: game A has the variance 0 (no spread at all). Game B has , so .
3.3A shortcut for the variance
Squaring the distances is slow. The same variance comes from the expected value of the squares minus the square of the mean:
For the number of heads:
The same result.
Example: one die. Every number from 1 to 6 has the probability .
3.4Rules for calculating
Let and be fixed numbers.
| Rule | In words |
|---|---|
| the mean follows every change of scale and every shift | |
| a shift does not change the spread; a factor multiplies the variance by | |
| of is | the standard deviation is multiplied by the size of |
| means always add | |
| when and are independent | variances add for independent quantities; standard deviations do not add |
| when independent | a difference is as uncertain as a sum: the variances still add |
Example. A temperature has the mean 20 and the standard deviation 5 in degrees Celsius. In Fahrenheit () the mean is and the standard deviation is . The shift 32 changes the mean only.
Example. The sum of two dice. One die has the mean 3.5 and the variance . The dice are independent, so:
That is not : standard deviations do not add.
Try it yourself
Show a hint
Show the solution
Answer: , , . For : mean 7 and variance 18.
The shift moves every value of by the same amount, so it does not appear in the variance.
4The binomial distribution
4.1One trial: the Bernoulli distribution
The simplest random experiment has two outcomes: yes or no, buys or does not buy, spam or not spam. Call one of them "success" and give it the probability . Let be 1 for a success and 0 for a failure. This is a Bernoulli variable:
Every label of a yes-or-no classification problem is a Bernoulli variable.
4.2Many trials: counting the successes
Three visitors come to an online shop. Each one buys with the probability 0.2, independently of the others. Let be the number of buyers. What is ?
Exactly one buyer can happen in three ways (B = buys, N = does not buy):
Every way has the same probability, one factor 0.2 and two factors 0.8, because the visitors are independent (multiplication rule). The number of ways is the number of choices of the one buyer among three visitors: . This is the whole idea of the binomial formula:
- = (the number of ways to place successes) (the probability of one such way)
4.3The binomial formula
has a binomial distribution with trials and success probability when it counts the successes in independent trials that each succeed with the probability . Then, for :
is the number of ways to choose which of the trials are the successes (last lesson, Part 6).
The full table for the three visitors (, ):
| Calculation | |||
|---|---|---|---|
| 0 | 1 | 0.512 | |
| 1 | 3 | 0.384 | |
| 2 | 3 | 0.096 | |
| 3 | 1 | 0.008 |
Check: .
4.4The four conditions
Before you use the formula, check all four:
- The number of trials is fixed in advance.
- Every trial has only two outcomes (success or failure).
- The probability of success is the same in every trial.
- The trials are independent.
| Situation | Binomial? |
|---|---|
| the number of heads in 10 tosses of a coin | yes: , |
| the number of buyers among 20 independent visitors | yes, if every visitor has the same |
| the number of tosses until the first head | no: the number of trials is not fixed (this is the geometric distribution, Part 6) |
| the number of aces among 5 cards dealt from a deck | no: the cards are not put back, so changes from card to card (hypergeometric, Part 6) |
| the number of calls in an hour | no: there are no separate trials (Poisson, Part 5) |
4.5A larger example
Ten visitors come, each buys with the probability 0.2. What is the probability of exactly two buyers?
"At most" and "at least" add single probabilities, or use the complement:
At most one buyer:
At least one buyer:
4.6Mean and spread
A binomial variable is a sum of independent Bernoulli variables, one for each trial. Means add and variances add (Part 3), so:
For ten visitors with : the mean is buyers, the variance is , and . "About 2 buyers, give or take 1."
4.7The shape
n = 10, p = 0.2
mean 2
n = 10, p = 0.5
mean 5
n = 10, p = 0.8
mean 8
With the distribution is symmetric around . With a small the bars pile up on the left and a tail reaches to the right; with a large it is the mirror picture. The highest bar is always near the mean . When grows, the shape comes closer and closer to a bell (Part 10).
Successes in n trials with the probability p. Choose k and the kind of question.
P(X = 2) = C(10, 2) × 0.22 × 0.88 = 0.3020
Mean: n × p = 2. Standard deviation: √(n × p × (1 − p)) = 1.265
C(10, 2) = 45: the number of ways to place 2 successes among 10 trials.
Try it yourself
Show a hint
Show the solution
Answer: , the mean is 3 and .
The four conditions hold: 5 throws, score or miss, the same 0.6 every time, independent throws.
5The Poisson distribution
5.1Counting events in time or space
A help desk receives 4 calls per hour on average. How likely are exactly 2 calls in the next hour? There are no "trials" here: a call can come at any moment. The binomial formula does not fit.
A count has a Poisson distribution with the rate when:
- events happen one at a time,
- they happen independently of each other,
- the average rate is constant: events per period on average.
Then, for (there is no upper limit):
is the base of the natural logarithm; every scientific calculator has a key for . Typical Poisson counts: calls per hour, customers per minute, accidents per month, typing mistakes per page, defects per metre of cable, visits to a web page per second.
Values of that are used in this lesson:
| 0.5 | 1 | 1.5 | 2 | 2.5 | 3 | 4 | 5 | 6 | |
|---|---|---|---|---|---|---|---|---|---|
| 0.6065 | 0.3679 | 0.2231 | 0.1353 | 0.0821 | 0.0498 | 0.0183 | 0.0067 | 0.0025 |
5.2The help desk
With :
At most two calls:
At least one call:
Remember that and , so is simply .
5.3Mean and spread
The mean and the variance are the same number. For the help desk: 4 calls on average, with .
5.4Changing the period
The rate belongs to a period. For another period, scale first, then use the formula.
The help desk has 4 calls per hour. In half an hour the average is ; in three hours it is .
5.5The shape
λ = 1
mean 1
λ = 4
mean 4
λ = 10
mean 10
For a small the distribution leans to the left with a tail to the right. For a larger it becomes more and more symmetric and bell-shaped, around .
Events in a period at the average rate λ. Choose k and the kind of question.
P(X = 2) = 42 × e−4 / 2! = 0.1465
Mean: λ = 4. Standard deviation: √λ = 2
The highest bars are near λ. A count has no upper limit here, so "at least" always goes through the complement.
5.6Poisson instead of binomial: rare events
When is large and is small, the binomial distribution is almost exactly a Poisson distribution with . A usual rule: and (some books say ).
Example. A factory makes 1,000 parts, each defective with the probability 0.002. What is the probability of no defective part?
The two answers agree to three decimals, and the Poisson one needs no thousandth power. This is also why counts of rare events (accidents, defects, clicks on a rarely used button) follow the Poisson distribution: they are binomial counts with a huge and a tiny .
Try it yourself
Show a hint
Show the solution
Answer: and .
6Other discrete distributions worth knowing
The syllabus names three distributions. Three more are so close to them that you should recognise them, because many "is this binomial?" mistakes are really one of these.
6.1The discrete uniform distribution
Every value has the same probability. A fair die is uniform on 1 to 6. Choosing one row of a table of rows at random is uniform on the rows: every row has the probability . This is the distribution behind "at random".
6.2The geometric distribution: waiting for the first success
Repeat independent trials with success probability until the first success. Let be the number of the trial on which it comes. For the first success on trial , the first trials must fail:
The last line is "no success in the first trials".
Example. A seller closes a sale with the probability 0.2 on every call. The probability that the first sale comes on the third call is . On average the first sale comes on call . The probability of no sale in the first ten calls is .
6.3The hypergeometric distribution: sampling without putting back
A box holds 10 parts, 3 of them defective. Four parts are taken out without putting them back. The draws are not independent, so the count of defective parts is not binomial. Count combinations instead (last lesson, Part 6):
In general, with things of which are "special", and taken without putting back:
When the population is much larger than the sample (a usual rule: the sample is at most 5 percent of the population), taking one thing out hardly changes the rest, and the binomial distribution with is a very good approximation. That is why surveys of 1,000 people out of millions are treated as binomial.
6.4Which one?
| Question | Distribution |
|---|---|
| How many successes in independent trials? | binomial |
| How many events in a period, at a known average rate? | Poisson |
| On which trial does the first success come? | geometric |
| How many special things in a sample taken without putting back from a small group? | hypergeometric |
| One of equally likely values? | uniform |
Which distribution is it?
1 of 8
The number of customers who buy among 30 independent visitors, each with the same probability.
Try it yourself
Show a hint
Show the solution
Answer: (a) Poisson, (b) binomial, (c) geometric.
(a) Customers arrive at any moment, at some average rate: a count in a period is a Poisson count. (b) Eight independent bulbs with the same probability 0.05: binomial with and . (c) The number of attempts is not fixed; the counting stops at the first success: geometric with , so on average the test is passed on attempt .
7Continuous distributions
7.1Why a table no longer works
A waiting time can be 3 minutes, 3.2 minutes, 3.2071 minutes: there are infinitely many possible values. If each of them had a positive probability, the sum would be infinite. So for a continuous quantity a single exact value has the probability 0, and only intervals have probabilities: "between 3 and 4 minutes", "more than 10 minutes".
7.2The density curve
A continuous distribution is described by a curve, the probability density. Its two rules replace the two rules of a table:
- the curve never goes below 0
- the whole area under the curve is exactly 1
the filled area
uniform between 0 and 10
Two consequences:
- , so for a continuous quantity and are the same number. (For a count they are not: Part 2.)
- The height of the curve is not a probability. Only areas are.
7.3The continuous uniform distribution
A bus comes every 10 minutes and you arrive at a random moment. Your waiting time is equally likely to be anywhere between 0 and 10 minutes. The density is flat. Because the whole area must be 1, its height is :
For a uniform distribution between and :
For the bus: the mean wait is 5 minutes, the variance is and minutes.
7.4The exponential distribution: the time between events
If events come at the rate per unit of time (a Poisson count), then the waiting time until the next event has the exponential distribution:
The first formula is nothing new: "waiting longer than " means "no event in a period of length ", and that is the Poisson probability of zero events with the rate .
Example. The help desk gets 4 calls per hour. The probability of waiting more than half an hour for the next call is . The mean waiting time is of an hour, 15 minutes.
Try it yourself
Show a hint
Show the solution
Answer: , the mean is 5, and .
: the interval from 4 to 4 has the width 0, so its area is 0. Only intervals have probabilities.
8The normal distribution
8.1The bell curve
Measure the heights of many adults, the weights of bags filled by a machine, or the errors of a measuring instrument, and the picture is always the same: most values lie near the middle, values far from the middle are rare, and the left and the right side look alike. This is the normal distribution.
A normal distribution is fixed by two numbers:
- the mean : where the centre of the bell is,
- the standard deviation : how wide the bell is.
It is written in this lesson. (Some books write the variance in the second place; always check which one a book means.)
- μ = 60, σ = 5
- μ = 70, σ = 5
- μ = 80, σ = 5
The mean moves the bell
- μ = 70, σ = 4
- μ = 70, σ = 8
- μ = 70, σ = 12
The standard deviation makes it narrow or wide
8.2Properties
- The curve is symmetric around . The mean, the middle value (median) and the highest point are the same.
- Half of the area lies to the left of and half to the right.
- The curve never touches the axis, but far from the mean the area is tiny.
- A larger makes the bell lower and wider. The area stays 1.
- It is a continuous distribution: probabilities are areas.
8.3Why it is everywhere
A quantity that is the sum of many small independent influences is approximately normal, whatever the influences look like. A height is the result of many genes and many meals. A measurement error is the sum of many small disturbances. The mean of a large sample is a sum of many observations. This fact is the central limit theorem (Part 12), and it is the reason for the special place of the bell curve.
Not everything is normal. Incomes, prices of flats, waiting times and the numbers of followers have a long tail to the right. Never assume a bell without looking at the data (next lesson).
8.4The 68-95-99.7 rule
For every normal distribution:
- about 68 percent of the values lie within 1 standard deviation of the mean: between and
- about 95 percent of the values lie within 2 standard deviations of the mean: between and
- about 99.7 percent of the values lie within 3 standard deviations of the mean: between and
Example. The marks of an exam are normal with the mean 70 and the standard deviation 10.
- about 68 percent of the students have between 60 and 80 marks
- about 95 percent have between 50 and 90
- about 99.7 percent have between 40 and 100
Symmetry gives more. Outside "50 to 90" are 5 percent of the students, half on each side: about 2.5 percent have more than 90 marks. Between 70 and 80 is half of 68 percent, 34 percent. So about percent have at most 80 marks.
A value more than 3 standard deviations from the mean is very rare (about 3 in 1,000). That is the usual rule for flagging a value as unusual.
Try it yourself
Show a hint
Show the solution
Answer: About 68 percent, about 2.5 percent and about 47.5 percent.
Between and lie about 68 percent. Outside (42 to 58) are 5 percent, half of them above 58: 2.5 percent. Between 42 and 58 are 95 percent, and the half of them to the left of the mean is percent.
9z-scores and the standard normal table
9.1The z-score
The 68-95-99.7 rule works only for whole numbers of standard deviations. For every other value we first ask: how many standard deviations is it away from the mean? That number is the z-score:
For the exam (, ): a mark of 85 has , one and a half standard deviations above the mean. A mark of 62 has . A positive z-score is above the mean, a negative one below, and 0 is the mean itself.
The z-score has no unit. It makes values from different scales comparable (Problem 16), and in machine learning it is the standard way of scaling features.
9.2The standard normal distribution
If is normal with mean and standard deviation , then is normal with the mean 0 and the standard deviation 1. This is the standard normal distribution. So one table is enough for all normal distributions:
is the area under the standard normal curve to the left of .
9.3The table
The row gives to one decimal, the column the second decimal. For go to the row 1.2 and the column .05: .
Φ(1.25) = 0.8944: the area to the left of z = 1.25. To the right: 1 − 0.8944 = 0.1056. For z = −1.25 the two areas change places.
| z | .00 | .01 | .02 | .03 | .04 | .05 | .06 | .07 | .08 | .09 |
|---|---|---|---|---|---|---|---|---|---|---|
| 0.0 | 0.5000 | 0.5040 | 0.5080 | 0.5120 | 0.5160 | 0.5199 | 0.5239 | 0.5279 | 0.5319 | 0.5359 |
| 0.1 | 0.5398 | 0.5438 | 0.5478 | 0.5517 | 0.5557 | 0.5596 | 0.5636 | 0.5675 | 0.5714 | 0.5753 |
| 0.2 | 0.5793 | 0.5832 | 0.5871 | 0.5910 | 0.5948 | 0.5987 | 0.6026 | 0.6064 | 0.6103 | 0.6141 |
| 0.3 | 0.6179 | 0.6217 | 0.6255 | 0.6293 | 0.6331 | 0.6368 | 0.6406 | 0.6443 | 0.6480 | 0.6517 |
| 0.4 | 0.6554 | 0.6591 | 0.6628 | 0.6664 | 0.6700 | 0.6736 | 0.6772 | 0.6808 | 0.6844 | 0.6879 |
| 0.5 | 0.6915 | 0.6950 | 0.6985 | 0.7019 | 0.7054 | 0.7088 | 0.7123 | 0.7157 | 0.7190 | 0.7224 |
| 0.6 | 0.7257 | 0.7291 | 0.7324 | 0.7357 | 0.7389 | 0.7422 | 0.7454 | 0.7486 | 0.7517 | 0.7549 |
| 0.7 | 0.7580 | 0.7611 | 0.7642 | 0.7673 | 0.7704 | 0.7734 | 0.7764 | 0.7794 | 0.7823 | 0.7852 |
| 0.8 | 0.7881 | 0.7910 | 0.7939 | 0.7967 | 0.7995 | 0.8023 | 0.8051 | 0.8078 | 0.8106 | 0.8133 |
| 0.9 | 0.8159 | 0.8186 | 0.8212 | 0.8238 | 0.8264 | 0.8289 | 0.8315 | 0.8340 | 0.8365 | 0.8389 |
| 1.0 | 0.8413 | 0.8438 | 0.8461 | 0.8485 | 0.8508 | 0.8531 | 0.8554 | 0.8577 | 0.8599 | 0.8621 |
| 1.1 | 0.8643 | 0.8665 | 0.8686 | 0.8708 | 0.8729 | 0.8749 | 0.8770 | 0.8790 | 0.8810 | 0.8830 |
| 1.2 | 0.8849 | 0.8869 | 0.8888 | 0.8907 | 0.8925 | 0.8944 | 0.8962 | 0.8980 | 0.8997 | 0.9015 |
| 1.3 | 0.9032 | 0.9049 | 0.9066 | 0.9082 | 0.9099 | 0.9115 | 0.9131 | 0.9147 | 0.9162 | 0.9177 |
| 1.4 | 0.9192 | 0.9207 | 0.9222 | 0.9236 | 0.9251 | 0.9265 | 0.9279 | 0.9292 | 0.9306 | 0.9319 |
| 1.5 | 0.9332 | 0.9345 | 0.9357 | 0.9370 | 0.9382 | 0.9394 | 0.9406 | 0.9418 | 0.9429 | 0.9441 |
| 1.6 | 0.9452 | 0.9463 | 0.9474 | 0.9484 | 0.9495 | 0.9505 | 0.9515 | 0.9525 | 0.9535 | 0.9545 |
| 1.7 | 0.9554 | 0.9564 | 0.9573 | 0.9582 | 0.9591 | 0.9599 | 0.9608 | 0.9616 | 0.9625 | 0.9633 |
| 1.8 | 0.9641 | 0.9649 | 0.9656 | 0.9664 | 0.9671 | 0.9678 | 0.9686 | 0.9693 | 0.9699 | 0.9706 |
| 1.9 | 0.9713 | 0.9719 | 0.9726 | 0.9732 | 0.9738 | 0.9744 | 0.9750 | 0.9756 | 0.9761 | 0.9767 |
| 2.0 | 0.9772 | 0.9778 | 0.9783 | 0.9788 | 0.9793 | 0.9798 | 0.9803 | 0.9808 | 0.9812 | 0.9817 |
| 2.1 | 0.9821 | 0.9826 | 0.9830 | 0.9834 | 0.9838 | 0.9842 | 0.9846 | 0.9850 | 0.9854 | 0.9857 |
| 2.2 | 0.9861 | 0.9864 | 0.9868 | 0.9871 | 0.9875 | 0.9878 | 0.9881 | 0.9884 | 0.9887 | 0.9890 |
| 2.3 | 0.9893 | 0.9896 | 0.9898 | 0.9901 | 0.9904 | 0.9906 | 0.9909 | 0.9911 | 0.9913 | 0.9916 |
| 2.4 | 0.9918 | 0.9920 | 0.9922 | 0.9925 | 0.9927 | 0.9929 | 0.9931 | 0.9932 | 0.9934 | 0.9936 |
| 2.5 | 0.9938 | 0.9940 | 0.9941 | 0.9943 | 0.9945 | 0.9946 | 0.9948 | 0.9949 | 0.9951 | 0.9952 |
| 2.6 | 0.9953 | 0.9955 | 0.9956 | 0.9957 | 0.9959 | 0.9960 | 0.9961 | 0.9962 | 0.9963 | 0.9964 |
| 2.7 | 0.9965 | 0.9966 | 0.9967 | 0.9968 | 0.9969 | 0.9970 | 0.9971 | 0.9972 | 0.9973 | 0.9974 |
| 2.8 | 0.9974 | 0.9975 | 0.9976 | 0.9977 | 0.9977 | 0.9978 | 0.9979 | 0.9979 | 0.9980 | 0.9981 |
| 2.9 | 0.9981 | 0.9982 | 0.9982 | 0.9983 | 0.9984 | 0.9984 | 0.9985 | 0.9985 | 0.9986 | 0.9986 |
| 3.0 | 0.9987 | 0.9987 | 0.9987 | 0.9988 | 0.9988 | 0.9989 | 0.9989 | 0.9989 | 0.9990 | 0.9990 |
For above 3 the area is practically 1.
9.4Three kinds of questions
The table gives areas to the left of a positive . Everything else follows from two facts: the whole area is 1, and the curve is symmetric.
to the left: read the table
to the right: the rest of the area 1
a negative z: the two tails are equal
between: left of b minus left of a
The exam again (, ).
At most 85 marks:
More than 85 marks:
Less than 60 marks (a negative z-score):
Between 60 and 85 marks:
Always draw a small bell and shade the area you want. The sketch tells you whether the answer must be more or less than 0.5, and that catches most mistakes.
A normal quantity X with the mean μ and the standard deviation σ. Move z and see the area.
x = μ + z × σ = 70 + 1.5 × 10 = 85
P(X < 85) = Φ(1.5) = 0.9332
Change μ and σ: the numbers on the axis change, the picture and the probability do not. Every normal distribution is the standard one with other labels.
9.5Backwards: from a probability to a value
"Which mark do the best 10 percent of the students exceed?" Now the area is known and the value is asked for.
- The area to the left of the mark is 0.90.
- Find 0.90 inside the table: the nearest entry is 0.8997, at .
- Turn the z-score back into a mark: .
The step back is the z-score formula solved for :
z-scores that are used again and again:
| Area to the left | 0.80 | 0.90 | 0.95 | 0.975 | 0.99 | 0.995 |
|---|---|---|---|---|---|---|
| 0.84 | 1.28 | 1.645 | 1.96 | 2.33 | 2.576 |
So the middle 95 percent of every normal distribution lies within 1.96 standard deviations of the mean (the "2" of the 68-95-99.7 rule is 1.96 rounded), and the middle 90 percent within 1.645.
Try it yourself
Show a hint
Show the solution
Answer: , and .
10The normal curve as an approximation, and sums
10.1A binomial distribution with a large n
for 100 tosses of a coin would need 41 binomial terms. But for a large the binomial bars form a bell, with the mean and the standard deviation . So areas of the normal curve can replace sums of bars.
The rule: the approximation is good when both and (some books ask for 10).
The continuity correction. A count takes whole values, the normal curve is continuous. The bar of the value 60 reaches from 59.5 to 60.5. So "at least 60" begins at 59.5:
| The count | The normal curve |
|---|---|
| the area to the right of 59.5 | |
| the area to the left of 60.5 | |
| the area between 59.5 and 60.5 |
Example. A coin is tossed 100 times. What is the probability of at least 60 heads?
The exact binomial value is 0.0284. Sixty heads in a hundred tosses would be a surprise: it happens in fewer than 3 of 100 such experiments.
A Poisson distribution with a large (about 10 or more) is also close to a normal curve, with the mean and the standard deviation .
10.2Sums and differences of normal quantities
If and are independent and normal, then and are normal too. Their means add or subtract, and their variances add in both cases (Part 3).
Example. A parcel holds a book and a box. The weight of the book is normal with the mean 200 g and the standard deviation 3 g; the box has the mean 300 g and the standard deviation 4 g. What is the probability that the parcel weighs more than 510 g?
The sum of independent quantities with the same mean and the same standard deviation has the mean and the standard deviation . This returns in the standard error (Part 12).
Try it yourself
Show a hint
Show the solution
Answer: The mean is 18, the standard deviation 3, and the probability is about .
The exact binomial value is 0.0662, so the approximation is close.
11Populations and samples
11.1The words
| Word | Meaning | Example |
|---|---|---|
| Population | all the things we want to know something about | all 2 million customers of a bank |
| Sample | the part of the population that we really observe | the 1,000 customers who were asked |
| Parameter | a number that describes the population; fixed, but usually unknown | the mean income of all customers; the share who would buy |
| Statistic | a number calculated from the sample; it changes from sample to sample | the mean income of the 1,000; the share among them |
The whole of statistics is one move: use a statistic to say something about a parameter. In machine learning the training data is a sample, and "all data the model will ever see" is the population.
11.2How to choose a sample
| Method | How it works | Remark |
|---|---|---|
| Simple random sample | every member has the same chance, like drawing names from a hat | the standard; the formulas of this lesson assume it |
| Systematic sample | every 10th (or k-th) member of a list, from a random start | simple; bad only if the list has a pattern with the same step |
| Stratified sample | split the population into groups (strata) such as cities or age groups, and draw a random sample from every group | every group is represented in the right share |
| Cluster sample | choose whole groups at random (some schools, some streets) and take everyone in them | cheap, but less exact |
| Convenience sample | whoever is easy to reach | not random: usually biased |
A random sample
every member has the same chance
A convenience sample
only those who are easy to reach
11.3Bias
A sample is biased when some members of the population have a smaller chance of being chosen than others, so that the sample differs from the population in a systematic way. A larger sample does not repair bias.
The classic example is real. Before the American election of 1936 the magazine Literary Digest sent out millions of questionnaires and received about 2.4 million answers. It predicted a clear win for the candidate Landon. Roosevelt won by one of the largest margins in history. The addresses had come from telephone books and lists of car owners, and in 1936 those were richer people; and only those who wished to answer did. A sample of 2.4 million was beaten by small polls with better sampling.
Everyday forms of bias:
- Selection bias: asking the visitors of a gym how much the people of a city exercise.
- Non-response bias: only the very satisfied and the very angry customers fill in the survey.
- Survivorship bias: studying only the companies that still exist.
- In machine learning: a model trained on photos taken in daylight is used at night; a model trained on the customers of one city is used in another.
11.4With and without putting back
Sampling with replacement means that a member can be chosen again; the draws are independent. Sampling without replacement means that nobody is chosen twice; that is how real surveys work. When the population is much larger than the sample, the difference does not matter (Part 6), and the simple formulas of the next part hold.
In machine learning both kinds appear. A train and test split takes rows without replacement: no row is in both. A bootstrap sample, used by random forests, takes rows with replacement from rows, so some rows appear several times and others not at all. A stratified split keeps the share of every class the same in the training and the test set, which matters when one class is rare.
Try it yourself
Show a hint
Show the solution
Answer: (a) a convenience sample, (b) a systematic sample, (c) a stratified sample, (d) a statistic.
(a) Only the students who are easy to reach were asked, and they are all from one class: a convenience sample, and probably a biased one. (b) A fixed step through a list from a random start is a systematic sample. (c) The cities are the strata, and every one of them is represented. (d) The number comes from the sample of 50, so it is a statistic. The mean age of all customers is the parameter, and nobody knows it exactly.
12The sampling distribution of the mean
12.1A statistic is a random variable
Take a sample of 25 students and calculate their mean mark. Take another 25 students: the mean is a little different. The sample mean depends on chance, so it is a random variable and has its own distribution. This is the sampling distribution of the mean. Its centre and its spread tell us how good one sample is.
12.2A population small enough to list
A population has only three values: 2, 4 and 6. Its mean and variance:
Draw samples of size 2 with replacement. There are equally likely samples:
| Sample | (2, 2) | (2, 4) | (2, 6) | (4, 2) | (4, 4) | (4, 6) | (6, 2) | (6, 4) | (6, 6) |
|---|---|---|---|---|---|---|---|---|---|
| Mean | 2 | 3 | 4 | 3 | 4 | 5 | 4 | 5 | 6 |
The distribution of the sample mean:
| 2 | 3 | 4 | 5 | 6 | |
|---|---|---|---|---|---|
| Probability |
In the second line the numbers 4, 1, 0, 1, 4 are the squared distances of the means 2, 3, 4, 5, 6 from 4.
Two facts appear, and they hold for every population:
- The sample means are centred on the population mean: .
- Their variance is the population variance divided by the sample size: .
Look also at the shape. The population is flat (each value ), but the means already pile up in the middle.
The population
mean 4, variance 8/3
The means of samples of size 2
mean 4, variance 4/3
12.3The standard error
For a random sample of size from a population with the mean and the standard deviation :
The standard deviation of the sample mean has its own name, the standard error (SE):
It is the typical distance between a sample mean and the true mean. Where it comes from: the sum of observations has the standard deviation (Part 10), and dividing the sum by gives .
The square root has a hard consequence:
| Sample size | 1 | 4 | 16 | 25 | 100 | 400 | 10,000 |
|---|---|---|---|---|---|---|---|
| SE when | 10 | 5 | 2.5 | 2 | 1 | 0.5 | 0.1 |
To halve the error you need four times as much data. To make it ten times smaller you need a hundred times as much. Data gets expensive quickly.
12.4The law of large numbers
As grows, goes to 0: the sample mean comes as close to as we wish. This is the law of large numbers, which the last lesson showed for the share of heads in a long run of tosses.
12.5The central limit theorem
The most important theorem of statistics:
A usual rule: is "large". If the population itself is normal, the statement is exact for every . If the population is very skewed, more than 30 may be needed.
single values
means of 5 values
means of 30 values
The picture shows 20,000 samples from a very skewed population (waiting times with the mean 2, the dashed line). Single values () show the skewed population itself. The means of 5 values are already more symmetric. The means of 30 values form a narrow bell around 2.
Choose a population and a sample size. Draw many samples and watch their means.
No samples yet. Every sample is 5 random values from the population; the picture collects the means of the samples.
Every number from 1 to 6 is equally likely. With n = 1 you see the population itself. With n = 30 the means form a bell around μ, whatever the population looks like.
Example. The marks of all students of a large course have the mean 70 and the standard deviation 10. What is the probability that (a) one student chosen at random has more than 73 marks, (b) the mean of 25 students chosen at random is more than 73? Assume the marks are normal.
(a) One student:
(b) The mean of 25:
A single student above 73 is ordinary (38 percent). A whole group of 25 with a mean above 73 is rare (under 7 percent): single values vary a lot, means vary little. For a question about a mean, divide by the standard error, not by .
Marks with the mean 70 and the standard deviation 10. How often is one student above x, and how often the mean of n students?
- one student
- the mean of 25 students
Standard error: σ / √n = 10 / √25 = 2
One student above 73: z = (73 − 70) / 10 = 0.3, probability 0.3821
The mean of 25 above 73: z = (73 − 70) / 2 = 1.5, probability 0.0668
Single values vary with σ, means vary with σ / √n. Four times as many students give half the standard error.
12.6The sample proportion
"Which share of the customers would buy?" is a question about a proportion. In a sample of people, say yes, and the sample proportion is . is binomial, so dividing its mean and its standard deviation by gives:
For a large sample ( and ), is approximately normal.
Example. 40 percent of all customers prefer the new design. In a random sample of 600 customers, what is the probability that more than 44 percent prefer it?
With 600 people the sample share is almost always within 4 points of the truth (two standard errors). This is why polls of about 1,000 people can speak for millions, if the sample is random.
Try it yourself
Show a hint
Show the solution
Answer: and the probability is .
A sample of 36 is large, so the central limit theorem allows the normal table, whatever the population looks like.
13Distributions and sampling in machine learning
Labels are Bernoulli variables. A classifier does not output "spam". It outputs , the parameter of a Bernoulli distribution for this email. Training a logistic regression or a neural network means finding the values that make the observed labels most probable.
Noise is normal. Linear regression assumes: price = the model's prediction + an error, and the error is normal with the mean 0. Minimising the squared errors, the usual training goal, is exactly what this assumption leads to.
Feature scaling is the z-score. Before training, a column is often replaced by . Every column then has the mean 0 and the standard deviation 1, so that a column in metres and a column of prices in thousands have the same weight.
Outliers. By the 68-95-99.7 rule, a value with a z-score above 3 or below is rare in normal data. A simple and common first check for unusual rows is "is ?".
Weights start as random numbers. A neural network begins with weights drawn from a normal (or uniform) distribution with the mean 0 and a small standard deviation.
Counts are Poisson. Predicting the number of orders per hour or of visits per day uses models built on the Poisson distribution.
A test set is a sample. If a model is right on a share of all possible inputs, then its accuracy measured on test rows is a sample proportion with the standard error . For a true accuracy of 0.90 and 400 test rows:
Measured accuracies between about 0.87 and 0.93 (two standard errors) are all consistent with the same model. A difference of one point between two models on a small test set proves nothing.
Mini-batches are samples. A neural network does not use all rows for every step of training. It uses a random batch, for example 32 rows. The direction computed from the batch is a sample mean, so its noise falls like : a batch four times as large is only twice as exact.
Bootstrap samples. A random forest trains every tree on rows drawn with replacement from the training rows. The probability that one given row is never drawn is
So every tree sees about 63 percent of the rows, and the other 37 percent can be used to test it. For the exact value is .
Try it yourself
Show a hint
Show the solution
Answer: , and the measured accuracy lies between about 0.70 and 0.80.
A measured accuracy of 0.72 and one of 0.78 can come from the very same model. With 300 test rows, differences of a few points are noise.
14Common mistakes
Using the binomial formula without checking the conditions. Cards dealt without putting back, or a number of trials that is not fixed, are not binomial (Part 4).
Forgetting . is the probability of one order of successes and failures. There are orders.
Reading "at least" and "more than" as the same. For a count, "at least 3" is and "more than 3" is .
Not scaling . A rate of 4 per hour is for half an hour and for two hours. Scale first, then calculate.
Adding standard deviations. For independent quantities the variances add: 3 and 4 give , not 7.
Subtracting variances for a difference. . A difference of two uncertain numbers is more uncertain than each of them.
Reading the table for the wrong side. The table gives the area to the left. "More than" needs . A sketch shows which side is meant.
Forgetting the minus sign of a z-score. A value below the mean has a negative z-score, and its area to the left is less than 0.5.
Putting a z-score where a probability belongs. A z-score can be any number; a probability lies between 0 and 1. If a "probability" is 1.5, it is a z-score.
Dividing by in a question about a mean. One value varies with . The mean of values varies with .
Thinking a single value of a continuous quantity has a probability. is 0 for a height. Ask for an interval.
Thinking the central limit theorem makes the data normal. It makes the sample mean approximately normal. The single values keep the shape of the population.
Trusting a large biased sample. Size reduces the random error, never the bias (Part 11).
| Wrong | Right |
|---|---|
| "more than 3" is | "more than 3" is for a count |
| 4 per hour, so for 30 minutes | for 30 minutes |
| of a sum is | for independent quantities |
| z for a sample mean: | |
| four times the data, a quarter of the error | four times the data, half of the error |
15Solved problems (from the easiest to the hardest)
Each problem has the question, the idea behind it with the part of the lesson it uses, and the calculation step by step. Cover the solution and try first.
Level 1: Random variables, binomial and Poisson
Problem 1: Reading a distribution table
The number of cars sold by a dealer in a day has the distribution in the table below. Check that it is a distribution. Find and the expected number of cars.
| 0 | 1 | 2 | 3 | |
|---|---|---|---|---|
| 0.1 | 0.3 | 0.4 | 0.2 |
Idea. The probabilities must add up to 1. A range of values adds probabilities; the expected value is every value times its probability (Parts 2 and 3).
The first line shows that it is a distribution.
Why: 1.7 cars are never sold on one day. Over 100 days the dealer sells about 170.
Problem 2: Variance and standard deviation
A machine makes 0, 1 or 2 defective parts in an hour with the probabilities 0.6, 0.3 and 0.1. Find the mean, the variance and the standard deviation of the number of defective parts.
Idea. Use the shortcut (Part 3).
Why: the square of the mean is subtracted, not the mean. A check with the definition: .
Problem 3: Changing the scale
The number of orders in a day has the mean 3 and the variance 4. Every order brings 50 in profit, and the fixed cost of a day is 20. Find the mean and the standard deviation of the daily profit .
Idea. The rules for (Part 3): the mean follows the whole formula, the spread only the factor.
Or directly: of is .
Why: the fixed cost moves every possible profit down by the same 20. It changes the mean and leaves the spread alone.
Problem 4: One binomial probability
A fair coin is tossed 6 times. What is the probability of exactly 4 heads?
Idea. Binomial with and (Part 4). With every order of heads and tails has the same probability .
Choosing the 2 tails is the same as choosing the 4 heads.
Why: . Always calculate the smaller of the two.
Problem 5: "At least" with a binomial count
A test has 5 questions with 4 answers each, and a student guesses every answer. What is the probability of at least 4 right answers?
Idea. Binomial with and . "At least 4" is 4 or 5 (Parts 2 and 4).
Why: here the direct sum has two terms and the complement would have four. Choose the shorter side. Guessing passes such a test less than twice in a hundred tries.
Problem 6: Mean and spread of a binomial count
200 seeds are planted, and each one grows with the probability 0.9, independently. How many plants are expected, and what is the standard deviation?
Idea. and (Part 4).
Why: "about 180 plants, give or take 4". By the 68-95-99.7 rule (the count is close to a bell, Part 10), fewer than 172 plants would be unusual.
Problem 7: One Poisson probability
A typist makes 2 mistakes per page on average. What is the probability of exactly 3 mistakes on a page?
Idea. A count on a page at a known average rate: Poisson with (Part 5).
Why: there is no number of "trials" on a page, only an average rate. That is the sign of a Poisson count.
Problem 8: "At least" with a Poisson count
An online shop receives 5 orders per hour on average. What is the probability of at least 2 orders in the next hour?
Idea. A Poisson count has no upper limit, so "at least" always goes through the complement (Part 5).
Why: the direct way would add infinitely many terms: 2, 3, 4, ... orders.
Problem 9: A uniform waiting time
A task takes between 10 and 30 minutes, and every time in this interval is equally likely. Find the probability that it takes less than 15 minutes, the mean time and the standard deviation.
Idea. A continuous uniform distribution: a probability is a share of the interval (Part 7).
Why: the density is flat with the height , so the area over an interval is its width divided by 20.
Level 2: The normal distribution
Problem 10: The 68-95-99.7 rule
The lifetime of a battery is normal with the mean 40 hours and the standard deviation 3 hours. Which share of the batteries lasts between 37 and 46 hours?
Idea. 37 is one standard deviation below the mean, and 46 is two above. Use the rule and symmetry (Part 8).
Why: the interval is not symmetric, so it is split at the mean into two halves that the rule knows.
Problem 11: An area to the left
The weights of apples are normal with the mean 150 g and the standard deviation 20 g. What is the probability that an apple weighs less than 176 g?
Idea. Turn the value into a z-score and read the table (Part 9).
Why: 176 is above the mean, so the answer must be more than 0.5. It is.
Problem 12: An area to the right
A delivery takes 30 minutes on average with the standard deviation 5 minutes, normally distributed. What is the probability that a delivery takes more than 38 minutes?
Idea. The table gives the left side; the right side is the rest (Part 9).
Why: about 1 delivery in 18 is this late. A promise "at most 38 minutes" would be broken more than 5 times in 100.
Problem 13: An area between two values
A machine fills bottles with a mean of 500 ml and a standard deviation of 4 ml, normally distributed. What is the probability that a bottle holds between 495 and 507 ml?
Idea. Two z-scores, then the difference of the two left areas (Part 9).
Why: "everything to the left of 507" minus "everything to the left of 495" leaves the strip between them.
Problem 14: A value below the mean
The lifetime of a lamp is normal with the mean 1,200 hours and the standard deviation 100 hours. What is the probability that a lamp fails before 1,080 hours?
Idea. A negative z-score: use the symmetry (Part 9).
Why: the area to the left of is as large as the area to the right of . The answer is less than 0.5, as it must be for a value below the mean.
Problem 15: From a probability back to a value
The monthly salaries in a company are normal with the mean 2,000 and the standard deviation 300. Which salary is exceeded by only 5 percent of the employees?
Idea. The backwards direction: area, then , then (Part 9).
Why: the question gives the area to the right (5 percent). The table works with the left side, so look for 0.95.
Problem 16: Comparing with z-scores
Aysel has 82 marks in mathematics, where the mean is 70 and the standard deviation 8. She has 75 marks in physics, where the mean is 60 and the standard deviation 6. In which subject did she do better compared with the other students?
Idea. Marks from different exams cannot be compared directly. z-scores can (Part 9).
Physics: she is 2.5 standard deviations above the mean there.
Why: the lower mark is the better result, because the physics exam was harder and its marks lie closer together. With the table: , so she is ahead of about 99 percent in physics and of , about 93 percent, in mathematics.
Problem 17: A Poisson count over a longer period
A machine breaks down 0.5 times per week on average. What is the probability of no breakdown in 4 weeks, and of exactly 2 breakdowns in 4 weeks?
Idea. Scale the rate to the period first: (Part 5).
Why: the formula always needs the average number of events in the period that the question is about.
Problem 18: Waiting for the first success
10 percent of the parts of a machine are defective. An inspector checks the parts one by one. What is the probability that the first defective part is the 5th one, and how many parts are checked on average until the first defective one?
Idea. The number of trials is not fixed: this is the geometric distribution (Part 6).
Why: four good parts must come first, then the defective one. There is no , because the order is fixed.
Level 3: Approximations, sums and sampling
Problem 19: The normal curve instead of a binomial sum
400 visitors come to a shop, and each buys with the probability 0.2. What is the probability that more than 90 of them buy?
Idea. and are both large, so the normal approximation with the continuity correction is used (Part 10).
"More than 90" is , which begins at 90.5:
Why: the exact binomial sum has 310 terms and gives 0.0961. The approximation needs one line of the table.
Problem 20: Poisson instead of binomial
A factory makes 2,000 parts in a day, and each one is defective with the probability 0.0015. What is the probability of at most 2 defective parts in a day?
Idea. A large and a tiny : Poisson with (Part 5).
Why: is a common factor of the three terms , and , so it is taken out. The exact binomial value is 0.4230.
Problem 21: The sum of several normal quantities
The weight of an adult is normal with the mean 75 kg and the standard deviation 10 kg. A lift carries 8 adults chosen at random. What is the probability that their total weight is more than 650 kg?
Idea. Means add, variances add (Part 10). The sum of independent normal quantities is normal.
Why: the standard deviation of the sum is , not . Heavy and light people partly cancel each other.
Problem 22: The mean of a sample
A machine fills packets with a mean of 500 g and a standard deviation of 10 g. A sample of 25 packets is weighed. What is the probability that the mean weight of the sample is below 496 g? Assume the weights are normal.
Idea. A question about a mean: use the standard error (Part 12).
Why: a single packet below 496 g is common (, probability 0.3446). A mean of 25 packets below 496 g is rare, and it would be a good reason to check the machine.
Problem 23: How large must the sample be?
The standard deviation of a population is 12. How large must a sample be so that the standard error of the mean is at most 1? And at most 0.5?
Idea. Solve for (Part 12).
Why: half the error costs four times the sample: .
Problem 24: A sample proportion
30 percent of all users click on an advertisement. In a random sample of 2,100 users, what is the probability that the share of clicks lies between 28 and 32 percent?
Idea. The sample proportion is approximately normal with the mean and the standard error (Part 12).
Why: two standard errors on each side: the 95 percent of the 68-95-99.7 rule, here with the exact table value.
Problem 25: A sampling distribution by listing
A population has the three values 1, 2 and 9. List all samples of size 2 drawn with replacement, find the distribution of the sample mean, and check that and .
Idea. The method of Part 12, now for a population that is not symmetric.
| Sample | (1, 1) | (1, 2) | (1, 9) | (2, 1) | (2, 2) | (2, 9) | (9, 1) | (9, 2) | (9, 9) |
|---|---|---|---|---|---|---|---|---|---|
| Mean | 1 | 1.5 | 5 | 1.5 | 2 | 5.5 | 5 | 5.5 | 9 |
The nine means add up to 36, so:
The squared distances of the nine means from 4 are 9, 6.25, 1, 6.25, 4, 2.25, 1, 2.25 and 25. Their sum is 57, so:
The two are equal.
Why: the two facts do not need a symmetric population. They hold for every population.
Problem 26: Normal and binomial together
A machine fills bottles with a mean of 250 ml and a standard deviation of 2 ml, normally distributed. A bottle with less than 246 ml is "underfilled". (a) Which share of the bottles is underfilled? (b) How many underfilled bottles are expected among 1,000? (c) A box holds 20 bottles. What is the probability that it contains at least one underfilled bottle?
Idea. The normal distribution gives the probability for one bottle (Part 9). The number of underfilled bottles in a box is then binomial with this (Part 4).
(a) One bottle:
(b) Among 1,000 bottles:
(c) A box of 20:
Why: a fault that touches only 2 bottles in 100 still appears in more than a third of all boxes. "At least one" grows quickly with the number of tries (last lesson).
16Practice problems
Forty problems in three levels. Solve each one on paper, with the table of Part 9 and the values of of Part 5 next to you, type your result into the answer boxes and press Check. Under every problem there is a hint and a full solution: look at the hint only when you are stuck, and at the solution only after you have an answer of your own. Give probabilities with four decimals unless the problem says something else.
Level 1: Random variables, binomial and Poisson
- 1.A random variable takes the values 1, 2, 3 and 4 with the probabilities 0.4, 0.3, 0.2 and 0.1. Find and .
Show a hint
Every value times its probability, then add.Show one possible solution
Answer: and .
- 2.For the random variable of Problem 1, find the variance and the standard deviation.
Show a hint
First , then subtract the square of the mean.Show one possible solution
Answer: and .
- 3.A random variable takes the values 0, 1, 2 and 3 with the probabilities 0.15, 0.35, and 0.2. Find and .
Show a hint
All probabilities together are 1.Show one possible solution
Answer: and .
- 4. has the mean 4 and the variance 9. Find the mean, the variance and the standard deviation of .
Show a hint
The mean follows the whole formula. The variance is multiplied by the square of the factor.Show one possible solution
Answer: Mean 14, variance 81, standard deviation 9.
The standard deviation also comes directly: .
- 5.A game pays 10 with the probability 0.2, pays 2 with the probability 0.5, and costs 5 (a result of ) with the probability 0.3. Find the expected result and its standard deviation.
Show a hint
For the variance square the values first: .Show one possible solution
Answer: Expected result 1.5, standard deviation about 5.22.
- 6.A fair coin is tossed 5 times. What is the probability of exactly 3 heads?
Show a hint
, and every order has the probability .Show one possible solution
Answer: .
- 7.Four independent customers each buy with the probability 0.3. What is the probability that exactly two of them buy?
Show a hint
Binomial with , , .Show one possible solution
Answer: .
- 8.Each part is defective with the probability 0.1, independently. What is the probability of at least one defective part among 6?
Show a hint
The complement: no defective part.Show one possible solution
Answer: About .
- 9.A fair coin is tossed 400 times. Find the mean and the standard deviation of the number of heads.
Show a hint
and .Show one possible solution
Answer: Mean 200, standard deviation 10.
- 10.Five cards are dealt from a deck of 52 without putting them back, and is the number of hearts. Is binomial with and ?
Show a hint
Check the four conditions. Does the probability of a heart stay the same from card to card?Show one possible solution
Answer: No.
The cards are not put back, so the draws are not independent and the probability of a heart changes after every card (, then or , and so on). The count is hypergeometric. Only with putting back would it be binomial.
- 11. is a Poisson count with . Find and .
Show a hint
.Show one possible solution
Answer: and .
- 12.A shop sells 2.5 laptops per day on average. What is the probability that it sells exactly 2 laptops tomorrow?
Show a hint
Poisson with , and .Show one possible solution
Answer: About .
- 13.A train arrives at a moment that is uniformly distributed between 0 and 60 minutes after the hour. What is the probability that it arrives more than 45 minutes after the hour, and what is the mean arrival time in minutes?
Show a hint
A probability is a share of the interval.Show one possible solution
Answer: , and the mean is 30 minutes.
- 14.A player hits the target with the probability 0.25 on every throw. What is the probability that the first hit comes on the third throw? On which throw does the first hit come on average?
Show a hint
Two misses first, then the hit. The mean of a geometric count is .Show one possible solution
Answer: About ; on average on the 4th throw.
Level 2: The normal distribution
- 15.A test score is normal with the mean 100 and the standard deviation 15. Use the 68-95-99.7 rule: which share of the scores lies between 85 and 115, and which share is above 130?
Show a hint
85 and 115 are one standard deviation from the mean; 130 is two above.Show one possible solution
Answer: About 68 percent, and about 2.5 percent.
Between and lie about 68 percent. Outside (70 to 130) are 5 percent, half of them above 130: 2.5 percent.
- 16.A quantity is normal with the mean 50 and the standard deviation 4. Find the z-score of the value 58 and of the value 45.
Show a hint
.Show one possible solution
Answer: and .
- 17.Find for the standard normal variable.
Show a hint
Row 0.8, column .05.Show one possible solution
Answer: .
, read from the table.
- 18.Find .
Show a hint
The right side is 1 minus the left side.Show one possible solution
Answer: .
- 19.Find .
Show a hint
, and .Show one possible solution
Answer: .
- 20.The time to finish a task is normal with the mean 60 minutes and the standard deviation 5 minutes. What is the probability that a person finishes in less than 53 minutes?
Show a hint
The z-score is negative.Show one possible solution
Answer: .
- 21.The temperature in a room is normal with the mean 25 degrees and the standard deviation 2 degrees. What is the probability of a temperature above 28.5 degrees?
Show a hint
, then the right side.Show one possible solution
Answer: .
- 22.The lifetime of a device is normal with the mean 1,000 hours and the standard deviation 50 hours. What is the probability of a lifetime between 950 and 1,100 hours?
Show a hint
The z-scores are and .Show one possible solution
Answer: .
- 23.Exam marks are normal with the mean 64 and the standard deviation 10. Which mark do the best 20 percent of the students exceed?
Show a hint
The area to the left is 0.80, which belongs to .Show one possible solution
Answer: .
- 24.The weight of a loaf of bread is normal with the mean 300 g and the standard deviation 25 g. Below which weight are the lightest 10 percent of the loaves?
Show a hint
By symmetry the z-score is .Show one possible solution
Answer: g.
The area to the left is 0.10. , so .
- 25.Kamran runs 100 metres in 12.4 seconds; the times of his group have the mean 13 and the standard deviation 0.5. He swims 50 metres in 31 seconds; there the mean is 34 and the standard deviation 2. In which sport is he better compared with his group? (A shorter time is better.)
Show a hint
Compare the z-scores. For times, the more negative one is the better one.Show one possible solution
Answer: Swimming.
In swimming he is 1.5 standard deviations faster than the mean, in running only 1.2.
- 26.Customers arrive at a rate of 6 per hour (Poisson). What is the probability of no customer in 10 minutes, and of exactly 3 customers in 30 minutes?
Show a hint
Scale the rate: for 10 minutes and for 30 minutes.Show one possible solution
Answer: About and .
10 minutes are a sixth of an hour, so :
30 minutes are half an hour, so :
- 27.A fair coin is tossed 8 times. What is the probability of at most 2 heads?
Show a hint
Add , and ; every order has the probability .Show one possible solution
Answer: .
- 28.A test has 12 questions with 4 answers each, and a student guesses all of them. How many right answers are expected, and what is the probability of exactly 3 right answers? Use .
Show a hint
Binomial with and ; .Show one possible solution
Answer: 3 right answers are expected; the probability is about .
Level 3: Approximations, sums and sampling
- 29.A die is rolled 180 times. Use the normal approximation with the continuity correction to find the probability of at least 37 sixes.
Show a hint
and . "At least 37" begins at 36.5.Show one possible solution
Answer: About .
- 30.An insurance company has 500 clients, and each one makes a claim in a month with the probability 0.004. Use the Poisson approximation to find the probability of at least 3 claims in a month.
Show a hint
. Use the complement: 0, 1 or 2 claims.Show one possible solution
Answer: About .
- 31.A job has two independent steps. The first takes a time that is normal with the mean 30 minutes and the standard deviation 4 minutes; the second has the mean 45 and the standard deviation 3. What is the probability that the whole job takes less than 85 minutes?
Show a hint
Means add, variances add: .Show one possible solution
Answer: .
The sum is normal with the mean and the variance , so .
- 32.A population has the mean 120 and the standard deviation 15. A random sample of 36 is taken. What is the probability that the sample mean lies between 117 and 123?
Show a hint
The standard error is .Show one possible solution
Answer: .
- 33.The standard deviation of a population is 20. Find the standard error of the sample mean for samples of size 16, 64 and 400.
Show a hint
.Show one possible solution
Answer: , and .
- 34.The standard deviation of a population is 8. How large must a sample be so that the standard error of the mean is at most 0.5?
Show a hint
Solve for .Show one possible solution
Answer: At least .
- 35.20 percent of all visitors of a site register. In a random sample of 1,600 visitors, what is the probability that fewer than 18.5 percent register?
Show a hint
.Show one possible solution
Answer: .
- 36.A population has the three values 0, 3 and 6. Samples of size 2 are drawn with replacement. Find and .
Show a hint
List the 9 samples and their means.Show one possible solution
Answer: and .
The means of , , , , , , , , are 0, 1.5, 3, 1.5, 3, 4.5, 3, 4.5, 6. Three of the nine are 3, and their sum is 27:
That is the population mean.
- 37.The length of a part is normal with the mean 50 mm and the standard deviation 4 mm. A part is accepted when its length is between 44 and 56 mm. (a) What is the probability that a part is accepted? (b) What is the probability that all 5 parts of a set are accepted?
Show a hint
The z-scores are and . For (b), independent parts multiply.Show one possible solution
Answer: (a) , (b) about .
- 38.Requests reach a server at a rate of 2 per minute (Poisson). What is the probability that the next request comes later than 30 seconds from now, and what is the mean waiting time in minutes?
Show a hint
The waiting time is exponential: with in minutes.Show one possible solution
Answer: About ; the mean wait is half a minute.
Half a minute is 30 seconds.
- 39.A model classifies 80 percent of all inputs correctly. It is tested on 400 random inputs. What is the standard error of the measured accuracy, and what is the probability that the measured accuracy is below 0.75?
Show a hint
The measured accuracy is a sample proportion with and .Show one possible solution
Answer: ; the probability is .
- 40.The weight of a box is normal with the mean 25 kg and the standard deviation 2 kg. A pallet carries 16 boxes. What is the probability that the total weight is more than 410 kg?
Show a hint
The sum of 16 boxes has the mean and the standard deviation .Show one possible solution
Answer: .
The sum is normal with the mean and the standard deviation .
The same question about the mean: with also gives .
17Check yourself
Twelve quick questions. Your answers are saved in this browser, so you can leave the page and continue later. Each finished round is kept as an attempt below the questions; you can delete the attempts at any time.
0 of 12 answered.
18Checking your work with Python
This is the only code of the lesson. Python has the binomial coefficient, and the normal distribution built in, and NumPy can draw samples.
from math import comb, exp, factorial, sqrt
from statistics import NormalDist
import numpy as np
print(round(comb(10, 2) * 0.2**2 * 0.8**8, 4))
print(round(4**2 * exp(-4) / factorial(2), 4))
marks = NormalDist(70, 10)
print(round(NormalDist().cdf(1.5), 4), round(marks.cdf(85), 4))
print(round(marks.inv_cdf(0.90), 1))
rng = np.random.default_rng(1)
means = rng.integers(1, 7, size=(100_000, 30)).mean(axis=1)
print(round(means.mean(), 3), round(means.std(), 3), round(sqrt(35 / 12 / 30), 3))Output
0.302 0.1465 0.9332 0.9332 82.8 3.5 0.313 0.312
Change it and run: change the numbers in the first two lines to those of a problem you solved by hand. Then put another mean and standard deviation into NormalDist, or another sample size instead of 30, and run again.
The first line is the binomial probability of exactly two buyers among ten visitors (Part 4), the second the Poisson probability of exactly two calls (Part 5). The third line prints twice: once for the standard normal variable and once as "at most 85 marks" for the exam, without any table. The fourth line goes backwards: the mark that the best 10 percent exceed. The last lines roll 30 dice 100,000 times and take the mean of every 30. The means are centred on 3.5, and their standard deviation is the standard error , as Part 12 says. (The number 1 in default_rng(1) fixes the random numbers, so that every run gives the same result.)
| By hand | In Python |
|---|---|
math.comb(n, k) | |
math.exp(-lam) | |
statistics.NormalDist().cdf(z) | |
| for a normal | statistics.NormalDist(mu, sigma).cdf(x) |
| from an area back to a value | statistics.NormalDist(mu, sigma).inv_cdf(area) |
| drawing samples | np.random.default_rng() and its methods integers, normal, binomial, poisson, choice |
19Quick summary
| Idea | Definition or rule |
|---|---|
| Random variable | a quantity whose value depends on chance; discrete (counts) or continuous (measurements) |
| Distribution | every value with its probability; all probabilities together are 1 |
| Expected value | : every value times its probability, added |
| Variance | ; the standard deviation is its square root |
| Scale and shift | and |
| Sums | means add; variances add for independent quantities (also for a difference) |
| Bernoulli | one trial: mean , variance |
| Binomial | ; mean , variance |
| Binomial conditions | fixed , two outcomes, the same , independent trials |
| Poisson | ; mean , variance ; scale to the period |
| Poisson for rare events | binomial with a large and a small : |
| Geometric | first success on trial : ; mean |
| Hypergeometric | without putting back: |
| Continuous distribution | a probability is an area under the density curve; a single value has the probability 0 |
| Uniform on to | ; mean , variance |
| Exponential | waiting time at the rate : , mean |
| Normal distribution | the symmetric bell with the centre and the width |
| 68-95-99.7 rule | the shares within 1, 2 and 3 standard deviations of the mean |
| z-score | ; back: |
| Table | is the area to the left; right side ; ; between: |
| Normal for binomial | when and , with the continuity correction of 0.5 |
| Population and sample | the whole and the observed part; a parameter describes the first, a statistic the second |
| Bias | a sample that differs from the population in a systematic way; more data does not repair it |
| Standard error of the mean | |
| Standard error of a proportion | |
| Law of large numbers | the sample mean comes closer and closer to as grows |
| Central limit theorem | for a large the sample mean is approximately normal, whatever the population looks like |