--- title: "Problem Set 9 Answer Key" author: "WHL" output: html_document --- ```{r setup, results = 'hide', message = FALSE, include = FALSE} options(digits = 4, scipen = 999) knitr::opts_chunk$set(echo = TRUE, fig.width = 4, fig.height = 4) library(tidyverse) library(lmSupport) library(lme4) library(ez) options(knitr.kable.NA = '') ``` # 1 ```{r, message = FALSE, results='hide'} # import data d <- read.csv("http://whlevine.hosted.uark.edu/psyc5143/ps10.csv") # make sure factors are factors d$id <- as.factor(d$id) d$A <- as.factor(d$A) # what coding is R using for factor A? contrasts(d$A) # dummy coding # useful info: condition means d %>% group_by(A) %>% summarise(M = mean(DV)) # fitting the model treating the data as between-subjects modelBetween <- lm(DV ~ A, d) # getting some SS values anova(modelBetween) SS_between <- 154.8 SS_within <- 158.8 SS_total <- SS_between + SS_within # another way to get these modelC <- lm(DV ~ 1, d) modelEffectSizes(modelC) modelA <- lm(DV ~ 1 + A, d) modelEffectSizes(modelA) modelCompare(modelC, modelA) ``` $SS_{between}$ = `r SS_between`. $SS_{within}$ = `r SS_within`. $SS_{total}$ = `r SS_total`. # 2 ```{r, message=FALSE, results='hide'} # a & b # probably the easiest way to do the ANOVA ezANOVA(data = d, dv = DV, wid = id, within = A, detailed = TRUE)$ANOVA # the SSs SS_persons <- 141.6 # this is SSd for the intercept SS_A <- 154.8 # this is SSn for the IV SS_resid <- 17.2 # this is SSd for the Iv # checking equality all.equal(SS_persons + SS_resid, SS_within) # this function checks for the # approximate equality of two things ``` a) $SS_{A}$ = `r SS_A`. $SS_{persons}$ = `r SS_persons`. $SS_{error}$ = `r SS_resid`. b) $SS_{between}$ = $SS_{A}$. $SS_{within}$ from #1 = $SS_{persons}$ + $SS_{error}$ from #2. c) The denominator for $F$ in #2 is much smaller than in #1 because $SS_{persons}$ has been removed from it. It cost a few $df$, but the $F$-ratio increased by more than a factor of 6! # 3 ```{r, results='hide'} modelLMEM <- lmer(DV ~ A + (1|id), d) anova(modelLMEM) ``` $F$ = 36 again!