A note on AI tools: You may use AI assistants (ChatGPT, Claude, etc.) to help debug your R code — that’s a realistic professional skill. You may not use AI to generate your interpretations. Every write-up sentence must reflect your own reading of the output. If you use AI for any part of this assignment, note where at the end.
A simulated within-subjects study measures 30 participants completing three kinds of tasks (a puzzle, a reading task, and math problems), each performed under three background-noise conditions (silence, white noise, music). This is teaching data (simulated for this course, units not specified) — practice the reshaping mechanics, don’t treat the scores as a real finding.
data <- read.csv("https://jkoxford-a11y.github.io/awesomesaucestats/data/cognitive_experiment_data.csv")str(data)
names(data)The column names follow a Task_Condition pattern, but
watch out: one task name (Math_Problems) itself contains an
underscore, so a naive split on the first underscore would
break it. You need a pattern that correctly separates the task from the
noise condition regardless of how many underscores the task name
has.
library(tidyverse)
long_df <- pivot_longer(
data,
cols = -Participant,
names_to = c("task", "noise"),
names_pattern = "(.*)_(Silence|White_Noise|Music)"
)
str(long_df)
nrow(long_df)
table(long_df$task, long_df$noise)table() output. Is the design balanced
(same number of observations in every task × noise cell)?Now deliberately do it the naive way, to see what goes wrong:
broken <- pivot_longer(
data,
cols = -Participant,
names_to = "condition",
values_to = "score"
)
str(broken)
length(unique(broken$condition))condition have in the
broken version, and what’s actually in it? Why doesn’t this give you a
usable task variable and a usable noise
variable the way Part 2 did?pivot_longer” failure mode from the chapter’s own
common-errors table. In your own words, what should you check
immediately after any pivot, before doing anything else with
the result?library(ggplot2)
ggplot(long_df, aes(x = noise, y = value, fill = task)) +
geom_boxplot() +
labs(x = "Noise condition", y = "Score", fill = "Task")task and noise)
crossed on the same 30 people, with Participant as the ID.
Without running it, write the aov_ez() call (from Ch 19)
you would use to test whether task, noise, and their
interaction affect performance.