# April 10, 2024 library(tidyverse) library(ez) library(lme4) twofactorRM <- read.csv("http://whlevine.hosted.uark.edu/psyc5143/twoFactorRM.csv", stringsAsFactors = T) # I want study time to be a factor twofactorRM$studytime <- factor(twofactorRM$studytime) # checking levels of things & default coding levels(twofactorRM$studytime) contrasts(twofactorRM$studytime) contrasts(twofactorRM$wordtype) # a digression: study time does NOT need to be a factor; the numbers # in this case are meaningful with good interval qualities, so this # could be treated as a quantitative numerical predictor rather than # a factor ... but not today! # single-sample t-tests instead of main effects # find each person's abstract & concrete mean wordContrast <- twofactorRM %>% group_by(Subject, wordtype) %>% summarise(M = mean(dv)) # what do we have wordContrast # rearrange the data a bit wordContrast <- wordContrast %>% spread(wordtype, M) # what do we have now? wordContrast # cool # create difference scores wordContrast <- wordContrast %>% mutate(d = concrete - abstract) # checking one more time wordContrast # do the t-test (vs H0: mu = 0) t.test(wordContrast$d, mu = 0) summary(lm(d ~ 1, wordContrast)) # single-sample t-tests for the simple effects of word type within each study # time condition twofactorRM %>% filter(studytime == "1") %>% t.test(dv ~ wordtype, data = .) twofactorRM %>% filter(studytime == "2") %>% t.test(dv ~ wordtype, data = .) twofactorRM %>% filter(studytime == "3") %>% t.test(dv ~ wordtype, data = .) ##### EXTRA STUFF (FYI) ##### # not discussed in class; here as an example # more-complex contrast (linear trend of time) linearTime <- twofactorRM %>% group_by(Subject, studytime) %>% summarise(M = mean(dv)) # rearrange the data linearTime <- linearTime %>% spread(studytime, M) # rename the variables colnames(linearTime)[2:4] <- c("one", "two", "three") # create the contrast linearTime <- linearTime %>% mutate(con = -1*one + 0*two + 1*three) # do the t-test (vs H0: mu = 0) t.test(linearTime$con, mu = 0) ##### # the semi-informative omnibus ANOVA ezANOVA(data = twofactorRM, dv = dv, wid = Subject, within = .(studytime, wordtype), detailed = T) # doing ALL the t-tests pairwise.t.test(x = twofactorRM$dv, # outcome g = twofactorRM$variable, # factor paired = TRUE, # paired data = TRUE p.adjust.method = "bonferroni") # attend to FWER # via lmer LMM <- lmer(dv ~ studytime*wordtype + (1|Subject), twofactorRM) anova(LMM) # no p-values AND F does NOT match the conventional ANOVA summary(LMM) # contrast slopes are what we're interested in, along with their t-tests