Setting up
library(data.table)
library(ez)
rm(list=ls())
set.seed(1)
This tutorial introduces some core statistical analyses commonly used in psychology and behavioral research. Each scenario gives you:
You’ll use:
Bonus activities:
A social researcher is interested in students height across different universities and whether they are significantly taller than the state average (165cm). For their first study, they looked at students who study at Western Sydney University (WSU), sampling a total of 100 students.
data_q1 <- rnorm(100, 170, 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.
A researcher is interested in whether caffeine affects recall memory. 60 participants were recruited in this study and were required to complete a memory recall task. 30 participants were given a cup of coffee before the task, and the other 30 participants were given water.
coffee <- rnorm(30, 8, 2)
nocoffee <- rnorm(30, 7, 2)
id <- 1:60
data <- data.table(id = id, coffee = coffee, nocoffee = nocoffee)
data_q2 <- melt(data, id.vars = "id", variable.name = "condition", value.name = "score")
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.
A social researcher wants to expand their study on student height across to different universities. They have sampled 100 students each who study exclusively at WSU, MQU and UNSW. They are interested in comparing the heights across these 3 universities and whether there are any significant height differences.
x_raw <- rnorm(100, 170, 5)
y_raw <- rnorm(100, 166, 5)
z_raw <- rnorm(100, 171, 5)
x <- (x_raw - mean(x_raw)) / sd(x_raw) * 5 + 170 # mean = 170, sd = 5
y <- (y_raw - mean(y_raw)) / sd(y_raw) * 5 + 166 # mean = 166, sd = 5
z <- (z_raw - mean(z_raw)) / sd(z_raw) * 5 + 171 # mean = 171, sd = 5
data <- data.table(MQU = x, UNSW = y, WSU = z)
data_q3 <- melt(data = data, measure.vars = c("MQU", "UNSW", "WSU"), variable.name = "University", value.name = "Height")
data_q3[, Subject := 1:300]
data_q3[, University := factor(University)]
data_q3[, Subject := factor(Subject)]
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.
A researcher is interested in the effects of essential oil, specifically lavender oil, and its effects on sleep quality/duration. 80 people were recruited in this study. For the first week, all participants followed their usual sleep routines, and at the end of that week, researchers recorded each person’s average number of hours slept per night. In the 2nd week, they used lavender oil before bed each night. Sleep hours were recorded again at the end of that week and then compared to the first week.
before_lav <- rnorm(80, 7, 2)
after_lav <- rnorm(80, 8, 2)
ID <- rep(1:80, 2)
data_q4 <- data.table(id = ID, before = before_lav, after = after_lav)
data_q4 <- melt(data_q4, id.vars = "id", variable.name = "time", value.name = "hours")
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.