PSY460: Advanced Quantitative Methods

Week #10: Mixed Effects Models

Today, we’ll discuss when and why to include random effects in your statistical models, and we’ll apply these to our linear model from last week. We’ll also discuss writing the second half of scientific papers, and we’ll make sure that everybody feels confident about running your final analyses.

“Quiz”

  • Write down a question you have from the assigned article.
  • Write down a question you have from the assigned video.
  • Reflect on your contributions to writing R code with your group during the past week. Approximately what percent did you contribute? If it was more or less than 33%, explain why. How well do you feel you understand the code that you submitted last night?

Mixed effects models

  • Whenever there are dependencies in data (e.g., some responses relate to other responses because they are given by the same person, or by people who are in the same school), this must be accounted for in statistical models. Mixed effects models provide a flexible way of doing this.
  • Linear mixed models are an improvement on typical linear models, by allowing you to account for the variance caused by “random” effects.
    • Random effects are typically modeled alongside “fixed” effects, thus making the models “mixed”.

What are random effects?

  • Unlike fixed effects (i.e., predictor variables for which average effects are anticipated to be systematic), random effects are unsystematic elements that vary across elements in a larger set (e.g., participants in a sample, or classrooms within schools, or items in a questionnaire).
    • Random effects can be modeled as intercepts (such that main effects differ across individual items) or as slopes (such that the imapct of fixed effects differ across items).

Research question

Do people update their judgments of whether somebody is a good cooperative partner more readily when they strongly endorse the moral value that was violated, and is this true only in cases of hypocrisy?

Getting ready for today’s analyses

#
library(tidyverse) # This gives us access to dplyr and ggplot. 
library(magrittr) # This allows us to use the double pipe.
library(lme4) # This allows us to conduct mixed effects models.
library(lmerTest) # This provides p values for mixed effects models.

TidyData <- read.csv('TidyData.csv', header = TRUE, 
                     stringsAsFactors = FALSE)

TidyData %<>% mutate(GoodCoopPartnerChange = 
                       as.numeric(rowMeans(
                         select(., c(IntegrityChange:FutureBehChange)))))

TidyData$Condition <- as.factor(TidyData$Condition)
TidyData$ID <- as.factor(TidyData$ID)
TidyData$Item <- as.factor(TidyData$Item)
glimpse(TidyData)
Rows: 2,044
Columns: 13
$ ID                    <fct> 11023, 11023, 11023, 11023, 11051, 11051, 11051,…
$ Item                  <fct> Caring_LawAbiding, Fair_Forgiving, Generous_Frug…
$ Condition             <fct> Lapse, Lapse, NoLapse, NoLapse, Lapse, NoLapse, …
$ CatMembChange         <int> 0, -7, 3, 4, -8, 10, -8, 4, -2, 5, -4, 1, 4, -6,…
$ IntegrityChange       <int> 1, -9, 2, 5, -2, 6, 0, 6, -1, 3, 1, 2, 10, 0, 2,…
$ TrustworthyChange     <int> 1, -4, 2, 2, 0, 6, 0, 6, 0, 5, 2, 3, 10, 0, 0, 2…
$ PartnerChange         <int> 0, -2, 2, 3, 0, 6, 0, 6, -1, 5, 2, 3, 8, -2, -2,…
$ WarmChange            <int> 2, -4, 0, 5, 0, 6, 2, 8, 0, 4, 1, 3, 0, 0, 0, 5,…
$ FutureBehChange       <int> 0, -11, 7, 7, -2, 10, -4, 4, -1, 6, 0, 1, -2, -6…
$ MoralEvalDiff         <int> -3, 10, 0, 3, 6, -14, -12, 14, 7, 3, -9, -12, 0,…
$ ValueDiff             <int> 1, 4, -5, 3, 6, -10, -10, -10, 2, 6, -10, -10, 1…
$ Pairing               <chr> "Caring vs. \nLaw-Abiding", "Fair vs. \nForgivin…
$ GoodCoopPartnerChange <dbl> 0.8, -6.0, 2.6, 4.4, -0.8, 6.8, -0.4, 6.0, -0.6,…

Looking at random effects visually

Adding random effects to the linear model

# 
summary(lmer(GoodCoopPartnerChange ~ ValueDiff*Condition + 
               (Condition | ID) + (Condition | Item), data = TidyData))
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: GoodCoopPartnerChange ~ ValueDiff * Condition + (Condition |  
    ID) + (Condition | Item)
   Data: TidyData

REML criterion at convergence: 10961.7

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-5.6077 -0.4343  0.0666  0.5324  4.8519 

Random effects:
 Groups   Name             Variance Std.Dev. Corr 
 ID       (Intercept)       1.1817  1.0871        
          ConditionNoLapse  0.7736  0.8796   -0.81
 Item     (Intercept)       1.1914  1.0915        
          ConditionNoLapse  1.0541  1.0267   -0.25
 Residual                  11.1410  3.3378        
Number of obs: 2044, groups:  ID, 509; Item, 32

Fixed effects:
                             Estimate Std. Error         df t value Pr(>|t|)
(Intercept)                  -1.35924    0.22470   33.02728  -6.049 8.33e-07
ValueDiff                    -0.24077    0.02042 1316.87517 -11.792  < 2e-16
ConditionNoLapse              1.40766    0.23733   30.03375   5.931 1.68e-06
ValueDiff:ConditionNoLapse    0.05132    0.02844 1387.05346   1.804   0.0714
                              
(Intercept)                ***
ValueDiff                  ***
ConditionNoLapse           ***
ValueDiff:ConditionNoLapse .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation of Fixed Effects:
            (Intr) ValDff CndtNL
ValueDiff   -0.015              
ConditnNLps -0.395  0.015       
VlDff:CndNL  0.010 -0.693 -0.014

Model comparison

Data: TidyData
Models:
NoInt.MLM: GoodCoopPartnerChange ~ ValueDiff + Condition + (Condition | ID) + (Condition | Item)
Int.MLM: GoodCoopPartnerChange ~ ValueDiff * Condition + (Condition | ID) + (Condition | Item)
          npar   AIC   BIC  logLik deviance  Chisq Df Pr(>Chisq)  
NoInt.MLM   10 10970 11027 -5475.3    10950                       
Int.MLM     11 10969 11031 -5473.7    10947 3.1423  1    0.07629 .
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Writing up Results

  • The Results should provide descriptive and inferential statistics that inform your hypotheses, along with clear visualizations.
  • After each analysis, you should briefly describe what each finding means in plain English.

Writing up Discussions

  • The Discussion should contain the following elements:

    • First, discuss whether your hypotheses were supported.

    • Next, contextualize your results with regard to previous research described in relevant literature.

    • Third, provide some plausible explanations for the specific pattern of results that your study uncovered.

    • Fourth, discuss limitations and generalizability.

    • Finally, conclude with broader implications.

Congratulations on making it through the hardest parts of class!

For our final quiz next week, I will ask for comprehension of some of the key ideas we’ve covered this semester. I will try to make it as straightforward as possible, and will fully reuse content from earlier slides.

What is left for your team to do in analyzing your data?