Writing down the analysis before the data

Today let's understand why writing down your analysis plan before you see the data is what keeps a result honest.

Here's the trial we'll use throughout. A team wants to know whether a daily 5-minute breathing-exercise reminder lowers stress. They recruit 200 people and split them into two equal groups: 100 get the reminder every day, and 100 get nothing. Everyone in the trial is measured on four things:

  • Stress at week 4, a score from 0 to 10 where a higher number means more stress.
  • Stress averaged across the four weekly check-ins.
  • Sleep quality at week 4, the same 0 to 10 scale, but here a higher number means better sleep.
  • Whether a participant's stress dropped by at least 2 points.

Here is the answer key for this lesson, something a real research team never gets to see. The reminder changes nothing. Every one of those four outcomes is drawn from the exact same distribution whether a person got the reminder or not. So any test in this lesson that comes back significant is, by construction, a false positive.

One sentence before the numbers: this builds the 200-person dataset and prints the two group sizes and the four outcome names, before a single test has run.

RInteractive R
# Build the trial's data: 200 participants, four outcomes measured on everyone set.seed(13) grp <- rep(c("treat", "control"), each = 100) stress_w4 <- c(rnorm(100, 5.0, 1.8), rnorm(100, 5.0, 1.8)) # stress at week 4, 0 to 10 stress_avg <- c(rnorm(100, 5.0, 1.5), rnorm(100, 5.0, 1.5)) # stress averaged over the 4 weekly check-ins sleep_w4 <- c(rnorm(100, 6.0, 1.6), rnorm(100, 6.0, 1.6)) # sleep quality at week 4, 0 to 10 improved <- c(rbinom(100, 1, 0.30), rbinom(100, 1, 0.30)) # 1 if stress dropped by 2 points or more table(grp) #> grp #> control treat #> 100 100 c("stress_w4", "stress_avg", "sleep_w4", "improved") #> [1] "stress_w4" "stress_avg" "sleep_w4" "improved"

  

In this data, the reminder group is labeled "treat" and the no-reminder group "control". The fourth outcome does not come from subtracting two separate stress readings. Since nothing here is real, it is simpler to draw the 1 for improved, or 0 for not, directly, at a 30% rate in both groups.

Two groups of 100, four outcomes, and not one result computed yet. Here's the shape of the whole lesson from here.

That is the whole arc. Everything from here works through those three steps on this one trial.

The same dataset, four honest questions

A pre-registration document eventually commits a researcher to one outcome before the data arrive. But to see why that matters, first watch what happens without one, on this exact 200-person dataset, when all four outcomes get tested.

Let's run a t-test on each of the three continuous outcomes, and a two-proportion test on the binary one. t.test() in R runs Welch's t-test by default, which compares two group means without assuming the two groups vary by the same amount. prop.test() does the same job, but for two shares instead of two means.

One sentence before the code: this runs all four honest tests on the same dataset and prints the four p-values side by side.

RInteractive R
# Run the honest test for each of the four outcomes, on the one dataset above p_stress_w4 <- t.test(stress_w4[grp == "treat"], stress_w4[grp == "control"])$p.value p_stress_avg <- t.test(stress_avg[grp == "treat"], stress_avg[grp == "control"])$p.value p_sleep_w4 <- t.test(sleep_w4[grp == "treat"], sleep_w4[grp == "control"])$p.value p_improved <- prop.test(c(sum(improved[grp == "treat"]), sum(improved[grp == "control"])), c(100, 100))$p.value round(c(stress_w4 = p_stress_w4, stress_avg = p_stress_avg, sleep_w4 = p_sleep_w4, improved = p_improved), 3) #> stress_w4 stress_avg sleep_w4 improved #> 0.520 0.014 0.675 0.546

  

Three of the four p-values come back with nothing to report: stress at week 4, sleep quality, and the share who improved all sit well above 0.05. But stress averaged over the four weeks clears the bar, at p = 0.014.

Remember the answer key from the step before this one. The reminder changes nothing, in every one of these four outcomes alike. So that one significant result is not a real effect. It is a false positive, produced by a dataset where, by construction, nothing is going on.

Key Insight
One dataset, tested four honest ways, turned up one significant result even though nothing in it is real. That is not a one-off quirk of this particular dataset, which is exactly what gets checked next.