# R for Psychological Research, Lesson 13: Before a t-test
# Code from the lesson page, in order. Run it line by line with Ctrl+Enter (Cmd+Enter on a Mac).
# Lines that start with # are comments: R ignores them.


# ---- Set up ----

library(tidyverse)
library(rstatix)
library(pwr)
students <- read_csv("data/students.csv", show_col_types = FALSE)


# ---- Plan the sample size: power ----

pwr.t.test(d = 0.5, sig.level = .05, power = .80, type = "two.sample")


# ---- Check the assumptions ----

is.numeric(students$Wellbeing_T1)
students %>%
  identify_outliers(Wellbeing_T1) %>%
  select(ID, Wellbeing_T1, is.outlier, is.extreme)

students %>% shapiro_test(Wellbeing_T1)
ggplot(students, aes(sample = Wellbeing_T1)) +
  stat_qq() +
  stat_qq_line()
