Week 4 Exercises - Data Detectives
From research question → model → plot → test → conclusion
About 50 minutes · Pairs or small groups · 🧰 tidyverse, rio, here
- Part A: Follow along (~20 min): We work through the graduate school burnout data together.
- Part B: On your own (~30 min): You apply the same routine to a new dataset on children’s well-being.
By the end you should be able to:
- Identify the predictor and outcome in a research question, and say whether each is categorical or continuous
- Use the decision tree from lecture to choose a model family
- Make a plot that matches the model
- Run
t.test()orcor.test()and find the numbers that matter - Write a one-sentence, APA-style conclusion, and say whether it is causal
Set up (5 min)
Download both datasets and save them in the
datafolder of your PSYC 640 R Project.- Graduate school burnout data (.csv) (Part A)
- Child well-being data (.csv) (Part B)
Open your R Project (double-click the
.Rprojfile). Check the top-right corner of RStudio: it should show your project’s name.Create a new Quarto document: File → New File → Quarto Document…
- Title:
Week 4 - Data Detectives - Author: your name (and your partner’s)
- Save it as
week4_inclass.qmdin your project folder
- Title:
Delete the example text, then add a setup chunk that loads your packages and imports both datasets:
library(tidyverse)
library(rio)
library(here)
burnout <- import(here("data", "wk4-inf.csv"))
wellbeing <- import(here("data", "child_wellbeing.csv"))- Run the chunk. You should see
burnout(90 obs.) andwellbeing(100 obs.) in your Environment pane.
file does not exist?
The file isn’t where here() is looking. Run here() in the Console to see your project folder, then make sure the CSV is inside its data folder, and that the file name is spelled exactly the same.
The Data Detective Routine 🔍
Use these same five steps for every research question today:
| Step | Ask yourself | What you’ll do in R |
|---|---|---|
| 1. Identify | What is the predictor (IV)? The outcome (DV)? Is each categorical or continuous? | glimpse(data) |
| 2. Model | Which model family fits, based on the decision tree? Write it as outcome ~ predictor. |
(No code; write it in text) |
| 3. Visualize | Which plot shows this relationship? | ggplot() |
| 4. Analyze | Which test matches the model? | t.test() or cor.test() |
| 5. Conclude | What did we find? Can we say it causes the outcome? | (Write one sentence) |
Decision tree reminder:
- Categorical predictor (2 groups) + continuous outcome → compare means → t-test → plot with a boxplot
- Continuous predictor + continuous outcome → association → correlation → plot with a scatterplot
Part A: Follow Along with Professor (~20 min)
The scenario
We’ve been hired as consultants for the university’s graduate school. They’re concerned about student burnout and have given us anonymous pilot data from 90 graduate students. Our job: be the data detectives.
| Variable | Description | Type |
|---|---|---|
student_id |
Unique ID for each student | ID |
program_type |
"Thesis-Based" or "Capstone-Based" |
Categorical (2 groups) |
weekly_hours |
Average hours per week spent on graduate work | Continuous |
burnout_score |
Burnout score (higher = more burned out) | Continuous |
In your .qmd, add a header # Part A and follow along. Type the code yourself rather than copying it; it sticks better.
A1. Get to know the data
glimpse(burnout)
burnout %>%
group_by(program_type) %>%
summarize(mean_burnout = mean(burnout_score),
sd_burnout = sd(burnout_score),
n = n())A2. Research Question 1
“Do thesis-based and capstone-based students differ in burnout?”
Work through the five steps together:
- Identify: predictor =
program_type(categorical, 2 groups); outcome =burnout_score(continuous) - Model: compare two group means → t-test →
burnout_score ~ program_type - Visualize:
ggplot(burnout, aes(x = program_type, y = burnout_score)) +
geom_boxplot() +
geom_jitter(width = 0.1, alpha = 0.4) +
labs(x = "Program Type", y = "Burnout Score",
title = "Burnout by Program Type")- Analyze:
t.test(burnout_score ~ program_type, data = burnout)- Conclude: From the output, find the t, df, p-value, and the two group means, then write the sentence together as a class.
A3. Research Question 2
“Is there an association between weekly work hours and burnout?”
🛑 Before you run anything: write down your prediction. Will the relationship be positive or negative? Why?
- Identify: predictor =
weekly_hours(continuous); outcome =burnout_score(continuous) - Model: association between two continuous variables → correlation →
burnout_score ~ weekly_hours - Visualize:
ggplot(burnout, aes(x = weekly_hours, y = burnout_score)) +
geom_point(alpha = 0.6) +
geom_smooth(method = "lm", se = FALSE) +
labs(x = "Weekly Hours", y = "Burnout Score",
title = "Weekly Hours and Burnout")- Analyze:
cor.test(~ weekly_hours + burnout_score, data = burnout)- Conclude: Find r, df, and the p-value. Did the result match your prediction? 🤔 If not, what could explain it? (Think about who these students are, and what might be a confound.)
Part B: On Your Own (~30 min)
The scenario
A developmental psychology lab is exploring factors related to children’s well-being. They collected pilot data from 100 children. This is an observational study: nobody was randomly assigned to anything.
| Variable | Description | Type |
|---|---|---|
child_id |
Unique ID for each child | ID |
parenting_style |
Primary parenting style observed at home: "Authoritative" or "Permissive" |
Categorical (2 groups) |
sleep_hours |
Average hours of sleep per night | Continuous |
anxiety_score |
Parent-reported anxiety (0–50; higher = more anxious) | Continuous |
In your .qmd, add a header # Part B. For each task, create a sub-header, a code chunk for each step that needs code, and write your answers in text below the chunk (not as code comments).
Every task follows the same pattern as Part A. Copy your Part A code and change the data name and variable names. The ___ blanks below show you what to change.
Task 1: Parenting Style and Anxiety
“Do children raised by authoritative parents have different anxiety levels than children raised by permissive parents?”
Step 1: Identify. In text, answer:
- What is the predictor? Is it categorical or continuous?
- What is the outcome? Is it categorical or continuous?
Step 2: Model. In text, answer:
- Which model family does the decision tree point to?
- Write the model in R formula syntax:
___ ~ ___
Step 3: Visualize. Make a boxplot, with points added, and give it labels and a title:
ggplot(wellbeing, aes(x = ___, y = ___)) +
geom_boxplot() +
geom_jitter(width = 0.1, alpha = 0.4) +
labs(x = "___", y = "___", title = "___")✍️ Before running the test: based on the plot alone, do you think the groups differ? Which group looks higher?
Step 4: Analyze. Get the group means, then run the test:
wellbeing %>%
group_by(___) %>%
summarize(mean_anxiety = mean(___),
sd_anxiety = sd(___),
n = n())
t.test(___ ~ ___, data = wellbeing)Step 5: Conclude. Fill in this template with your numbers:
Children with _____ parents (M = _____, SD = _____) had significantly higher / lower anxiety scores than children with _____ parents (M = _____, SD = _____), t(_____) = _____, p _____.
t.test() output
t = ...: the test statisticdf = ...: degrees of freedom (R uses a Welch correction, so it may have decimals; round to one decimal place)p-value = ...: if R prints< 2.2e-16, report it as p < .001mean in group ...: the two group means
Task 2: Sleep and Anxiety
“Is there an association between how many hours a child sleeps and their anxiety level?”
Step 1: Identify. What are the predictor and outcome? Is each categorical or continuous?
Step 2: Model. Which model family? Write the formula.
✋ Prediction: before running anything, do you expect a positive or negative relationship? Why?
Step 3: Visualize. Make a scatterplot with a line of best fit:
ggplot(wellbeing, aes(x = ___, y = ___)) +
geom_point(alpha = 0.6) +
geom_smooth(method = "lm", se = FALSE) +
labs(x = "___", y = "___", title = "___")Step 4: Analyze.
cor.test(~ ___ + ___, data = wellbeing)Step 5: Conclude. Fill in this template:
There was a significant positive / negative correlation between children’s hours of sleep and their anxiety scores, r(_____) = _____, p _____. Children who slept more tended to have higher / lower anxiety.
Then answer: How strong is this relationship? (Rough guide: |r| ≈ .10 small, .30 moderate, .50+ large.) Did it match your prediction?
cor.test() output
cor: this is r, the correlation (between −1 and +1)df = ...: degrees of freedom (N − 2)p-value = ...: same rules as above
🤔 Challenge Question (if you finish early)
This study is observational. In 3–4 sentences, answer:
- Can the researchers conclude that permissive parenting causes higher anxiety? Use the 3 rules of causality from lecture to explain why or why not.
- Propose one confounding variable that could influence both parenting style and child anxiety, and explain how.
- Bonus: could the causal arrow run the other way (anxiety → parenting style)? Describe how.
- Bonus: describe a study design that would give stronger evidence for a causal claim.
Before You Submit ✅
Upload both the rendered .docx and your .qmd file to myCourses.