Skip to content

Instantly share code, notes, and snippets.

@raphaelvallat
Last active March 20, 2018 18:37
Show Gist options
  • Save raphaelvallat/916ca2c2a49b1bb92f4ce92126fcd180 to your computer and use it in GitHub Desktop.
Save raphaelvallat/916ca2c2a49b1bb92f4ce92126fcd180 to your computer and use it in GitHub Desktop.
Mixed within-between ANOVA in R
library(ez)
library(lsmeans)
library(effsize)
# Load the file
df <- read.csv(file="", head=TRUE, sep=",")
# Choose dependant variable (e.g. reaction time)
df$dv <- df$RT
# Compute mixed within-and-between subject designs ANOVA
# See https://cran.r-project.org/web/packages/ez/ez.pdf
rt_anova = ezANOVA(
data = df,
dv = dv, # Dependant variable (must be numeric)
wid = Subject, # Variable specifying the subject identifier
within = Session, # Predictor variables that are observed or predicted within subjects
between = Group, # Predictor variables that are observed or predicted between subjects
type = 2) # 2 is the default, 3 = SPSS / SAS default
print(rt_anova)
# Post-hocs using paired T-tests
pairwise.t.test(df$dv, df$Session, paired=TRUE, p.adj="none")
# Effect sizes
for ( i in levels(df$Session) )
{
tmp <- droplevels(df[-which(df$Session == i), ])
cat(levels(tmp$Session))
d <- cohen.d(tmp$dv, tmp$Session, paired=TRUE, hedges.correction=FALSE, conf.level=0.95)
print.effsize(d)
cat('---------\n\n')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment