Descriptive statistics: two variables

Print the chapter

Every lesson of the chapter, ready for paper. Exercise sets are lettered A, B, C… and answered at the end.

To save a PDF, choose “Save as PDF” in the print dialog.

1. Two-way tables: joint, marginal and conditional proportions

Warm-up

Three quick questions from earlier lessons.

Discover

In a class, 12 of 20 girls and 9 of 15 boys play a sport. Who is more likely to play, a girl or a boy?

  1. Equally likely: 60% each
  2. A girl: 12 is more than 9

Key idea

A two-way table counts cases by two categorical variables.

Joint proportion: a cell ÷ grand total. Marginal proportion: a row or column total ÷ grand total. Conditional proportion: a cell ÷ its row (or column) total: the proportion within one group.

Worked example

Pets: 30 cat owners (18 adults, 12 children), 50 dog owners (35 adults, 15 children).

Joint: adults with cats =1880= \tfrac{18}{80}
Cell ÷ 80.
Marginal: adults =5380= \tfrac{53}{80}
Column total ÷ 80.
Conditional: adults among cat owners =1830=0.6= \tfrac{18}{30} = 0.6
Within cat owners.

Your turn, guided

Your turn: children among dog owners.

0.30.3
15 of 50.

Practice ★

  1. A survey asked 145 people whether they exercise weekly. Under 30: 22 yes, 43 no. Age 30 or over: 27 yes, 53 no. What proportion of the under-30s exercise weekly?
  2. A survey asked 121 people whether they exercise weekly. Under 30: 59 yes, 12 no. Age 30 or over: 23 yes, 27 no. What proportion of the under-30s exercise weekly?
  3. A survey asked 150 people whether they exercise weekly. Under 30: 41 yes, 40 no. Age 30 or over: 19 yes, 50 no. What proportion of the under-30s exercise weekly?

Watch out!

Practice ★★

  1. A survey asked 124 people whether they exercise weekly. Under 30: 21 yes, 50 no. Age 30 or over: 31 yes, 22 no. What proportion of all the people exercise weekly?
  1. A survey asked 140 people whether they exercise weekly. Under 30: 47 yes, 17 no. Age 30 or over: 37 yes, 39 no. What proportion of all the people are under 30 and exercise weekly?
  2. A survey asked 135 people whether they exercise weekly. Under 30: 44 yes, 25 no. Age 30 or over: 10 yes, 56 no. What proportion of all the people are under 30 and exercise weekly?

Exit ticket

Three questions to check you have got it.

  1. A survey asked 145 people whether they exercise weekly. Under 30: 22 yes, 43 no. Age 30 or over: 27 yes, 53 no. What proportion of the under-30s exercise weekly?
  2. A survey asked 121 people whether they exercise weekly. Under 30: 59 yes, 12 no. Age 30 or over: 23 yes, 27 no. What proportion of the under-30s exercise weekly?
  3. A survey asked 150 people whether they exercise weekly. Under 30: 41 yes, 40 no. Age 30 or over: 19 yes, 50 no. What proportion of the under-30s exercise weekly?

Summary card

Two-way tables

  • Joint: cell / total. Marginal: margin / total.
  • Conditional: cell / its group total.

Watch out: name the group you condition on.

2. Association between categorical variables

Warm-up

Three quick questions from earlier lessons.

Discover

70% of students who sleep 8+ hours passed a test, and 40% of those who sleep less passed. Is there an association between sleep and passing?

  1. Yes, the pass rates differ
  2. We cannot tell without an experiment

Key idea

Compare conditional distributions.

Two categorical variables are associated if the conditional distribution of one differs across the groups of the other. If the conditional proportions are all equal, there is no association. Association in observational data does not show causation.

Worked example

Of 50 phone users, 30 sleep badly; of 50 non-users, 10 sleep badly.

60% vs 20% sleep badly
Within each group.
Association between phone use and sleep
A big difference.
It does not prove phones cause bad sleep
Observational data.

Your turn, guided

Your turn: the difference in proportions (users − non-users).

0.40.4
0.6 − 0.2.

Practice ★

  1. Of 40 drivers who texted, 30 had a near-miss; of 40 who did not text, 10 had one. Is there an association between texting and near-misses in these data?
    1. Yes: 75% of texters vs 25% of non-texters had a near-miss
    2. No: both groups have 40 drivers
    3. Yes, and it proves texting causes near-misses
  1. In a school, 50 of 125 girls and 100 of 250 boys walk to school. What does this suggest?
    1. No association: 40% of each group walks
    2. Boys are more likely to walk: 100 > 50
    3. Girls are more likely to walk

Watch out!

Practice ★★

  1. A survey asked 135 people whether they exercise weekly. Under 30: 44 yes, 40 no. Age 30 or over: 18 yes, 33 no. Find the proportion of under-30s who exercise minus the proportion of those 30 or over who exercise.
  2. A survey asked 163 people whether they exercise weekly. Under 30: 45 yes, 37 no. Age 30 or over: 48 yes, 33 no. Find the proportion of under-30s who exercise minus the proportion of those 30 or over who exercise.

Exit ticket

Three questions to check you have got it.

  1. A survey asked 135 people whether they exercise weekly. Under 30: 44 yes, 40 no. Age 30 or over: 18 yes, 33 no. Find the proportion of under-30s who exercise minus the proportion of those 30 or over who exercise.
  2. A survey asked 163 people whether they exercise weekly. Under 30: 45 yes, 37 no. Age 30 or over: 48 yes, 33 no. Find the proportion of under-30s who exercise minus the proportion of those 30 or over who exercise.
  3. A survey asked 112 people whether they exercise weekly. Under 30: 28 yes, 48 no. Age 30 or over: 13 yes, 23 no. Find the proportion of under-30s who exercise minus the proportion of those 30 or over who exercise.

Summary card

Association

  • Compare conditional proportions across groups.
  • Different: associated. Equal: not associated.

Watch out: association is not causation; counts are not rates.

3. Scatterplots and correlation

Warm-up

Three quick questions from earlier lessons.

Discover

Points lie close to a line going down from left to right. Which correlation fits?

  1. r=−0.95r = -0.95
  2. r=0.2r = 0.2

Key idea

Describe a scatterplot by direction, form, strength and unusual points. Correlation measures linear strength.

The correlation rr is between −1-1 and 11: its sign gives the direction, ∣r∣|r| the strength of a linear relationship. It has no units, does not change when units change, and is the same if xx and yy are swapped. It is sensitive to outliers and misleading for curved patterns.

Worked example

Hours of study vs test score: r=0.78r = 0.78.

Direction: positive (more study, higher scores)
Positive r.
Strength: fairly strong, linear
|r| = 0.78.
Scores out of 50 or 100: same rr
Unitless.

Your turn, guided

Your turn: r=0.6r = 0.6 for (x,y)(x, y). What is rr for (y,x)(y, x)?

0.60.6
Symmetric in x and y.

Practice ★

  1. A scatterplot of car age against resale value has r=−0.94r = -0.94. How would you describe the relationship?
    1. Strong, negative, linear: older cars tend to be worth less
    2. Weak, because r is negative
    3. Each extra year causes a fixed loss of value
  2. A scatterplot of car age against resale value has r=−0.92r = -0.92. How would you describe the relationship?
    1. Strong, negative, linear: older cars tend to be worth less
    2. Weak, because r is negative
    3. Each extra year causes a fixed loss of value
  1. Heights (cm) and weights (kg) of students have r=0.58r = 0.58. Heights are converted to inches. What is the new correlation?
    1. Still 0.580.58: changing units does not change rr
    2. Smaller, since inches are bigger units
    3. It cannot be known without the data

Watch out!

Practice ★★

  1. Which statements about the correlation rr of 50 pairs (x,y)(x, y) are true? Tick all that are.
    1. −1≤r≤1-1 \le r \le 1
    2. rr has no units
    3. Swapping xx and yy does not change rr
    4. rr measures the strength of any relationship, curved or straight
    5. r=0r = 0 means there is no relationship at all

Exit ticket

Three questions to check you have got it.

  1. A scatterplot of car age against resale value has r=−0.94r = -0.94. How would you describe the relationship?
    1. Strong, negative, linear: older cars tend to be worth less
    2. Weak, because r is negative
    3. Each extra year causes a fixed loss of value
  2. A scatterplot of car age against resale value has r=−0.92r = -0.92. How would you describe the relationship?
    1. Strong, negative, linear: older cars tend to be worth less
    2. Weak, because r is negative
    3. Each extra year causes a fixed loss of value
  3. A scatterplot of car age against resale value has r=−0.90r = -0.90. How would you describe the relationship?
    1. Strong, negative, linear: older cars tend to be worth less
    2. Weak, because r is negative
    3. Each extra year causes a fixed loss of value

