# February 21 library(tidyverse) library(ggeffects) d <- read.csv("http://whlevine.hosted.uark.edu/psyc5143/PBmeat.csv") # contrast code the meat factor & the PB factor & create a product term d <- d %>% mutate(meatC = ifelse(meat == "none", -1/2, 1/2), PBC = ifelse(PB == "none", -1/2, 1/2), int = meatC*PBC) summary(lm(tastiness ~ meatC + PBC + int, d)) # creating a decent plot (still not great, but better?) model.plot <- lm(tastiness ~ meat*PB, d) plot1 <- ggemmeans(model.plot, terms = c("PB", "meat")) %>% ggplot() + theme_bw() + geom_line(aes(x = x, y = predicted, group = group, color = group)) plot1 # dummy codes d <- d %>% mutate(meatD = ifelse(meat == "none", 0, 1), PBD = ifelse(PB == "none", 0, 1)) summary(lm(tastiness ~ meatD*PBD, d), t = F) # larger design scrambled <- read.csv("http://whlevine.hosted.uark.edu/psyc5143/scrambled.csv") # what's in there? glimpse(scrambled) # cell means scrambled %>% group_by(text, wpm) %>% summarise(M = mean(dv), SD = sd(dv), n = length(dv)) # marginal means scrambled %>% group_by(text) %>% summarise(M = mean(dv)) scrambled %>% group_by(wpm) %>% summarise(M = mean(dv)) # contrast codes scrambled <- scrambled %>% mutate(T = ifelse(text == "intact", 1/2, -1/2), R1 = ifelse(wpm == "600 wpm", -2/3, 1/3), R2 = case_when(wpm == "300 wpm" ~ 1/2, wpm == "450 wpm" ~ -1/2, wpm == "600 wpm" ~ 0), TR1 = T*R1, TR2 = T*R2) model.contrasts <- lm(dv ~ T + R1 + R2 + TR1 + TR2, scrambled) summary(model.contrasts) anova(model.contrasts) # plot! model.default <- lm(dv ~ text*wpm, scrambled) plot2 <- ggemmeans(model.default, terms = c("wpm", "text")) %>% ggplot() + theme_bw() + geom_line(aes(x = x, y = predicted, group = group, color = group)) plot2