library(haven)
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.3.2
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(afex)
## Warning: package 'afex' was built under R version 4.3.3
## Loading required package: lme4
## Loading required package: Matrix
## ************
## Welcome to afex. For support visit: http://afex.singmann.science/
## - Functions for ANOVAs: aov_car(), aov_ez(), and aov_4()
## - Methods for calculating p-values with mixed(): 'S', 'KR', 'LRT', and 'PB'
## - 'afex_aov' and 'mixed' objects can be passed to emmeans() for follow-up tests
## - Get and set global package options with: afex_options()
## - Set sum-to-zero contrasts globally: set_sum_contrasts()
## - For example analyses see: browseVignettes("afex")
## ************
## 
## Attaching package: 'afex'
## The following object is masked from 'package:lme4':
## 
##     lmer
library(tidyverse)
## Warning: package 'ggplot2' was built under R version 4.3.2
## Warning: package 'readr' was built under R version 4.3.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats   1.0.0     ✔ readr     2.1.5
## ✔ ggplot2   3.4.4     ✔ stringr   1.5.0
## ✔ lubridate 1.9.3     ✔ tibble    3.2.1
## ✔ purrr     1.0.2     ✔ tidyr     1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ tidyr::expand() masks Matrix::expand()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ✖ tidyr::pack()   masks Matrix::pack()
## ✖ tidyr::unpack() masks Matrix::unpack()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
ANOVA_Example_Data <- read_sav("ANOVA Example Data.sav")
View(ANOVA_Example_Data)
ANOVA_Example_Data %>% #start with dataset
distinct(Subject, .keep_all = TRUE) -> dataset.unique
(dataset.unique.aov <- aov_ez(id = "Subject", dv = "RaceDFeb", data = dataset.unique, between=c("TrainTyp", "EC")))
## Converting to factor: TrainTyp, EC
## Contrasts set to contr.sum for the following variables: TrainTyp, EC
## Anova Table (Type 3 tests)
## 
## Response: RaceDFeb
##        Effect     df  MSE         F   ges p.value
## 1    TrainTyp 1, 670 0.17      0.51 <.001    .477
## 2          EC 1, 670 0.17 12.40 ***  .018   <.001
## 3 TrainTyp:EC 1, 670 0.17      0.00 <.001    .961
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '+' 0.1 ' ' 1
(dataset.unique %>% # start with the dataset 
group_by(EC) %>% # group by the training goal variable
summarise(mean = mean(RaceDFeb),  # get the mean of the DV in each group
          SD = sd(RaceDFeb)) -> trainingGoalDescriptives) # get the SD of the DV in each group
## # A tibble: 2 × 3
##   EC                            mean    SD
##   <dbl+lbl>                    <dbl> <dbl>
## 1 0 [Self-Pos Black Training]  0.153 0.386
## 2 1 [Other-Neg Black Training] 0.264 0.435