Lesson 3

A

Locked — confirm your name above to begin.

Statistics is a framework for evaluating what we know, what we think we know, and how confident we are that we know it. The core mechanism we rely on — in science and in life — is prediction: seeing how well our understanding of the world predicts something we have not seen.

This part is close to what you did before. You are going to choose one number to be the best possible prediction of human size.

  • 7,414 adults. Body mass in kilograms, one measurement each.
  • Choose the one number that best predicts all of them.
  • Best means lowest error — wrong by the smallest amount, on average.
heavier than your number:  |  lighter:  |  average miss:
how far off you are on a typical person: — this is what knowing nothing about them costs you

Controls

60.0

To open Stage B

  • Settle on a number and lock it in. Inside ±0.3 kg and you are through. currently
Stage B is open.

R code

nh <- read.csv("data/clean/nhanes_adults.csv")y  <- nh$Weightguess <- 60.0mean(guess - y)      # which way you leansum(y > guess); sum(y < guess)

B

Solve Stage A to unlock this section.

One number is usually not enough. Not all people are identical, which is why the error above is so large: your one number does a bad job of fitting the data.

How do we make it do better? Usually there are groups, or factors, we are not accounting for — in any model there are always things we do not see. Here we separate the 7,414 adults by biological sex and compare the body mass of females and males.

That needs two numbers. You could fit a separate body mass for females and for males. Instead we use one number for females and an adjustment for males. You could do it the other way round, and it would work just as well.

  • The same 7,414 adults, split by biological sex.
  • One number for females, plus an adjustment added only for males.
  • One box per group, on the body masses as they were measured. The box holds the middle half, the line inside it is the middle person, the diamond is the average, and the whiskers reach the 5th and 95th.
  • Your two numbers draw as rules across their own boxes. Bring both to the middle at once.
  • Under the plot: how far off you are on a typical person now, against what knowing nothing cost you in Stage A. The difference is what the label was worth.
female:  |  male:
typical miss now:  |  knowing nothing cost you:  |  so the label is worth:

Controls

60.0
0.0

To open Stage C

  • Bring both groups inside ±0.4 kg at once. worst of the two:
Stage C is open.

R code

nh <- read.csv("data/clean/nhanes_adults.csv")is_male <- as.numeric(nh$Gender == "male")base  <- 60.0extra <- 0.0guess <- base + extra * is_maletapply(guess - nh$Weight, is_male, mean)# the same two numbers, found for youcoef(lm(Weight ~ is_male, data = nh))

C

Solve Stage B to unlock this section.

The bigger the data set, the easier it is to find a clear difference: with a lot of data, even a small difference is relatively easy to detect. With a smaller sample you get less reliable — and sometimes counterintuitive — results. The smaller the sample, the more likely you are to find something counterintuitive, or even flatly wrong in direction.

Here you estimate the female number and the male adjustment in a small sample, and find a case where the adjustment for males comes out negative — males lighter than females. In the full data set that does not happen. In a small sample it can.

Think about how many people you want in each group for that to happen. Weighing handful after handful blindly will take a long time; look at the graph before you fit, and stop when you see a handful you suspect will hold.

  • n females and n males, drawn from the same 7,414.
  • The same two numbers as Part B, fitted to the handful in front of you.
  • Lower panel: the adjustment you settled on, and how uncertain it is.
  • Raise the number in each group and watch what it does to the result.
female, off by:  |  male, off by:
your adjustment for males:  |  give or take:  |  across all 7,414 it is:
handfuls weighed: 0  |  of those, males lighter: 0

Controls

6
70.0
0.0

To open Stage D

  • Land both groups of the handful in front of you, inside ±1.0 kg. worst of the two:
  • Land a handful where the adjustment for males comes out negative. not yet
Stage D is open.

R code

nh <- read.csv("data/clean/nhanes_adults.csv")n  <- 6f  <- sample(nh$Weight[nh$Gender == "female"], n)m  <- sample(nh$Weight[nh$Gender == "male"],   n)base  <- 70.0extra <- 0.0mean(base - f); mean(base + extra - m)# the same two numbers, and the same band, found for yout.test(m, f, var.equal = TRUE)# how wide the band is, for any ns <- sd(nh$Weight[nh$Gender == "male"])2 * s * sqrt(2 / n)

D

Solve Stage C to unlock this section.

So far we have predicted within one data set, or with one extra factor. Another key aspect of statistics — and of understanding the world — is how well a model, a way of predicting one system, works in a different system entirely.

First, fit a model of growth to my older son Beren's real growth data. The setup is simple: he weighed some amount at age two, and he grows at some rate over time. Age two is the baseline. Find the weight at age two and the growth rate that best explain the rest of his growth.

  • Beren's home-scale weighings, from his first birthday on.
  • Two numbers: his weight at age two, and kilograms added per year.
  • Lower panel: what your line leaves over, split into his younger half and his older half.
Beren younger:  |  older:  |  Cyrus younger:  |  older:

Controls

12.0
0.00

To open Stage E

  • Fit Beren: both halves inside ±0.4 kg. worst of his two:
  • Then settle on Cyrus's weight at age two and lock it in. Beren first
Stage E is open.

R code

k <- read.csv("data/clean/kids_growth.csv")k$kg <- ifelse(k$units == "g", k$value / 1000, k$value)d <- subset(k, measure == "mass" & age_years >= 1)base  <- 12.0grow  <- 0.00extra <- 0.0guess <- base + grow * (d$age_years - 2) +         extra * (d$kid == "cyrus")tapply(d$kg - guess, d$kid, mean)# the same three numbers, found for youcoef(lm(kg ~ I(age_years - 2) + kid, data = d))

E

Solve Stage D to unlock this section.

The Lord of the Rings is a trilogy of books by J. R. R. Tolkien, turned into three films by Peter Jackson. The films are very faithful to the books, often using quotes from them verbatim, and the order in which those quotes appear on screen is very close to the order in which they appear on the page.

Across the bottom: the minute of the film a quote is spoken. Up the side: the page of its own book the quote falls on. Were the three films made in the same way — do they begin in the same place, and do they move through their books at the same rate? Or are there fundamental differences in how the three books were adapted?

  • 32 quotes across the three films.
  • Across: minute of the film. Up: page of that film's own book.
  • Six knobs — an opening page and a pace for each film.
  • Two sliders: how many opening pages the three films are allowed between them, and how many paces.
average miss: pages  |  worst miss: pages

Controls

1
one opening page for all three films
1
one pace for all three films

To finish the lesson

  • Get the average miss down to 15 pages or better. best so far:
  • Answer the question below.
Fit accepted.

The best you have reached each way

The Return of the King has 311 pages. You have estimated a pace, in pages per minute, for The Fellowship of the Ring. If The Return of the King had been adapted at Fellowship's pace, how long would you expect it to be?
minutes

R code

q <- read.csv("data/clean/lotr_quotes.csv")# one opening page, one pacelm(page_total ~ minute, data = q)# one for each film, opening page onlylm(page_total ~ minute + film, data = q)# one of each for each filmfit <- lm(page_total ~ minute * film, data = q)mean(abs(residuals(fit)))