Chapter 6
Joint distributions
Lectures 15–16 · two unknowns at once: joint tables, independence, prediction from one quantity to another, covariance, correlation and sums
So far every model has had one unknown quantity: one count, one waiting time, one height. Most interesting questions involve two or more at once. How tall will a boy grow, given how tall his father is? If a geyser's eruption was long, how long until the next one? Does a second breathalyser reading tell us anything the first didn't? Are hair colour and eye colour connected? Each question asks how two random quantities behave together, and the tool for that is a joint distribution.
Joint distributions serve both of the course's goals. For prediction, they let us use one quantity to predict another: the father's height to predict the son's, the length of an eruption to predict the wait for the next. The best prediction turns out to be a conditional mean, and the way it shrinks towards the average is Galton's regression to the mean, seen at last through the mathematics. For inference, joint distributions describe how quantities are connected. Covariance and correlation measure the connection, and independence is the special case of no connection at all. But a connection in the data is not yet a cause, and this chapter keeps asking what produced the association.
Here is the route through the chapter.
- Section 6.1 describes two random variables at once, with joint tables and joint densities.
- Section 6.2 recovers each variable on its own (marginal distributions), and one given the other (conditional distributions).
- Section 6.3 defines independence, the assumption behind most of the models so far.
- Section 6.4 uses conditional expectation to predict one quantity from another.
- Section 6.5 measures association with covariance and correlation.
- Section 6.6 finds the mean and spread of sums and averages, which is the bridge to Chapters 7 to 9.
The calculus you need is double integrals over rectangles and simple regions (Section 0.4).
Think About It: Before You Start
A man is 6 ft 3 in tall, about 6 inches above the average for men. How tall would you predict his adult son will be: 6 inches above average, the average, or something in between? Write down a number before reading on. Example 6.9 answers it with Galton's data.
Something in between, and closer to the average than most people guess. Height is partly inherited, so the son of a tall father is likely to be tall. But the father's own height was partly luck: genes from his parents that he won't necessarily pass on, and a good childhood that his son may or may not share. The son gets only part of that advantage. In Galton's data, sons of fathers about 4 inches above average were only about 2 inches above average themselves. This is regression to the mean, and Section 6.4 shows exactly where it comes from.
Lecture 15 — Joint, marginal and conditional distributions
6.1 Joint distributions
Two variables in one table
When two random variables are discrete, their joint behaviour fits in a table: one row for each value of the first, one column for each value of the second, and the probability of each combination in the cell.
Definition: Joint PMF
The joint probability mass function of discrete random variables and is It satisfies and
The comma in
Example 6.1: Hair and Eye Colour ★ lecture example
In 1974 the statistician R. D. Snee reported the hair and eye colour of 592 statistics students at the University of Delaware. Pick one of these students at random, and let be their hair colour and their eye colour. (a) Find the joint PMF of and . (b) What is the probability that the student is blond with blue eyes? (c) What is the probability that their eyes are blue or green?
(a) From counts to probabilities. R's HairEyeColor table also splits the students by sex (a split added later, artificially, for teaching purposes); adding over sex recovers Snee's counts, and dividing by 592 gives the joint PMF:
he <- apply(HairEyeColor, c(1, 2), sum) # add over the third dimension (sex)
he
round(he / sum(he), 3) # joint PMF
Eye
Hair Brown Blue Hazel Green
Black 68 20 15 5
Brown 119 84 54 29
Red 26 17 14 14
Blond 7 94 10 16
Eye
Hair Brown Blue Hazel Green
Black 0.115 0.034 0.025 0.008
Brown 0.201 0.142 0.091 0.049
Red 0.044 0.029 0.024 0.024
Blond 0.012 0.159 0.017 0.027
| hair \ eyes | brown | blue | hazel | green |
|---|---|---|---|---|
| black | 0.115 | 0.034 | 0.025 | 0.008 |
| brown | 0.201 | 0.142 | 0.091 | 0.049 |
| red | 0.044 | 0.029 | 0.024 | 0.024 |
| blond | 0.012 | 0.159 | 0.017 | 0.027 |
All 16 entries are at least 0, and they add to 1 (up to rounding).
(b) Read one cell:
(c) Add the cells in the event. "Blue or green eyes" is the blue and green columns together, eight cells. The blue column holds
Picture. A tile plot shows the whole joint distribution at once: each tile's shade is its probability.
d <- as.data.frame(as.table(he / sum(he)))
names(d) <- c("hair", "eye", "p")
ggplot(d, aes(eye, hair, alpha = p)) + geom_tile(fill = "steelblue", colour = "white") +
geom_text(aes(label = sprintf("%.3f", p)), alpha = 1) +
scale_alpha(range = c(0.05, 0.6), guide = "none") +
labs(x = "eye colour", y = "hair colour")
Blond hair goes with blue eyes far more often than with brown. The two variables seem connected, and Section 6.3 makes "connected" precise.
Data: R. D. Snee (1974), "Graphical display of two-way contingency tables", The American Statistician 28, 9–12; R's HairEyeColor.
Two continuous variables: joint densities
For two continuous random variables, probability is spread over the plane, and a joint density describes how thickly. In Chapter 5, probability was an area under a curve; now it is a volume under a surface.
Definition: Joint Density
Continuous random variables and have joint density if ,
As in one dimension, single points (and single lines) have probability zero, and is not itself a probability: it is probability per unit area.
Example 6.2: The Shooting-Range Target ★ lecture example
A forensic team test-fires a weapon at a square target 1 metre on each side. Measured from the bottom-left corner, the horizontal and vertical positions of an impact, and , have joint density
(a) Non-negative: on the square. Total volume 1: integrate over first, holding fixed, then over :
(b) The density is largest where is largest: at the top-right corner , where , and smallest at the bottom-left corner, where . Shots drift up and to the right, perhaps because of how the weapon was held.
(c) Integrate over the small square:
f <- function(x, y) 6/5 * (x + y^2)
inner <- function(x) sapply(x, function(xx) integrate(function(y) f(xx, y), 0.75, 1)$value)
integrate(inner, 0.75, 1)
0.1234375 with absolute error < 1.4e-15
Check Yourself
In Example 6.1, find the probability that a randomly chosen student has red hair and eyes that are not brown. The red-haired students' eye colours are 26 brown, 17 blue, 14 hazel and 14 green. Give 4 decimal places.
Add the three red-hair cells for blue, hazel and green eyes, then divide by 592.
What is the probability of a single point for continuous random variables?
A probability can't exceed 1. What kind of quantity is ?
A joint density is probability per unit area, like a density in Chapter 5 is probability per unit length. It can exceed 1; only its total volume must equal 1.
Think About It: Whose Table Is It?
The hair and eye colour data came from 592 statistics students at one American university in the 1970s. Would you use this joint PMF to predict the eye colour of a blond person in Lagos, or in Stockholm? What kinds of question could these data answer?
No. The joint distribution describes this population: mostly young Americans of European descent, at one university, in one decade. Hair and eye colour vary enormously between populations, so in Lagos or Stockholm the table would look completely different. A probability model is always a model of some population, and predictions travel only as far as the population does. The data can answer questions about that group, and they can illustrate a real biological link: some of the same genes affect both hair and eye pigment. But to estimate how common blue eyes are anywhere else, you'd need data from there.
Key Takeaways
- A joint PMF
lists the probability of every combination; probabilities of events are sums of cells. - A joint density spreads probability over the plane; probabilities are volumes, .
- Integrate one variable at a time: hold fixed, integrate over , then integrate over .
6.2 Marginal and conditional distributions
Marginals: one variable at a time
The joint distribution contains everything about and , including the distribution of each one on its own. To find , add up every way it can happen: together with each possible value of . In a table, that's a row sum, written in the margin, which is where the name comes from.
Definition: Marginal Distributions
If and have joint PMF , the marginal PMFs are
This is the Law of Total Probability (Section 3.6) at work: the events split the sample space into pieces, and is the sum over the pieces.
Conditionals: one variable given the other
If we learn the value of , our probabilities for change. Conditional probability (Section 3.5) says how: restrict attention to the row or column we now know we're in, and rescale it so it adds to 1.
Definition: Conditional Distributions
For discrete and , the conditional PMF of given (for any with ) is
For each fixed , the conditional distribution is a genuine distribution in : it's non-negative and adds (or integrates) to 1, because we divided by exactly the total of that slice. Geometrically, a conditional density is a slice of the joint density surface along the line , rescaled to have area 1.
Example 6.3: What Colour Are a Blond Student's Eyes? ★ lecture example
Using Snee's students from Example 6.1: (a) find the marginal distributions of hair colour and of eye colour; (b) find the conditional distribution of eye colour given blond hair; (c) find . Compare (b) and (c) with the marginal probabilities.
(a) Row and column totals. The marginal of is the row sums, and the marginal of is the column sums, of the joint table:
round(rowSums(he) / sum(he), 3) # marginal of hair colour
round(colSums(he) / sum(he), 3) # marginal of eye colour
Black Brown Red Blond
0.182 0.483 0.120 0.215
Brown Blue Hazel Green
0.372 0.363 0.157 0.108
| hair | black | brown | red | blond |
|---|---|---|---|---|
| 0.182 | 0.483 | 0.120 | 0.215 |
| eyes | brown | blue | hazel | green |
|---|---|---|---|---|
| 0.372 | 0.363 | 0.157 | 0.108 |
(b) Restrict to the blond row and rescale. There are 127 blond students, and their eye colours are 7 brown, 94 blue, 10 hazel and 16 green:
round(prop.table(he, 1), 3) # each row divided by its total
Eye
Hair Brown Blue Hazel Green
Black 0.630 0.185 0.139 0.046
Brown 0.416 0.294 0.189 0.101
Red 0.366 0.239 0.197 0.197
Blond 0.055 0.740 0.079 0.126
(c) Now restrict to a column. Of the 215 blue-eyed students, 94 are blond:
Comparing. Overall, 36% of students have blue eyes, but among blond students it's 74%. Overall 21.5% are blond, but among the blue-eyed it's 44%. Notice that
d <- as.data.frame(as.table(prop.table(he, 1)))
names(d) <- c("hair", "eye", "p")
ggplot(d, aes(eye, p)) + geom_col(width = 0.6) + facet_wrap(~ hair, nrow = 1) +
labs(x = "eye colour", y = "Pr(eye | hair)") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
Example 6.4: The Target's Margins and Slices
For the shooting-range target of Example 6.2, with
(a) Integrate out the other variable. For , integrate over from 0 to 1:
(b) Slice and rescale. The conditional density of given is
Example 6.5: The Dart's Horizontal Position ★ lecture example
Return to the dart of Example 5.2, landing uniformly at random on a round board of radius 1. Put the origin at the bullseye, so the landing point has joint density on the disc . (a) Find the marginal density of , the dart's horizontal position. (b) What is the probability that the dart lands within half a foot of the vertical centre line, ? (c) Given that the dart's height is , what is the conditional distribution of ?
(a) Integrate out , minding the boundary. For a fixed between and 1, the disc extends vertically from
(b) Integrate the marginal (R does it numerically):
integrate(function(x) 2 / pi * sqrt(1 - x^2), -0.5, 0.5)
0.6089978 with absolute error < 6.8e-15
The vertical strip is half the board's width but holds 61% of its area.
(c) Slice at height . For , the marginal of is
Simulation check. Throw 20,000 random darts (keeping points in the square that fall inside the disc) and compare the histogram of with the semicircle:
set.seed(6)
x <- runif(20000, -1, 1); y <- runif(20000, -1, 1)
keep <- x^2 + y^2 <= 1
darts <- data.frame(x = x[keep], y = y[keep])
ggplot(darts, aes(x)) +
geom_histogram(aes(y = after_stat(density)), binwidth = 0.1, boundary = 0, colour = "white") +
stat_function(fun = function(x) 2 / pi * sqrt(1 - x^2), linewidth = 1) +
labs(x = "horizontal position X", y = "density")
mean(abs(darts$x) <= 0.5)
[1] 0.6137667
Check Yourself
Using Snee's data, find . There are 108 black-haired students, 68 of them with brown eyes. Give 3 decimal places.
Restrict to the black-hair row and divide by its total.
Do the cells in other rows still matter once we know ?
The column totals mix together all values of . Is that what we want after learning ?
Knowing restricts us to that row. Dividing by the row total, , makes the row add to 1.
Think About It: Who Is in the Denominator?
A news story says: "70% of people arrested for burglary in our city were unemployed." A politician concludes that unemployed people are very likely to commit burglary. Write both statements as conditional probabilities. Which one does the story actually report, and what extra information would you need to get the other?
The story reports
Key Takeaways
- Marginals: sum or integrate out the other variable,
or . - Conditionals: slice and rescale,
; the same with densities. - Mind the boundaries of the region where : they set the limits of integration.
in general: always check which variable is being conditioned on.
6.3 Independence
Two events are independent if learning that one happened doesn't change the probability of the other (Section 3.5). Two random variables are independent if learning the value of one doesn't change the distribution of the other: every conditional distribution equals the marginal. That's equivalent to the joint distribution factorizing.
Definition: Independent Random Variables
Random variables and are independent if (discrete), or (continuous). Equivalently,
To show dependence, one counterexample is enough: a single pair where the joint isn't the product of the marginals. To show independence, the factorization must hold everywhere.
- Hair and eye colour are dependent.
, but . Blond, blue-eyed students are about twice as common as independence would predict. - The target is dependent.
isn't a product of a function of and a function of : for example, , but . - The dart is dependent. Near the corner , outside the disc, the joint density is 0, but both marginals are positive at 0.9. A quick test: if the region where isn't a rectangle (with sides parallel to the axes), the variables can't be independent, because knowing one restricts the range of the other.
Watch Out: Pairwise Isn't Mutual
Mutual independence of implies that every pair is independent, but not the other way round. Toss two fair coins, let and be 1 for heads and 0 for tails, and let if the coins match. Each pair of , , is independent (check that
Example 6.6: Who Wins the Match? ★ lecture example
In English Premier League football, home teams have scored about 1.5 goals per game on average and away teams about 1.2. A simple model says the home goals and the away goals are independent. Under this model: (a) find the probability that the match ends 1–1; (b) find the probabilities of a home win, a draw and an away win. (c) Is independence a reasonable assumption?
(a) Independence turns the joint PMF into a product:
(b) Add the cells in each event. A home win is every cell with , a draw is the diagonal , and an away win is . There are infinitely many cells, but those with more than 10 goals for either side have negligible probability, so an 11-by-11 table is plenty:
P <- outer(dpois(0:10, 1.5), dpois(0:10, 1.2)) # joint PMF: rows = home goals, columns = away
round(P[1:4, 1:4], 3) # the top-left corner of the table
c(home = sum(P[lower.tri(P)]), draw = sum(diag(P)), away = sum(P[upper.tri(P)]))
[,1] [,2] [,3] [,4]
[1,] 0.067 0.081 0.048 0.019
[2,] 0.101 0.121 0.073 0.029
[3,] 0.076 0.091 0.054 0.022
[4,] 0.038 0.045 0.027 0.011
home draw away
0.4414646 0.2548168 0.3037180
The model gives a home win 44%, a draw 25% and an away win 30%. That's close to the real long-run figures in the Premier League, where home teams have won a little under half of all matches and about a quarter have been drawn.
d <- expand.grid(home = 0:5, away = 0:5)
d$p <- dpois(d$home, 1.5) * dpois(d$away, 1.2)
d$result <- ifelse(d$home > d$away, "home win", ifelse(d$home == d$away, "draw", "away win"))
ggplot(d, aes(away, home, fill = result, alpha = p)) + geom_tile(colour = "white") +
geom_text(aes(label = sprintf("%.3f", p)), alpha = 1, size = 3.8) +
scale_fill_manual(values = c("orange", "grey60", "steelblue")) +
scale_alpha(range = c(0.1, 0.6), guide = "none") +
labs(x = "away goals", y = "home goals", fill = NULL)
(c) Critical thinking. Independence is a modelling assumption, and in football it's only roughly true. The score affects how teams play: a team that's losing attacks, which can produce goals at both ends, and teams that are level late on may settle for a draw. Statisticians who model football (most famously Mark Dixon and Stuart Coles, in 1997) found that independent Poisson models slightly underpredict low-scoring draws such as 0–0 and 1–1, and they added a small correction for this dependence. A model can be useful even when an assumption is a little wrong, as long as we check its predictions against data.
Here's a continuous example, where independence makes a double integral easy.
Example 6.7: Police or Fire First? ★ lecture example
A small town's emergency dispatcher receives police calls at random at 4 per hour and fire calls at random at 1 per hour, independently. Let be the time (in hours) until the first police call and the time until the first fire call, so and are independent (Section 5.4). (a) What is the probability that a police call comes first? (b) What is the distribution of the time
(a) Integrate the joint density over the region . By independence,
(b) The minimum is bigger than exactly when both are. By independence,
(c)
set.seed(6)
x <- rexp(100000, rate = 4); y <- rexp(100000, rate = 1)
mean(x < y) # close to 0.8
mean(pmin(x, y)) * 60 # close to 12 minutes
mean(pmin(x, y) > 0.5) # close to 0.082
[1] 0.79983
[1] 11.95805
[1] 0.08009
This is a basic fact about Poisson processes: two independent streams of random events merge into a single stream whose rate is the sum, and each event belongs to the first stream with probability .
The calculation in (a) is a volume over a region. The contours below show the joint density , highest near the origin; the shaded region above the diagonal, where , holds 80% of the probability, because police calls are four times as frequent and so usually come first.
g <- expand.grid(x = seq(0, 1.2, length.out = 121), y = seq(0, 1.2, length.out = 121))
g$f <- 4 * exp(-4 * g$x) * exp(-g$y)
ggplot(g, aes(x, y)) +
geom_polygon(data = data.frame(x = c(0, 1.2, 0), y = c(0, 1.2, 1.2)), fill = "orange", alpha = 0.25) +
geom_contour(aes(z = f), colour = "steelblue", bins = 10) +
geom_abline(slope = 1, intercept = 0, linetype = "dashed") +
annotate("text", x = 0.74, y = 1.12, label = "police first (x < y): 0.8") +
annotate("text", x = 0.9, y = 0.3, label = "fire first: 0.2") +
coord_equal() + labs(x = "x: time to first police call (hours)", y = "y: time to first fire call (hours)")
Check Yourself
Can you write as a function of times a function of ?
Factorization of the joint density settles the question directly.
In Example 6.7, what is the probability that the first call is a fire call?
Use
, the complement of 0.8.
Think About It: Independence Is a Claim About the World
Each of these models assumes independence. For each, say whether you believe it and what could create dependence: (a) the results of 10 coin tosses; (b) whether each of 10 houses on a street floods this year; (c) whether each of the 12 jurors on a jury votes "guilty"; (d) the DNA profiles of two people chosen at random from a city.
(a) Believable: coins have no memory and don't influence each other. (b) No: the houses share a river, a storm and a drainage system, so one flooding makes the others much more likely to flood. Insurers who treat neighbouring houses as independent badly underestimate the chance of many claims at once. (c) No: jurors deliberate together and influence each other, and they all saw the same evidence. (d) Roughly, for strangers, but not for relatives or people from small, closely related communities, who share DNA from common ancestors. That matters when a DNA match is reported as "1 in a billion": the calculation multiplies probabilities across many genetic markers, assuming independence, and it can be badly wrong for a suspect's brother. Sally Clark's case (Section 3.6) is the most famous example of a false independence assumption in court.
Key Takeaways
- and are independent when the joint PMF or density factorizes into the marginals; then every conditional distribution equals the marginal.
- One cell where joint product of marginals proves dependence. A non-rectangular region where means dependence.
- With independence, joint probabilities are products, which makes many calculations easy. But independence is an assumption about the mechanism, and it should be checked.
- Mutual independence implies pairwise independence, not the reverse.
Lecture 16 — Prediction, covariance and sums
6.4 Expected values and prediction
Expected values of functions of two variables
Expected values work just as in Chapters 4 and 5: weight each possible value by its probability. The only change is that the possible values are now pairs.
Theorem: Expected Value of a Function of X and Y
For any function ,
Two consequences are used constantly.
Theorem: Linearity, and Products of Independent Variables
- For any random variables and and constants , , :
. No independence is needed. - If and are independent, then
, and more generally .
We give the discrete case; for densities, replace sums by integrals.
(1) With
(2) If
For the football model of Example 6.6, linearity gives the expected total goals,
Conditional expectation: the best prediction
If we know , the distribution of is its conditional distribution given , and that distribution has its own mean.
Definition: Conditional Expectation
The conditional expectation of given is the mean of the conditional distribution:
Why does it matter? Because it's the best possible prediction of from , in the same sense that the mean was the best single guess in Chapters 2 and 4.
Theorem: The Conditional Mean Is the Best Predictor
Suppose we predict by a number , after learning that , and the loss is the squared error . The expected loss, , is smallest when
Write
So prediction from one variable to another is a matter of conditional means, and the conditional variance measures how far off the prediction will typically be. If we know nothing about , the best guess is the overall mean , and the two are linked by a useful rule.
Theorem: Law of Total Expectation
In the discrete case,
Example 6.8: When Will Old Faithful Erupt Again?
Of the 272 eruptions in R's faithful data (Example 2.1), 97 lasted 3 minutes or less and 175 lasted longer. After a short eruption the average wait for the next was 54.5 minutes (SD 5.8); after a long one it was 80.0 minutes (SD 6.0). (a) Find the overall average wait using the law of total expectation. (b) A park ranger posts a prediction of the next eruption. How much better is a prediction that uses the length of the last eruption than one that ignores it?
(a) Let indicate a long eruption, with
(b) Compare typical prediction errors. Ignoring the last eruption, the best prediction is 70.9 minutes, and the typical error is the overall SD of the waits, about 13.6 minutes. Using it, the ranger predicts 54.5 or 80.0 minutes, and the typical error is the conditional SD, about 6 minutes. Knowing one variable has cut the prediction error by more than half.
long <- faithful$eruptions > 3
tapply(faithful$waiting, long, mean) # conditional means
tapply(faithful$waiting, long, sd) # conditional SDs
sd(faithful$waiting) # unconditional SD
FALSE TRUE
54.49485 79.98857
FALSE TRUE
5.840098 5.994239
[1] 13.59497
This is what Yellowstone's rangers actually do: the posted prediction depends on the duration of the previous eruption. A prediction based on a conditional mean is only as good as the conditional spread around it, which is why the posted time comes with a window of about 10 minutes either way.
Example 6.9: Tall Fathers, Slightly Less Tall Sons ★ lecture example
Galton's data (Example 5.1) include the heights of 481 sons and of their fathers. (a) Estimate by averaging sons' heights for fathers in bands of height. (b) Fathers at least 72 inches tall averaged 73.1 inches. How tall were their sons on average? (c) What about the sons of fathers at most 66 inches tall? Explain the pattern.
(a) Group the fathers and average the sons in each group. Each group mean estimates the conditional mean for fathers of that height:
galton <- read.csv("https://raw.githubusercontent.com/vincentarelbundock/Rdatasets/master/csv/HistData/GaltonFamilies.csv")
sons <- subset(galton, gender == "male")
band <- cut(sons$father, breaks = c(61, 64, 66, 68, 70, 72, 74, 79))
data.frame(n = as.vector(table(band)), son_mean = round(tapply(sons$childHeight, band, mean), 1))
n son_mean
(61,64] 8 67.4
(64,66] 55 67.6
(66,68] 100 68.2
(68,70] 179 69.4
(70,72] 104 70.3
(72,74] 26 71.2
(74,79] 9 70.9
means <- data.frame(father = tapply(sons$father, band, mean),
son = tapply(sons$childHeight, band, mean))
ggplot(sons, aes(father, childHeight)) +
geom_jitter(width = 0.1, height = 0.1, alpha = 0.4, colour = "steelblue") +
geom_abline(slope = 1, intercept = 0, linetype = "dashed") +
geom_smooth(method = "lm", se = FALSE, colour = "black", linewidth = 0.8) +
geom_point(data = means, aes(father, son), colour = "orange", size = 4) +
labs(x = "father's height (inches)", y = "son's height (inches)")
`geom_smooth()` using formula = 'y ~ x'
The conditional means rise with the father's height, roughly along a straight line,
(b) and (c) Compare distances from the average. The average father was 69.1 inches and the average son 69.2.
| fathers | number | fathers' mean | sons' mean |
|---|---|---|---|
| 72 in or more | 55 | 73.1 (+4.0) | 71.0 (+1.8) |
| 66 in or less | 63 | 65.3 (−3.8) | 67.6 (−1.7) |
The numbers in brackets are distances from the average father or son.
tall <- sons$father >= 72; short <- sons$father <= 66
c(mean(sons$father[tall]), mean(sons$childHeight[tall]))
c(mean(sons$father[short]), mean(sons$childHeight[short]))
[1] 73.11091 71.02545
[1] 65.31746 67.56825
Sons of tall fathers were tall, but less than half as far above average as their fathers; sons of short fathers were short, but closer to average. This is regression to the mean (Section 4.7), and Galton described it for human height using exactly these data, in 1886 (he had first seen it in the seeds of sweet peas). It doesn't mean that heights are converging and everyone will one day be the same height: the spread of the sons' heights (SD 2.6) is at least as large as the fathers' (2.3). The tall sons of the next generation come partly from fathers of average height who were lucky in the genes and environment they passed on.
Prediction. For a father 75 inches tall (6 ft 3 in, the man in "before you start"), the fitted line (with unrounded coefficients,
Caveat. Brothers share a father, so the 481 sons aren't independent observations; the estimates are fine, but Chapter 8's margins of error would need adjusting.
Causal Inference: Why Do Sons Regress?
Regression to the mean isn't a force pulling people towards the average. It happens whenever two quantities are imperfectly related, and the DAG shows why for heights. A father's height doesn't cause his son's height. Both are caused by shared influences (genes, and the family's food, money and health) and by influences that aren't shared (the half of the son's genes that come from his mother, and his own childhood). Only the shared part carries over. A father who is very tall was probably helped by both the shared and the unshared influences, and the son inherits only the first.
Galton himself read the regression in genetic terms, and used it to argue that "ability" was inherited (the history box after Example 5.6). The DAG shows why that inference was too quick: the data can't separate genes from family resources, because both arrows point the same way. Disentangling them took twin and adoption studies, decades later.
Check Yourself
Using the fitted line with unrounded coefficients,
Substitute 75 for the father's height.
Should the spread of waits be the same before and after we learn something relevant?
If they were independent, would the conditional means differ so much?
Conditioning on a related variable shrinks the spread around the prediction. The smaller conditional SD is the typical size of the prediction error once we know the eruption length.
Think About It: The Sophomore Slump
In many sports, the "Rookie of the Year" usually does worse in their second season, and athletes on the cover of Sports Illustrated often have a bad run afterwards (the "cover jinx"). Explain both using regression to the mean. Then design a comparison that would tell you whether the cover really causes bad performance.
An athlete becomes Rookie of the Year, or makes the cover, after an exceptional period: real skill plus some good luck. Next season the skill remains, but the luck is fresh, and on average it's ordinary, so performance usually drops towards the athlete's true level. No jinx is needed. To test for a real cover effect, compare cover athletes with athletes who had equally exceptional runs but didn't make the cover (perhaps because another story took the slot that week). If both groups decline by the same amount, the decline is regression to the mean. This is the same logic as the police hot-spots example in Section 4.7: when units are selected because they were extreme, you need a comparison group selected the same way.
Key Takeaways
or . Linearity always holds; needs independence. - The conditional mean is the best prediction of from under squared loss; the conditional variance is its expected squared error.
- Law of total expectation: is the average of the conditional means, weighted by .
- When two quantities are imperfectly related, predictions regress to the mean.
6.5 Covariance and correlation
Covariance
We often want a single number saying how strongly two quantities move together. The idea: if large values of go with large values of , then and tend to have the same sign, and their product tends to be positive. If large goes with small , the product tends to be negative.
Definition: Covariance
The covariance of and , with means and , is
Expand the product and use linearity:
Theorem: Properties of Covariance
For random variables , , and constants , , , :
, and . : adding constants changes nothing, and rescaling rescales. . - If and are independent, .
(1) is clear from the definition. For (2), has mean , so its deviation from its mean is ; similarly for ; and
Example 6.10: The First Die and the Total ★ lecture example
Roll two fair dice. Let be the first die and the total. (a) Find . (b) Explain why it's positive.
(a) Use the properties rather than a 36-cell table. By property 3, then properties 1 and 4 (the two dice are independent),
Check by brute force over the 36 equally likely outcomes:
x <- rep(1:6, times = 6); y <- rep(1:6, each = 6); s <- x + y
mean((x - mean(x)) * (s - mean(s))) # population covariance over the 36 outcomes
35 / 12
[1] 2.916667
[1] 2.916667
(We use mean rather than R's cov(), because cov() divides by , as the sample variance does, and here we want the exact probability-weighted average.)
(b) A high first roll pushes the total up, so the two tend to be above (or below) average together. The covariance is exactly the first die's own variance, because that's the part of the total the first die contributes; the second die adds variation that is unrelated to .
Correlation
Covariance has awkward units (inches times inches, minutes times minutes), and its size depends on the units: measure heights in centimetres instead of inches and the covariance grows by a factor of . Dividing by both standard deviations gives a pure number.
Definition: Correlation
The correlation of and (with positive standard deviations) is It is the covariance of the standardized variables and .
Theorem: Correlation Is Between −1 and 1
, and exactly when is a linear function of , (with for and for ), with probability 1.
Let and be the standardized variables, each with variance 1. A variance is never negative, so, using the rules of Section 6.6 (which follow from the covariance properties above),
For the dice,
What do different correlations look like? Each panel shows 200 simulated points with the stated correlation. The last panel is a perfect curved relationship with correlation 0: correlation sees only straight-line trends.
set.seed(6)
make <- function(rho) { x <- rnorm(200); y <- rho * x + sqrt(1 - rho^2) * rnorm(200)
data.frame(panel = sprintf("r = %+.1f", rho), x, y) }
d <- do.call(rbind, lapply(c(-0.9, -0.5, 0, 0.5, 0.9), make))
x <- seq(-2, 2, length.out = 200)
d <- rbind(d, data.frame(panel = "curve, r = 0", x, y = x^2 - mean(x^2)))
d$panel <- factor(d$panel, levels = unique(d$panel))
ggplot(d, aes(x, y)) + geom_point(alpha = 0.5, size = 1, colour = "steelblue") +
facet_wrap(~ panel, ncol = 3, scales = "free") + labs(x = "X", y = "Y") +
theme(axis.text = element_blank())
Correlation and the best straight-line prediction
Correlation measures how well a straight line predicts one variable from another. That's the precise sense in which it measures linear association.
Theorem: The Best Linear Predictor
Among all predictions of of the form , the expected squared error is smallest when
For any , the expected squared error is
Three things follow.
- Regression to the mean, exactly. In standard units, the predicted is times the standardized . Unless , the prediction is closer to the mean (in SDs) than the predictor was. Galton's fathers and sons have , so a father 2 SDs above average predicts a son only about 0.8 SD above average.
- is the fraction of variance explained. Using cuts the prediction error's variance from to . With , that's only a 15% reduction; with , it's 81%.
- If the true conditional mean is a straight line (as it is for a bivariate Gaussian, Section 6.7), the best linear predictor is the conditional mean, the best predictor of all.
For data cor(x, y)), and the fitted line has slope and passes through . This is the least-squares line (in R, lm(y ~ x)), which Gauss used for Ceres (Section 5.3).
Example 6.11: Predicting Old Faithful from a Straight Line ★ lecture example
For the 272 eruptions in faithful, the eruption lengths have mean 3.49 minutes and SD 1.14, and the waits until the next eruption have mean 70.9 minutes and SD 13.6. The sample correlation is . (a) Find the least-squares line for predicting the wait from the eruption length. (b) Predict the wait after a 2-minute eruption and after a 4.5-minute eruption. (c) How big is the typical prediction error?
(a) Slope and intercept from the summaries: coef(fit) below shows. (The rounded summaries printed above give 10.74 and 33.4, which is close enough for prediction.) So
(b) After 2 minutes:
(c) The typical error is
cor(faithful$eruptions, faithful$waiting)
fit <- lm(waiting ~ eruptions, data = faithful)
coef(fit)
predict(fit, data.frame(eruptions = c(2, 4.5)))
sd(faithful$waiting) * sqrt(1 - cor(faithful$eruptions, faithful$waiting)^2)
[1] 0.9008112
(Intercept) eruptions
33.47440 10.72964
1 2
54.93368 81.75778
[1] 5.903088
ggplot(faithful, aes(eruptions, waiting)) +
geom_point(alpha = 0.6, colour = "steelblue") +
geom_smooth(method = "lm", se = FALSE, colour = "black") +
labs(x = "eruption length (minutes)", y = "wait until next (min)")
`geom_smooth()` using formula = 'y ~ x'
Critical thinking. The line fits well, but the picture shows two clusters, and the line passes through the gap between them, where there are few eruptions. Predictions for a 3-minute eruption rest on very little data. A correlation of 0.90 summarizes the relationship in one number, and the scatterplot shows what the number leaves out.
Uncorrelated isn't independent
Independence implies zero covariance, but zero covariance does not imply independence. Covariance only detects linear tendencies: whether tends to rise or fall as rises. A relationship can be strong and still have no linear trend.
Example 6.12: The Dart, Once More ★ lecture example
For the dart of Example 6.5, uniform on the disc : (a) show that ; (b) explain why and are nonetheless dependent.
(a) Symmetry. The disc and the density are unchanged if we replace by . So is symmetric about 0, giving , and the product is equally likely to be and , giving . Hence
(b) Example 6.5 showed that the conditional distribution of given is uniform on , which depends on . Knowing that the dart is near the top tells you it must be near the centre line. The spread of depends on , though its average doesn't, and covariance only sees the average.
cov(darts$x, darts$y) # close to 0
c(sd(darts$x[abs(darts$y) < 0.2]), sd(darts$x[abs(darts$y) > 0.8])) # spread depends on y
[1] -0.001576221
[1] 0.5720822 0.2759127
Watch Out: What a Correlation Can't Tell You
- It only measures straight-line association. is consistent with a strong curved relationship, like the dart's, or with symmetric about 0.
- It is sensitive to outliers. A single extreme point can create or destroy a correlation (try it in the widget).
- It depends on the range. Among NBA players, height and points scored are only weakly correlated, because everyone is tall. Restricting the range of weakens correlations.
- It says nothing about cause. See the causal box below.
Causal Inference: Storks Deliver Babies (R = 0.62)
In 2000 the physicist Robert Matthews published a short paper with a deliberately absurd finding. Across 17 European countries, the number of breeding pairs of storks was strongly correlated with the number of births: , too strong to be a fluke by the standards of Chapter 9. Do storks bring babies?
The explanation is a common cause. Large countries, such as Poland and Turkey, have more land for storks and more people to have babies. Land area is a confounder (Chapter 1), and in the DAG there is no arrow between storks and births at all:
Comparing countries of similar size, or comparing births per person with storks per square kilometre, would most likely weaken or remove the correlation. Real cases are less obvious. Ice-cream sales and drownings rise together (summer causes both); cities with more police have more crime (more crime leads cities to hire police, which is reverse causation); and selecting a group on a collider can create correlation from nothing (Section 3.5). A correlation is a fact about the data. Whether it reflects a cause is a question about the mechanism that produced the data, and the DAG is where to start.
Source: R. Matthews (2000), "Storks deliver babies (p = 0.008)", Teaching Statistics 22, 36–38.
History: Correlation Was Born in a Police Bureau
In the 1880s the Paris police adopted a system of criminal identification invented by Alphonse Bertillon, a clerk at the Prefecture of Police. Each arrested person was measured: head length, head breadth, the length of the left middle finger, the left foot, the forearm and more. The measurements were filed so that a repeat offender using a false name could be identified. Francis Galton studied the system in 1888 and noticed a flaw. The measurements weren't independent: a person with long forearms usually has long feet and is tall. Recording several related measurements added less information than Bertillon assumed, just as a second correlated breathalyser reading does (Section 6.6).
Galton realised that he needed a measure of how closely two quantities were "co-related", and in his 1888 paper "Co-relations and their measurement, chiefly from anthropometric data" he introduced the correlation coefficient, building on his work on heredity (the history box after Example 5.6). Karl Pearson gave it the formula we use today in 1896, which is why it is often called the Pearson correlation. Bertillon's system was soon overtaken by fingerprints, another method Galton helped to establish, in his book Finger Prints (1892).
The word itself has drawn criticism. In Bernoulli's Fallacy (2021), Aubrey Clayton includes "correlation" in his list of terms that statistics would do better without. One reason the word is risky: it sounds like a general measure of connection between two things, when the number measures only how well a straight line fits, and it invites causal stories it can't support. These notes keep the standard word, because every paper and program uses it (R's cor()). But read every correlation as "how well does a straight line predict one from the other, in these data?", and nothing more.
Check Yourself
Does a correlation say anything about what happens when we change ?
Correlation isn't a percentage of points. What does measure?
is the fraction of the variance of removed by the best straight-line prediction from . Whether changing would change is a causal question that the correlation can't answer.
For Galton's fathers and sons, the covariance of heights is 2.37 square inches, the fathers' SD is 2.31 inches and the sons' SD is 2.62 inches. Find the correlation, to 2 decimal places.
Divide the covariance by the product of the SDs.
Think About It: More Police, More Crime?
Across US cities, the number of police officers per person is positively correlated with the crime rate. A commentator concludes that police cause crime. Give two other explanations, and say what kind of data would help you choose between them.
Reverse causation: cities with high crime hire more police, so crime causes police rather than the other way round. Confounding: larger, denser cities have both more crime and more police per person, and so may poorer cities with more crime and more federal policing grants. To find the effect of police on crime you need variation in police numbers that isn't caused by crime: for example, comparing the same city before and after a hiring increase that was decided for unrelated reasons (an election promise or a budget formula), with similar cities that didn't change as a comparison. Economists have used exactly these kinds of "natural experiments", and most find that more police lead to less crime, the opposite of the raw correlation.
Key Takeaways
. Independent ⇒ , but not conversely. lies in , and only for exact straight lines. - The best straight-line prediction is : slope , error variance . This is regression to the mean.
- Correlation measures linear association in the data; it is not evidence of cause by itself.
6.6 Sums and averages
Totals and averages are everywhere: the total of an insurer's claims, the average of repeated measurements, the number of successes in trials. Their means are easy. Their spreads depend on covariances.
Theorem: Variance of a Sum
For any random variables and and constants and ,
This is the result promised in Section 4.3. Two consequences will carry the rest of the course.
- Subtracting adds uncertainty. The difference between two independent measurements is more variable than either.
- Averaging reduces it. If are independent, each with variance , their average has
Four times as much data halves the spread of an average. Chapter 7 builds on this.
Sums also change shape. The total of one die is flat; of two dice, a triangle; of five dice, already close to a bell. Each new independent piece smooths the distribution further, a first glimpse of the Central Limit Theorem of Chapter 7.
total_pmf <- function(k) { p <- rep(1/6, 6); out <- 1
for (i in 1:k) out <- convolve(out, rev(p), type = "open")
data.frame(dice = paste(k, ifelse(k == 1, "die", "dice")), total = k:(6 * k), p = out) }
d <- do.call(rbind, lapply(c(1, 2, 3, 5), total_pmf))
d$dice <- factor(d$dice, levels = unique(d$dice))
ggplot(d, aes(total, p)) + geom_col(width = 0.8) + facet_wrap(~ dice, nrow = 1, scales = "free") +
scale_x_continuous(breaks = function(l) pretty(l, n = 3)) +
labs(x = "total", y = "probability")
Example 6.13: Is a Second Breathalyser Reading Worth Taking? ★ lecture example
A breathalyser's readings scatter around the true alcohol level with SD g/dL (Example 5.7). Two readings are taken and averaged. (a) If the two errors are independent, what is the SD of the average? (b) What if the errors have correlation 0.5, because the same device and the same breath sample affect both? (c) For a driver whose true level is 0.075, find the probability that the average is 0.08 or more in each case, assuming Gaussian errors.
(a) The average is . With independent errors,
(b) With correlation , the covariance is , so
(c) The average has mean 0.075 either way. Standardizing:
- independent:
; - correlated:
.
sd_avg <- 0.005 * sqrt((1 + c(0, 0.5)) / 2)
sd_avg
1 - pnorm(0.08, mean = 0.075, sd = sd_avg)
[1] 0.003535534 0.004330127
[1] 0.0786496 0.1241065
A single reading wrongly puts this driver over the limit 16% of the time (Example 5.7). Averaging two independent readings cuts that to 8%; with correlated errors, only to 12%. (Example 5.7's rule, using the lower of two readings, is stricter still: 2.5% with independent errors.) Laboratories check for correlated errors by using two different methods, such as a breath test and a blood test, rather than two readings from the same device.
Example 6.14: Where the Binomial Variance Comes from
In Section 4.4 we stated that has variance . Prove it.
Write
Example 6.15: How Many Shared Birthdays? ★ lecture example
In a class of 30 students, how many pairs of students share a birthday, on average? (Ignore February 29 and assume all 365 days are equally likely.)
Count with indicators. There are pairs of students. For each pair, let if the two share a birthday, which has probability . The number of shared-birthday pairs is the sum of these 435 indicators, so by linearity
set.seed(6)
pairs <- replicate(10000, { b <- sample(1:365, 30, replace = TRUE); sum(choose(table(b), 2)) })
mean(pairs) # close to 1.19
[1] 1.1759
Sums of independent named distributions
Sometimes the sum of independent random variables has a recognizable distribution.
Theorem: Sums of Independent Poisson and Gaussian Random Variables
- If and are independent, then
. - If and are independent, then
.
(1) The event splits into the disjoint events
(2) The mean and variance follow from linearity and the variance of a sum. That the sum is Gaussian again can be proved with moment generating functions: if and are independent, then
In the football model of Example 6.6, the total number of goals is therefore , and the chance of a 0–0 draw is , matching the top-left cell of the joint table.
Bayesian Inference: What Does a Reading of 0.081 Really Tell Us?
Example 5.7 predicted readings from a known alcohol level. A court has the reverse problem: given a reading of 0.081, how likely is it that the driver's true level was over 0.08? Bayes' theorem for random variables answers it with a joint distribution: the posterior density of given the reading is
Suppose that, among drivers who are stopped and tested, true levels are roughly Gaussian with mean 0.06 and SD 0.02 (an illustrative prior), and that readings are Gaussian around the true level with SD 0.005. When both pieces are Gaussian, the posterior is Gaussian too, and its mean is a weighted average of the prior mean and the reading, each weighted by its precision (1/variance):
prec <- c(prior = 1 / 0.02^2, reading = 1 / 0.005^2)
post_mean <- sum(prec * c(0.06, 0.081)) / sum(prec)
post_sd <- 1 / sqrt(sum(prec))
c(post_mean, post_sd, 1 - pnorm(0.08, post_mean, post_sd))
[1] 0.079764706 0.004850713 0.480656043
So
Check Yourself
and are independent with SDs 3 and 4. What is ?
Variances add for independent variables, even for a difference.
A lab instrument has measurement SD 0.08 mg. How many independent repeat measurements must be averaged to bring the SD of the average down to 0.02 mg?
Think About It: Ten Witnesses, or One?
Ten eyewitnesses each estimate a getaway car's speed. If their errors were independent, the average of ten estimates would have one-third () of the spread of a single estimate. Name two reasons why the errors may not be independent, and say what that does to the value of the extra witnesses.
Witnesses who talked to each other before giving statements tend to converge on a shared story, and witnesses who all stood at the same spot share the same viewing angle and the same illusions of speed. Leading questions from the same investigator can push them all the same way. Positively correlated errors mean the average is less precise than , and if the correlation is high, ten witnesses may be little better than one, even though their agreement looks impressive. This is why police guidelines say witnesses should be separated before they give statements: it protects the independence that makes several accounts more valuable than one. The "wisdom of crowds" works only when the crowd's errors are independent.
Key Takeaways
; for independent variables the covariance term vanishes. - The average of independent measurements with SD has SD . Positive correlation erodes the benefit.
- Write counts as sums of indicators; linearity of expectation needs no independence.
- Independent Poissons add to a Poisson; independent Gaussians add to a Gaussian.
Prediction and inference in this chapter
- Prediction. The best prediction of one quantity from another is a conditional mean: a son's height given his father's, the wait for Old Faithful given the last eruption. The conditional spread is the size of the error to expect. The best straight-line prediction has slope , and in standard units it is always closer to the average than the predictor, which is regression to the mean. And averages of independent measurements predict more precisely than single ones, by a factor of .
- Inference. Joint distributions describe how quantities are connected. Independence (or its failure) is a claim about the mechanism, and we checked it in tables, in densities and in football scores. Correlation measures linear association, but the storks, the police and Galton's own reading of his data all showed that association alone can't tell us why two things move together; for that we need the DAGs of Chapter 1 and the right comparison groups. The Bayesian box turned a breathalyser reading into a probability about the driver's true level, by combining a joint distribution of truth and measurement.
- What comes next. The sample mean is itself a random variable: a sum of independent pieces, divided by . This section gave its mean and its SD. Chapter 7 finds its whole distribution, which turns out to be approximately Gaussian (the Central Limit Theorem), and that is the key to the margins of error and tests in Chapters 8 and 9.
6.7 Interludes
Interlude (Optional): Galton's Ellipse: The Bivariate Gaussian
When Galton drew contour lines through his table of parents' and children's heights, joining cells with equal counts, he found that they formed ellipses, tilted along the direction of the correlation. He asked the Cambridge mathematician J. D. Hamilton Dickson to find the surface that would produce them, and in 1886 Dickson gave him the bivariate Gaussian density. In standard units, with correlation , it is
Galton's own data show the ellipses. The curves below enclose about 50% and 90% of a bivariate Gaussian fitted to the fathers' and sons' heights; their tilt is the correlation of 0.39.
galton <- read.csv("https://raw.githubusercontent.com/vincentarelbundock/Rdatasets/master/csv/HistData/GaltonFamilies.csv")
sons <- subset(galton, gender == "male")
ggplot(sons, aes(father, childHeight)) +
geom_jitter(width = 0.1, height = 0.1, alpha = 0.35, colour = "steelblue") +
stat_ellipse(type = "norm", level = 0.5, linewidth = 1) +
stat_ellipse(type = "norm", level = 0.9, linewidth = 1, linetype = "dashed") +
labs(x = "father's height (inches)", y = "son's height (inches)")
The same idea extends to any number of variables, as the multivariate Gaussian, described by a vector of means and a matrix of covariances. It is the workhorse of modern statistics and machine learning, from weather forecasting to the "latent spaces" of image generators.
Why it matters: when you see correlation used as if it were the measure of dependence, the analyst is (often silently) assuming a bivariate Gaussian. For data like the dart's, that assumption fails.
Interlude (Optional): Markov Chains: Dependence Through Time
Many sequences of random variables are dependent in a simple way: tomorrow depends on today, but not on the more distant past. Suppose that if today is rainy, tomorrow is rainy with probability 0.6, and if today is dry, tomorrow is rainy with probability 0.2. This is a Markov chain, named after the Russian mathematician Andrey Markov, who in 1913 used one to describe how vowels and consonants follow each other in Pushkin's novel in verse Eugene Onegin.
What fraction of days are rainy in the long run? If that fraction is , it must reproduce itself from one day to the next (by the Law of Total Probability):
Why it matters: independence is the exception. Most real data, from daily ozone (Chapter 1) to the eruptions of Old Faithful, carry memory, and the models of later courses handle it with chains like this one.
6.8 Exercises
Each exercise has a hint and an answer. For continuous problems, sketch the region where the density is positive before setting up any integral.
Exercises
A joint table. Discrete random variables and have the joint PMF below.
Y = 1 Y = 2 Y = 3 Y = 4 0.10 0.05 0.03 0.01 0.07 0.16 0.18 0.09 0.12 0.09 0.04 0.06 (a) Find
and . (b) Find the marginal distributions of and . (c) Find and . (d) Find . (e) Are and independent? Row sums give ; column sums give . For (d), compute by multiplying each cell by and adding; then subtract . For (e), find one cell that isn't the product of its margins.
(a) 0.09 and 0.10. (b) : 0.19, 0.50, 0.31; : 0.29, 0.30, 0.25, 0.16. (c)
; . (d) , , , so . (e) No: , but . A joint density. and have joint density
for . (a) Verify that is a valid joint density. (b) Find the marginal densities. (c) Find and . (d) Find . For (d) you need , (from the marginals) and
. (a) , and
. (b) and , each on . (c) and . (d) , and , so , , , and . Correlation from a small table. Find for the joint PMF below. Are and independent?
Y = 0 Y = 3 0.15 0.18 0.20 0.30 0.07 0.10 Marginals:
, . Only the column contributes to . , ,
, so . With and , : very nearly uncorrelated. But they aren't independent: , while . Does the fund beat the market? Many hedge funds advertise returns that are uncorrelated with the stock market. Over 10 weeks, the market's weekly returns (%) were 1, 5, 3, 10, 15, 2, 3, 7, 11, 10, and a fund's were 2, 7, 7, 11, 12, 8, 6, 8, 10, 14. (a) Draw a scatterplot. (b) Compute the sample correlation. (c) Is the advertisement believable?
Enter the two vectors in R and use
plot(x, y)andcor(x, y).(b) . (c) No: the fund rose and fell with the market. With only 10 weeks the estimate is uncertain, but a correlation this high would be very unlikely if the true correlation were 0 (Chapter 9 makes this precise).
Linearity without independence. Twenty people throw their hats into a pile and each takes one at random. Let be the number who get their own hat. (a) Using indicators, find . (b) Are the indicators independent? (c) Compare with Secret Santa (Example 4.7).
Person gets their own hat with probability .
(a)
, whatever the number of people. (b) No: if 19 people have their own hats, so does the 20th. (c) It's the same problem; there, about 37% of games had nobody drawing their own name, and the average was 1. Which comes first? Three components of a machine fail at random, independently, with exponential lifetimes of mean 2, 4 and 8 years. (a) What is the distribution of the time until the first failure? (b) What is its mean? (c) What is the probability that the 2-year component fails first?
The rates are , and per year. Extend Example 6.7 to three variables.
(a)
. (b) years. (c) . Independent or not? For each joint density, decide whether and are independent, and explain. (a) on . (b) on . (c)
for all . Does the density factor into a function of times a function of , and is the region a rectangle?
(a) Independent: on a square. (b) Dependent: the formula factors, but the region isn't a rectangle; learning forces . (c) Independent: is the product of two standard Gaussian densities.
Pairwise but not mutual. Toss two fair coins. Let if the first is heads, if the second is heads, and if they match (each is 0 otherwise). (a) Show that and are independent. (b) Show that , and are not mutually independent.
List the four equally likely outcomes with the values of , , .
(a)
; the other three cells work the same way. (b) , but the product of the marginals is . Galton's prediction. Using the line
for Galton's data: (a) predict the son's height for fathers of 65, 69.1 and 75 inches; (b) of the 15 sons whose fathers were at least 74 inches tall, 12 were shorter than their fathers. Is that surprising? (c) Would you use this line to predict the height of a son born in 2025? Why or why not? For (b), think about regression to the mean. For (c), think about whether the mechanism has stayed the same since the 1880s.
(a) About 67.4, 69.2 and 71.9 inches. (b) Not surprising: the prediction for these fathers is about 72 inches, well below their own heights, so most sons should be shorter. (c) No: average heights have risen by several inches since Galton's time, because of better nutrition and health. The relationship within families may be similar, but the intercept has changed. Predictions assume the mechanism that produced the data still holds.
Diversification. Using R's
EuStockMarkets(daily closing prices of four European stock indices, 1991–1998), compute daily percentage returns withr <- diff(log(EuStockMarkets)) * 100. (a) Find the SDs of the DAX (Germany) and FTSE (UK) returns and their correlation. (b) Use the variance-of-a-sum formula to find the SD of a portfolio half in each, and check it in R. (c) What would the portfolio's SD be if the two were independent?The portfolio return is
. Use sd(r[, "DAX"]),cor(r[, "DAX"], r[, "FTSE"]).(a) SDs about 1.03% and 0.80%; correlation about 0.64. (b) The variance is
plus the covariance term , about 0.69 in total (0.686 with unrounded inputs), so the SD is about , matching sd((r[, "DAX"] + r[, "FTSE"]) / 2). That's below the DAX's SD but slightly above the FTSE's: with correlation 0.64, mixing helps only a little. (c). Diversification works best when assets are weakly correlated. Total expectation at the dispatch desk. On a night shift, a dispatcher receives calls, and each call takes on average 15 minutes to handle, independently of how many calls there are. What is the expected total handling time? Use the law of total expectation.
Given , the expected total is . Average that over the distribution of .
minutes. Spot the flaw. For each claim, say what is wrong. (a) "The correlation between ice-cream sales and drownings is 0.8, so banning ice cream would save lives." (b) "Hours studied and exam score have correlation 0, so studying doesn't matter." (c) "Shoe size and reading ability are strongly correlated in elementary schools, so bigger feet help children read."
Think about confounders, curved relationships and what was held fixed.
(a) Summer heat is a common cause of both; correlation isn't causation. (b) Zero correlation rules out only a straight-line trend; the relationship could be curved (a little study helps a lot, cramming all night hurts), or other variables could mask it (weaker students study more). (c) Age is a confounder: older children have bigger feet and read better.
The Gaussian integral. Chapter 5 promised a proof that the standard Gaussian density integrates to 1. Let
. (a) Write as a double integral over the plane. (b) Change to polar coordinates () and evaluate it. (c) Conclude that is a valid density. , and . The substitution handles the integral. , so , and dividing by gives total area 1. Notice that the proof uses exactly the factorization of the joint density in Exercise 7(c). Gaussian sums by MGFs. The moment generating function of is
. Use it to show that the sum of independent and random variables is Gaussian, and find its parameters. For independent and ,
. An MGF determines the distribution. , the MGF of .