Setting up

library(ez)
library(tidyverse)
library(data.table)
rm(list=ls())

This tutorial introduces five core statistical analyses commonly used in psychology and behavioral research. Each scenario gives you:

You’ll use:

Bonus activities:

Q1

A cognitive psychologist wants to test whether reaction time (RT) differs across three levels of task difficulty (Easy, Medium, Hard). Each participant completes all three tasks.

set.seed(1)
rm_data <- data.table(
  id = rep(1:30, each = 3),
  difficulty = rep(c("Easy", "Medium", "Hard"), times = 30),
  rt = c(rnorm(30, mean = 500, sd = 40),
         rnorm(30, mean = 550, sd = 40),
         rnorm(30, mean = 600, sd = 40))
)

head(rm_data)
a). What is the independent variable(s) and how many levels?
b). What is the dependant variable?
c). Calculate the mean for the dependent variable within each level of the independent variable(s).
d). What type of statistical test would you run? Why?
e). Perform the statistical test and write a sentence explaining the results.

Q2

A sleep study measures accuracy under two lighting conditions (Bright vs Dim) and two times of day (Morning vs Evening). Each participant completes all four combinations.

tw_data[, accuracy := rnorm(.N, 
                            mean = fifelse(light == "Bright" & time == "Morning", 90,
                                    fifelse(light == "Bright", 85,
                                    fifelse(time == "Morning", 80, 75))),
                            sd = 5)]

head(tw_data)
a). What is the independent variable(s) and how many levels?
b). What is the dependant variable?
c). Calculate the mean for the dependent variable within each level of the independent variable(s).
d). What type of statistical test would you run? Why?
e). Perform the statistical test and write a sentence explaining the results.

Q3

Group A (Training) and Group B (Control) complete a memory test before and after a training intervention.

set.seed(3)
mx_data <- CJ(id = 1:60, time = c("Pre", "Post"))
mx_data[, group := rep(rep(c("Training", "Control"), each = 30), each = 2)]
mx_data[, score := ifelse(group == "Training" & time == "Post",
                          rnorm(.N, mean = 85, sd = 5),
                          rnorm(.N, mean = 75, sd = 5))]
a). What is the independent variable(s) and how many levels?
b). What is the dependant variable?
c). Calculate the mean for the dependent variable within each level of the independent variable(s).
d). What type of statistical test would you run? Why?
e). Perform the statistical test and write a sentence explaining the results.

Q4.

A researcher explores the relationship between screen time and sleep quality.

set.seed(4)
cor_data <- data.table(
  screen_time = runif(50, 1, 10)
)
cor_data[, sleep_quality := 100 - screen_time * 6 + rnorm(.N, 0, 5)]
a). Visualise the relationship between sleep quality and screen time.
b). Perform the statistical test and write a sentence explaining the results.

Q5.

You want to predict exam performance from hours of study.

set.seed(5)
reg_data <- data.table(
  study_hours = runif(60, 0, 20)
)
reg_data[, exam_score := 50 + 2.5 * study_hours + rnorm(.N, 0, 5)]
a). Visualise the relationship between exam performance and hours of study.
b). Perform the statistical test and write a sentence explaining the results.