Exercise: Resample people, not their repeated measurements

Exercise: Resample people, not their repeated measurements#

A paired experiment records many trials per person. Compare uncertainty from resampling independent people with an inappropriate shortcut that treats trials as independent.

See the shared submission guidance and rubric. Run from book/exercises; the setup below supplies data, not completed answers.

# Shared simulator and small utility functions; no live service is called.
source("../R/course.R")
set.seed(117)
people <- data.frame(id=1:30, baseline=rnorm(30,600,50), effect=rnorm(30,-20,30))
d <- expand.grid(id=people$id, condition=c("A","B"), trial=1:15)
d$rt <- people$baseline[d$id] + (d$condition=="B")*people$effect[d$id] + rnorm(nrow(d),0,25)

1. Preserve the pair#

Compute each participant’s mean in A and B and the paired difference B-A. Report the average difference. Explain why independently shuffling all condition labels would ignore the paired design.

# Build a one-row-per-person paired-difference table.

Your explanation and evidence:

2. Compare bootstrap units#

Construct 2000 bootstrap estimates by resampling participants’ differences. Compare its percentile interval with an intentionally naive bootstrap that resamples trial rows within each condition independently. Label the naive method as a demonstration, not an endorsed interval. Explain which variability it loses.

# Save both bootstrap distributions and compare widths without forcing an expected outcome.

Your explanation and evidence:

3. Test a specified null#

Under a symmetric paired-difference null, generate 4999 random sign flips of the participant differences. Calculate a two-sided Monte Carlo p-value with the (b+1)/(B+1) correction, counting absolute statistics at least as extreme as observed. Explain the symmetry/exchangeability assumption and distinguish this null distribution from the bootstrap sampling distribution.

# Compute the sign-flip reference distribution and corrected tail count.

Your explanation and evidence:

What to submit#

A paired-difference display, two explicitly labeled bootstrap intervals, and a sign-flip test with its assumptions. Do not use the bootstrap distribution as if it were the null distribution.