Summary card

Correlation

  • −1≤r≤1-1 \le r \le 1; sign = direction, size = linear strength.
  • Unitless; symmetric in xx and yy.

Watch out: rr only sees straight lines.

4. The least-squares regression line

Warm-up

Three quick questions from earlier lessons.

Discover

If r=1r = 1, every point is on a line. A student 1 SD above the mean in xx is then 1 SD above the mean in yy. If r=0.5r = 0.5, how many SDs above the mean in yy would you predict?

  1. 0.5 SD
  2. 1 SD

Key idea

The line that minimizes the sum of squared residuals.

Least-squares regression line y^=a+bx\hat{y} = a + bx with slope b=r sysxb = r\,\dfrac{s_y}{s_x} and intercept a=yˉ−bxˉa = \bar{y} - b\bar{x}; it always passes through (xˉ,yˉ)(\bar{x}, \bar{y}).

Worked example

r=0.6r = 0.6, xˉ=10\bar{x} = 10, sx=2s_x = 2, yˉ=50\bar{y} = 50, sy=8s_y = 8.

  1. Step 1The data.
  2. Step 2The point of means (x̄, ȳ) = (10, 50).
  3. Step 3The line ŷ = 26 + 2.4x passes through it.
  4. Step 4Residuals: no other line makes the sum of their squares smaller.

b=2.4b = 2.4
0.6 × 8/2.
a=26a = 26
50 − 2.4 × 10.
y^=26+2.4×12=54.8\hat{y} = 26 + 2.4 \times 12 = 54.8
At x = 12.

Your turn, guided

Your turn: r=0.5r = 0.5, sx=4s_x = 4, sy=6s_y = 6. The slope.

b=0.75b = 0.75
0.5 × 6/4.

Practice ★

  1. r=0.6r = 0.6, sx=15s_x = 15 and sy=16s_y = 16. Find the slope of the least-squares regression line of yy on xx.
  2. r=0.5r = 0.5, sx=11s_x = 11 and sy=17s_y = 17. Find the slope of the least-squares regression line of yy on xx.
  1. The regression line is y^=27+9x\hat{y} = 27 + 9x. Predict yy for x=7x = 7.

Watch out!

Practice ★★

  1. The least-squares line has slope 22, and xˉ=37\bar{x} = 37, yˉ=52\bar{y} = 52. Find its intercept.
  2. The least-squares line has slope 55, and xˉ=28\bar{x} = 28, yˉ=53\bar{y} = 53. Find its intercept.
  1. Boss problem. r=0.8r = 0.8, xˉ=15\bar{x} = 15, sx=4s_x = 4, yˉ=42\bar{y} = 42, sy=8s_y = 8.

Exit ticket

Three questions to check you have got it.

  1. r=0.6r = 0.6, sx=15s_x = 15 and sy=16s_y = 16. Find the slope of the least-squares regression line of yy on xx.
  2. r=0.5r = 0.5, sx=11s_x = 11 and sy=17s_y = 17. Find the slope of the least-squares regression line of yy on xx.
  3. r=0.9r = 0.9, sx=19s_x = 19 and sy=12s_y = 12. Find the slope of the least-squares regression line of yy on xx.

Summary card

Least-squares line

b=r sy/sxb = r\,s_y/s_x, a=yˉ−bxˉa = \bar{y} - b\bar{x}, through (xˉ,yˉ)(\bar{x}, \bar{y}).

Watch out: sys_y on top.

5. Residuals and residual plots

Warm-up

Three quick questions from earlier lessons.

Discover

The model predicts 70 for a student who actually scored 76. Is the student above or below the line, and by how much?

  1. 6 above
  2. 6 below

Key idea

Residuals show what the line misses.

Residual = observed −- predicted =y−y^= y - \hat{y}. Positive: point above the line. A residual plot (residuals against xx) should look like random scatter around 0; a curve or a fan shape means a linear model is not appropriate.

Worked example

