Skip to main content

Activity: Study Design & Sampling

Design and sampling

In-class activity: reading a design off a real randomized, blinded, unbalanced experiment — Wright & Czeisler’s circadian light study — and testing whether the placebo arm was needed.
Author

Bill Perry

Worksheet: Reading a Design

📥 Knees data 📥 Tools script (.R) 📥 Script skeleton (.R)

The study. Wright & Czeisler (2002) asked whether bright light shone on the back of the knee could reset a person’s circadian clock, the way light in the eyes does. Each volunteer was randomly assigned to one of three treatments and their circadian rhythm shift was measured in hours (negative = the clock shifted later).

  • control — no light at all
  • knee — light on the back of the knee
  • eyes — light in the eyes

Why this study is here. knee is not really a third treatment. It is a placebo — it puts a person through the entire procedure (the apparatus, the room, the night, the measurement) while delivering light somewhere it should not work. Today you decide whether that arm earned its place.

This is Whitlock & Schluter, Example 15.1.


Part 1 · Setup and the data

▶ Run this:

# ── Part 1.1 · Setup and the data ───────────────────────────────────────
library(tidyverse)
library(effectsize)

source("themes_functions/r_themes_and_functions.R")

knees_df <- read_csv("data/knees.csv")

knees_df

Part 2 · Read the design off the data

Before any test: how many replicates, at what level, and is it balanced?

▶ Run this:

# ── Part 2.1 · Read the design off the data ─────────────────────────────
count(knees_df, treatment)

✏️ Your turn: What is the experimental unit here, and is the design balanced?

unit = ____________________    balanced? ____________________

▶ Run this — the numbers for each group:

# ── Part 2.2 · Read the design off the data ─────────────────────────────
knees_df %>%
  group_by(treatment) %>%
  reframe(summary_stats(shift_h))

▶ Run this — look at the data before you test it:

# ── Part 2.3 · Read the design off the data ─────────────────────────────
ggplot(knees_df, aes(treatment, shift_h)) +
  geom_boxplot() +
  geom_jitter(width = 0.15)

✏️ Your turn: From the plot alone, which treatment looks different from the other two?

________________________


Part 3 · Did the placebo do anything?

This is the bias question: does going through the procedure, without useful light, shift the clock on its own?

▶ Run this:

# ── Part 3.1 · Did the placebo do anything? ─────────────────────────────
knees_df %>%
  filter(treatment %in% c("control", "knee")) %>%
  t.test(shift_h ~ treatment, data = .)

✏️ Your turn: p = __________ . Is there a procedural artifact in this experiment?

________________________


Part 4 · Did the real treatment do anything?

▶ Run this:

# ── Part 4.1 · Did the real treatment do anything? ──────────────────────
knees_df %>%
  filter(treatment %in% c("control", "eyes")) %>%
  t.test(shift_h ~ treatment, data = .)

▶ Run this — how big is it?

# ── Part 4.2 · Did the real treatment do anything? ──────────────────────
knees_df %>%
  filter(treatment %in% c("control", "eyes")) %>%
  cohens_d(shift_h ~ treatment, data = .)

✏️ Your turn: p = __________ , d = __________ .

Note

Two comparisons, both decided in advance

We ran two tests against the same control rather than one test across all three groups. That is legitimate here because we chose both comparisons before looking — each one answers a specific design question. Three groups at once is a one-way ANOVA, which is Week 8.


Part 5 · What the design bought

✏️ Your turn: In the sponge experiment from lecture, the sham control (foam) did differ from the bare control, and the real treatment added nothing. Here the result came out the other way around. One sentence: what would you have concluded in this study if the knee arm had never been run?

________________________________________________________
Tip

🚀 If you finish early: This design is unbalanced (8, 7, 7). Work out how much precision that costs: compare the standard error of the control mean with what it would be if all 22 subjects had been split evenly into three groups of about 7.3.

# ── Part 5.1 · What the design bought (bonus) ───────────────────────────
# Write your code in the R script:

Part 6 · The final figure

This is the only plot that gets labels, a theme and a title — because this is the one you would put in a paper.

▶ Run this:

# ── Part 6.1 · The final figure ──────────────────────────────────────────
knees_summary <- knees_df %>%
  group_by(treatment) %>%
  reframe(summary_stats(shift_h))

final_plot <- ggplot(knees_summary, aes(treatment, mean)) +
  geom_col(fill = "grey70", width = 0.6) +
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se), width = 0.15) +
  labs(
    title = "Circadian shift by light treatment",
    subtitle = "Mean ± 1 SE; light on the knee behaves like no light at all",
    x = "Light treatment",
    y = "Circadian shift (hours)"
  ) +
  theme_regular(base_size = 12)

final_plot

ggsave(
  "figures/knees_figure.pdf",
  plot   = final_plot,
  width  = 6,
  height = 4,
  units  = "in"
)

✏️ Your turn: Open the PDF and check the axis labels are readable before you submit it.


Review and checkpoint

At this point you can:


🎟️ Exit ticket

📥 Download the exit ticket (.docx)

Hand this in on Canvas before you leave. It is how I know you ran the code, so every answer comes from your own output. Upload two files:

  1. scripts/09_study_design_sampling.R. It must run top to bottom with no errors.
  2. The exit ticket with these three answers.

✏️ E1. Part 2.1: what is the experimental unit, and is the design balanced? Give the counts.

✏️ E2. Part 3.1: the knee (placebo) vs control p-value. Is there a procedural artifact?

✏️ E3. Part 4.2: the eyes vs control p-value and Cohen’s d.

Points: 3, one per answer. No script that runs, no points.


Homework

No homework this week.