y^=12+3x\hat{y} = 12 + 3x; the data point is (5,30)(5, 30).

y^=27\hat{y} = 27
Predicted.
Residual =30−27=3= 30 - 27 = 3
Observed − predicted.
The point is 3 above the line
Positive.

Your turn, guided

Your turn: same line, point (4,20)(4, 20).

Residual −4-4
20 − 24.

Practice ★

  1. y^=30+3x\hat{y} = 30 + 3x. A data point is (7,46)(7, 46). Find its residual.
  2. y^=36+4x\hat{y} = 36 + 4x. A data point is (3,41)(3, 41). Find its residual.
  3. y^=32+6x\hat{y} = 32 + 6x. A data point is (7,70)(7, 70). Find its residual.

Watch out!

Practice ★★

  1. The residual plot of a linear model fitted to 56 points shows a clear U-shaped curve. What does that tell you?
    1. A straight line is not a good model: the relationship is curved
    2. The model is good, because residuals are both positive and negative
    3. There is one outlier
  1. A point has residual +8+8. Where is it relative to the regression line?
    1. 8 units above the line: the model underpredicts it
    2. 8 units below the line
    3. On the line

Exit ticket

Three questions to check you have got it.

  1. y^=30+3x\hat{y} = 30 + 3x. A data point is (7,46)(7, 46). Find its residual.
  2. y^=36+4x\hat{y} = 36 + 4x. A data point is (3,41)(3, 41). Find its residual.
  3. y^=32+6x\hat{y} = 32 + 6x. A data point is (7,70)(7, 70). Find its residual.

Summary card

Residuals

  • e=y−y^e = y - \hat{y}; positive is above the line.
  • Residual plot: no pattern means a linear model is appropriate.

Watch out: observed minus predicted, in that order.

6. Interpreting a regression model: slope, r², extrapolation

Warm-up

Three quick questions from earlier lessons.

Discover

price^=2+0.5 weight\widehat{\text{price}} = 2 + 0.5\,\text{weight} for bags of rice (dollars, kg). What does 0.5 mean?

  1. Each extra kg adds 0.5 dollars to the predicted price
  2. Every bag costs exactly 0.5 dollars per kg

Key idea

Interpret in context, and know the limits.

Slope: the predicted change in yy for each one-unit increase in xx. Intercept: the predicted yy when x=0x = 0 (meaningful only if x=0x = 0 makes sense). r2r^2: the fraction of the variation in yy explained by the linear model. Predicting outside the range of the data is extrapolation and is unreliable.

Worked example

r=0.9r = 0.9 for study hours and scores.

r2=0.81r^2 = 0.81
Square r.
81% of the variation in scores is explained by the linear model on hours
Interpretation.
19% is not explained
The rest is other factors and chance.

Your turn, guided

Your turn: r=−0.7r = -0.7. Find r2r^2.

0.490.49
(−0.7)².

Practice ★

  1. A regression has r=0.2r = 0.2. What fraction of the variation in yy is explained by the linear model (r2r^2)?
  2. A regression has r=0.8r = 0.8. What fraction of the variation in yy is explained by the linear model (r2r^2)?
  1. For trees, height^=3+8 age\widehat{\text{height}} = 3 + 8\,\text{age} (feet, years). What does 88 mean?
    1. For each extra year of age, the predicted height increases by 8 feet
    2. Every tree grows exactly 8 feet each year
    3. A tree of age 0 is 8 feet tall

Watch out!

Practice ★★

  1. A model for children aged 2 to 6 predicts height from age. Is it reasonable to use it for a 40-year-old?
    1. No: 40 is far outside the ages used to fit the model (extrapolation)
    2. Yes, if r is close to 1
    3. Yes: a line can be extended forever

Exit ticket

Three questions to check you have got it.

  1. A regression has r=0.2r = 0.2. What fraction of the variation in yy is explained by the linear model (r2r^2)?
  2. A regression has r=0.8r = 0.8. What fraction of the variation in yy is explained by the linear model (r2r^2)?
  3. A regression has r=0.4r = 0.4. What fraction of the variation in yy is explained by the linear model (r2r^2)?

Summary card

Interpreting regression

  • Slope: predicted change per unit of xx.
  • r2r^2: share of variation explained.
  • No extrapolation.

Watch out: r2r^2, not rr, is the explained fraction.