Mixed Effects Models - Autocorrelation

Course Business
! Lab materials on Canvas
! Package to install for today’s analyses:
languageR
Week 11.2: Autocorrelation
! Autocorrelation
! Introduction
! Testing for Autocorrelation
! Visualizing Autocorrelation
! Direction & Lag
! Why Does Autocorrelation Matter?
! Lab
Longitudinal Designs
• Two big questions mixed-effects models can
help us answer about longitudinal data:
1) What is the overall trajectory of change
across time?
" Monday: Growth curve analysis
2) How does an observation at one time point
relate to the next time point?
" Today: Autocorrelation
Autocorrelation
• Previously, we looked at general trajectory
across time
• e.g., kids who are 28 months old have larger
vocabs than kids who are 20 months old
• But, there may be relations among specific
observations
• Does reading to your kids a lot one month
increase their vocab growth the next month?
• Does being in a positive mood one day carry over
to the next day?
• Does purchasing a particular brand once make
you more likely to purchase it again?
relationship.csv
• One member of a dating couple rates their
warmth towards the partner
• For each of 10 consecutive days
• First, let’s see if WarmthToday consistently
increases or decreases across the 10 Days of
the study
• model.time <- lmer(WarmthToday ~ 1 + Day +
(1 + Day|Couple), data=relationship)
relationship.csv
• No linear increase or decrease in warmth over
the 10 days
• Makes sense … this is a relatively short timescale
Autocorrelation
• We found no overall increase/decrease
• Nevertheless, succeeding days might be more
similar, even if there is no overall trend
1 2 3 4 5
L I N E A R T R E N D
Autocorrelation
• We found no overall increase/decrease
• Nevertheless, succeeding days might be more
similar, even if there is no overall trend
• If you have warm feelings towards your partner
one day, maybe warmer the next, too
+ 2 3 4 5
L I N E A R T R E N D
Autocorrelation
• We found no overall increase/decrease
• Nevertheless, succeeding days might be more
similar, even if there is no overall trend
• If you have warm feelings towards your partner
one day, maybe warmer the next, too
+ + 3 4 5
L I N E A R T R E N D
Autocorrelation
• We found no overall increase/decrease
• Nevertheless, succeeding days might be more
similar, even if there is no overall trend
• If you have warm feelings towards your partner
one day, maybe warmer the next, too
• If you have negative feelings, maybe less warm
the next day
+ + 3 - 5
L I N E A R T R E N D
Autocorrelation
• We found no overall increase/decrease
• Nevertheless, succeeding days might be more
similar, even if there is no overall trend
• If you have warm feelings towards your partner
one day, maybe warmer the next, too
• If you have negative feelings, maybe less warm
the next day
+ + 3 - -
L I N E A R T R E N D
Autocorrelation
• We found no overall increase/decrease
• Nevertheless, succeeding days might be more
similar, even if there is no overall trend
• If you have warm feelings towards your partner
one day, maybe warmer the next, too
• If you have negative feelings, maybe less warm
the next day
+ + 3 - -
Autocorrelation
• relationship %>% head(n=10)
Couple 01
Autocorrelation
• These are examples of autocorrelation
Couple 01 Couple 02
Autocorrelation
"Maybe in order to understand mankind, we have
to look at that word itself: MANKIND. Basically,
it's made up of two separate words, 'mank' and
'ind.' What do these words mean? It's a mystery,
and that's why so is mankind.”
-- Jack Handey
Autocorrelation
To understand autocorrelation, we have to look
at the two separate words that make it up
auto (self) + correlation
• Autocorrelation refers to a variable correlating
with itself, over time
• Examples:
• Positive mood in the morning # Positive mood in
the afternoon
• RT on the previous trial # RT on this trial due to
waxing & waning of attention
Autocorrelation
• These are examples of autocorrelation
Couple 01 Couple 02
Week 11.2: Autocorrelation
! Autocorrelation
! Introduction
! Testing for Autocorrelation
! Visualizing Autocorrelation
! Direction & Lag
! Why Does Autocorrelation Matter?
! Lab
Testing for Autocorrelation
• Is there autocorrelation in relationship warmth?
• We want to test whether yesterday’s warmth
predicts today’s warmth
• So, we need to add WarmthYesterday as a variable
• With package languageR…
• relationship %>% mutate(WarmthYesterday =
lags.fnc(relationship,
time='Day',
depvar='WarmthToday',
group='Couple’,
lag=1)) -> relationship
• For each observation, get the value of WarmthToday
from 1 day previous and store in WarmthYesterday
Variable that identifies the time point
Dependent variable
Variable with the level-2 grouping
factor (e.g., subjects or schools)
Dataframe name
Baayen & Milin, 2010
Testing for Autocorrelation
• Is there autocorrelation in relationship warmth?
• We want to test whether yesterday’s warmth
predicts today’s warmth
• So, we need to add WarmthYesterday as a variable
• relationship %>% head(n=13)
Day 1 for each couple
gets the couple’s mean
Baayen & Milin, 2010
Testing for Autocorrelation
• Is there autocorrelation in relationship warmth?
• Now, include WarmthYesterday in our model
• model.auto <- lmer(WarmthToday ~
1 + Day + WarmthYesterday +
(1 + Day + WarmthYesterday|Couple),
data=relationship)
Testing for Autocorrelation
• Non-significant linear effect: No consistent
increase/decrease in warmth over these 10 days
• But, significant autocorrelation: Adjacent days are
more similar in warmth towards partner
• Random walk
1 2 3 4 5
L I N E A R T R E N D
X
Autocorrelation
• These are examples of autocorrelation
Couple 01 Couple 02
Week 11.2: Autocorrelation
! Autocorrelation
! Introduction
! Testing for Autocorrelation
! Visualizing Autocorrelation
! Direction & Lag
! Why Does Autocorrelation Matter?
! Lab
Visualization of Autocorrelation
• Visualization of the autocorrelation
• With package languageR:
• acf.fnc(xxx ,
time='xxx ',
x=' ',
group=' ')
Variable that identifies the time point
Dependent variable
Variable with the level-2 grouping
factor (e.g., subjects or schools).
Needs to be a FACTOR variable
Dataframe name
Baayen & Milin, 2010
Visualization of Autocorrelation
• Visualization of the autocorrelation
• With package languageR:
• acf.fnc(relationship,
time='Day',
x='WarmthToday',
group='Couple')
Variable that identifies the time point
Dependent variable
Variable with the level-2 grouping
factor (e.g., subjects or schools).
Needs to be a FACTOR variable
Dataframe name
Baayen & Milin, 2010
Lag
Acf
-0.5
0.0
0.5
1.0
0 2 4 6 8
Couple01 Couple02
0 2 4 6 8
Couple03 Couple04
0 2 4 6 8
Couple05 Couple06
0 2 4 6 8
Couple07
Couple08 Couple09 Couple10 Couple11 Couple12 Couple13
-0.5
0.0
0.5
1.0
Couple14
-0.5
0.0
0.5
1.0
Couple15 Couple16 Couple17 Couple18 Couple19 Couple20 Couple21
Couple22 Couple23 Couple24 Couple25 Couple26 Couple27
-0.5
0.0
0.5
1.0
Couple28
-0.5
0.0
0.5
1.0
Couple29 Couple30 Couple31 Couple32 Couple33 Couple34 Couple35
Couple36
0 2 4 6 8
Couple37 Couple38
0 2 4 6 8
Couple39
-0.5
0.0
0.5
1.0
Couple40
One box
per
couple
Height of the second
line indicates strength of
autocorrelation for that
couple
Week 11.2: Autocorrelation
! Autocorrelation
! Introduction
! Testing for Autocorrelation
! Visualizing Autocorrelation
! Direction & Lag
! Why Does Autocorrelation Matter?
! Lab
Direction of Autocorrelation
• Positive autocorrelation—Having more of something
at time t means you have more of it at time t+1
• More warmth on day 3 # More warmth on day 4
• Longer RT on one trial # Longer RT on the next trial
• Negative autocorrelation—Having more
at time t means you have less at t+1
• e.g., homeostatic processes
• Very hungry at time t # Get something
to eat # Not hungry at time t+1
• Stock prices: Price increases # People
sell the stock # Price decreases
• Both analyzed the same way—just look at the sign to
understand the effect
Positive autocorrelation.
This bar would be < 0 if
it were a negative
autocorrelation.
Lag
Acf
-0.5
0.0
0.5
1.0
0 2 4 6 8
Couple01 Couple02
0 2 4 6 8
Couple03 Couple04
0 2 4 6 8
Couple05 Couple06
0 2 4 6 8
Couple07
Couple08 Couple09 Couple10 Couple11 Couple12 Couple13
-0.5
0.0
0.5
1.0
Couple14
-0.5
0.0
0.5
1.0
Couple15 Couple16 Couple17 Couple18 Couple19 Couple20 Couple21
Couple22 Couple23 Couple24 Couple25 Couple26 Couple27
-0.5
0.0
0.5
1.0
Couple28
-0.5
0.0
0.5
1.0
Couple29 Couple30 Couple31 Couple32 Couple33 Couple34 Couple35
Couple36
0 2 4 6 8
Couple37 Couple38
0 2 4 6 8
Couple39
-0.5
0.0
0.5
1.0
Couple40
Autocorrelation: Lag
• Autocorrelation can happen at different time
scales or lags
• Most common is lag 1: an observation correlates
with the next one
1 2 3 4 5
Autocorrelation: Lag
• Autocorrelation can happen at different time
scales or lags
• Most common is lag 1: an observation correlates
with the next one
1 2 3 4 5
Autocorrelation: Lag
• Autocorrelation can happen at different time
scales or lags
• Most common is lag 1: an observation correlates
with the next one
• Lag 2: an observation correlates not with the next
observation, but the one two time points later
• Like the (false) idea that twins “skip a generation”
• Effects that recur, but not immediately (e.g.,
earthquakes)
1 2 3 4 5
Autocorrelation: Lag
• Autocorrelation can happen at different time
scales or lags
• Most common is lag 1: an observation correlates
with the next one
• Lag 2: an observation correlates not with the next
observation, but the one two time points later
• Like the (false) idea that twins “skip a generation”
• Lag 3, Lag 4, etc…
• Mood might have a lag 7 autocorrelation –
weekly change (sad Monday, happy Friday)
• But, be careful with autocorrelations >1—is
there a theoretically plausible reason to
expect them?
Lag
1
autocorrelation
Lag
2
autocorrelation
Lag
3
autocorrelation
Leftmost line
is lag 0—i.e.,
the correlation
of an
observation
with itself
This will
always be 1
It’s shown for
purposes of
comparison
Lag
Acf
-0.5
0.0
0.5
1.0
0 2 4 6 8
Couple01 Couple02
0 2 4 6 8
Couple03 Couple04
0 2 4 6 8
Couple05 Couple06
0 2 4 6 8
Couple07
Couple08 Couple09 Couple10 Couple11 Couple12 Couple13
-0.5
0.0
0.5
1.0
Couple14
-0.5
0.0
0.5
1.0
Couple15 Couple16 Couple17 Couple18 Couple19 Couple20 Couple21
Couple22 Couple23 Couple24 Couple25 Couple26 Couple27
-0.5
0.0
0.5
1.0
Couple28
-0.5
0.0
0.5
1.0
Couple29 Couple30 Couple31 Couple32 Couple33 Couple34 Couple35
Couple36
0 2 4 6 8
Couple37 Couple38
0 2 4 6 8
Couple39
-0.5
0.0
0.5
1.0
Couple40
Testing Autocorrelation, continued
• Does our lag 1 autocorrelation account for the
sequential dependency?
• Examine the autocorrelation of the model
residuals
• relationship %>% mutate(resids =
resid(model.auto)) -> relationship
• Now run acf.fnc() on resids rather than
WarmthToday
Baayen & Milin, 2010
Lag
Acf
-0.5
0.0
0.5
1.0
0 2 4 6 8
Couple01 Couple02
0 2 4 6 8
Couple03 Couple04
0 2 4 6 8
Couple05 Couple06
0 2 4 6 8
Couple07
Couple08 Couple09 Couple10 Couple11 Couple12 Couple13
-0.5
0.0
0.5
1.0
Couple14
-0.5
0.0
0.5
1.0
Couple15 Couple16 Couple17 Couple18 Couple19 Couple20 Couple21
Couple22 Couple23 Couple24 Couple25 Couple26 Couple27
-0.5
0.0
0.5
1.0
Couple28
-0.5
0.0
0.5
1.0
Couple29 Couple30 Couple31 Couple32 Couple33 Couple34 Couple35
Couple36
0 2 4 6 8
Couple37 Couple38
0 2 4 6 8
Couple39
-0.5
0.0
0.5
1.0
Couple40 No consistent
autocorrelation
remaining in the
data
Week 11.2: Autocorrelation
! Autocorrelation
! Introduction
! Testing for Autocorrelation
! Visualizing Autocorrelation
! Direction & Lag
! Why Does Autocorrelation Matter?
! Lab
Why Does Autocorrelation Matter?
• Autocorrelation can be an interesting research
question in its own right
• Important for model assumptions
• A simple growth-curve model:
• Assumes that time matters only insofar
as there’s a general increase/decrease with time
• Otherwise, all observations from a couple equally
similar or dissimilar … error terms independent
=
Warmth
Yi(j) γ00
Overall
baseline
Time
γ10x1(j)
+ U0j
Random
intercept for
couple
+ Error term—
independent,
identically
distributed
Ei(j)
+
Why Does Autocorrelation Matter?
• Autocorrelation can be an interesting research
question in its own right
• Important for model assumptions
• Assumption all observations from a couple equally
similar or dissimilar … error terms independent
• Not true if there’s autocorrelation … observations
similar in time dependent on one another
• Underestimates
standard error
# inflates Type I
error 1 2 3 4 5
L I N E A R T R E N D
Week 11.2: Autocorrelation
! Autocorrelation
! Introduction
! Testing for Autocorrelation
! Visualizing Autocorrelation
! Direction & Lag
! Why Does Autocorrelation Matter?
! Lab
1 of 41

Recommended

Mixed Effects Models - Growth Curve Analysis by
Mixed Effects Models - Growth Curve AnalysisMixed Effects Models - Growth Curve Analysis
Mixed Effects Models - Growth Curve AnalysisScott Fraundorf
201 views62 slides
Mixed Effects Models - Empirical Logit by
Mixed Effects Models - Empirical LogitMixed Effects Models - Empirical Logit
Mixed Effects Models - Empirical LogitScott Fraundorf
122 views30 slides
Mixed Effects Models - Fixed Effects by
Mixed Effects Models - Fixed EffectsMixed Effects Models - Fixed Effects
Mixed Effects Models - Fixed EffectsScott Fraundorf
222 views58 slides
Mixed Effects Models - Introduction by
Mixed Effects Models - IntroductionMixed Effects Models - Introduction
Mixed Effects Models - IntroductionScott Fraundorf
200 views57 slides
Mixed Effects Models - Centering and Transformations by
Mixed Effects Models - Centering and TransformationsMixed Effects Models - Centering and Transformations
Mixed Effects Models - Centering and TransformationsScott Fraundorf
144 views45 slides
Mixed Effects Models - Simple and Main Effects by
Mixed Effects Models - Simple and Main EffectsMixed Effects Models - Simple and Main Effects
Mixed Effects Models - Simple and Main EffectsScott Fraundorf
619 views90 slides

More Related Content

What's hot

Mixed Effects Models - Effect Size by
Mixed Effects Models - Effect SizeMixed Effects Models - Effect Size
Mixed Effects Models - Effect SizeScott Fraundorf
261 views60 slides
Mixed Effects Models - Orthogonal Contrasts by
Mixed Effects Models - Orthogonal ContrastsMixed Effects Models - Orthogonal Contrasts
Mixed Effects Models - Orthogonal ContrastsScott Fraundorf
361 views68 slides
Mixed Effects Models - Random Intercepts by
Mixed Effects Models - Random InterceptsMixed Effects Models - Random Intercepts
Mixed Effects Models - Random InterceptsScott Fraundorf
185 views79 slides
Exploratory by
Exploratory Exploratory
Exploratory toby2036
1.5K views99 slides
Mixed Effects Models - Signal Detection Theory by
Mixed Effects Models - Signal Detection TheoryMixed Effects Models - Signal Detection Theory
Mixed Effects Models - Signal Detection TheoryScott Fraundorf
282 views61 slides
Mixed Effects Models - Model Comparison by
Mixed Effects Models - Model ComparisonMixed Effects Models - Model Comparison
Mixed Effects Models - Model ComparisonScott Fraundorf
154 views58 slides

What's hot(20)

Mixed Effects Models - Effect Size by Scott Fraundorf
Mixed Effects Models - Effect SizeMixed Effects Models - Effect Size
Mixed Effects Models - Effect Size
Scott Fraundorf261 views
Mixed Effects Models - Orthogonal Contrasts by Scott Fraundorf
Mixed Effects Models - Orthogonal ContrastsMixed Effects Models - Orthogonal Contrasts
Mixed Effects Models - Orthogonal Contrasts
Scott Fraundorf361 views
Mixed Effects Models - Random Intercepts by Scott Fraundorf
Mixed Effects Models - Random InterceptsMixed Effects Models - Random Intercepts
Mixed Effects Models - Random Intercepts
Scott Fraundorf185 views
Exploratory by toby2036
Exploratory Exploratory
Exploratory
toby20361.5K views
Mixed Effects Models - Signal Detection Theory by Scott Fraundorf
Mixed Effects Models - Signal Detection TheoryMixed Effects Models - Signal Detection Theory
Mixed Effects Models - Signal Detection Theory
Scott Fraundorf282 views
Mixed Effects Models - Model Comparison by Scott Fraundorf
Mixed Effects Models - Model ComparisonMixed Effects Models - Model Comparison
Mixed Effects Models - Model Comparison
Scott Fraundorf154 views
Mixed Effects Models - Post-Hoc Comparisons by Scott Fraundorf
Mixed Effects Models - Post-Hoc ComparisonsMixed Effects Models - Post-Hoc Comparisons
Mixed Effects Models - Post-Hoc Comparisons
Scott Fraundorf679 views
Mixed Effects Models - Random Slopes by Scott Fraundorf
Mixed Effects Models - Random SlopesMixed Effects Models - Random Slopes
Mixed Effects Models - Random Slopes
Scott Fraundorf262 views
Reporting Phi Coefficient test in APA by Ken Plummer
Reporting Phi Coefficient test in APAReporting Phi Coefficient test in APA
Reporting Phi Coefficient test in APA
Ken Plummer34.6K views
Opinion Dynamics on Networks by Mason Porter
Opinion Dynamics on NetworksOpinion Dynamics on Networks
Opinion Dynamics on Networks
Mason Porter182 views
Mixed Effects Models - Crossed Random Effects by Scott Fraundorf
Mixed Effects Models - Crossed Random EffectsMixed Effects Models - Crossed Random Effects
Mixed Effects Models - Crossed Random Effects
Scott Fraundorf295 views
Null hypothesis for phi-coefficient by Ken Plummer
Null hypothesis for phi-coefficientNull hypothesis for phi-coefficient
Null hypothesis for phi-coefficient
Ken Plummer2.2K views
Meta-Prod2Vec: Simple Product Embeddings with Side-Information by recsysfr
Meta-Prod2Vec: Simple Product Embeddings with Side-InformationMeta-Prod2Vec: Simple Product Embeddings with Side-Information
Meta-Prod2Vec: Simple Product Embeddings with Side-Information
recsysfr8K views
Reporting point biserial correlation in apa by Ken Plummer
Reporting point biserial correlation in apaReporting point biserial correlation in apa
Reporting point biserial correlation in apa
Ken Plummer27.7K views
Reporting single sample z-test for proportions by Ken Plummer
Reporting single sample z-test for proportionsReporting single sample z-test for proportions
Reporting single sample z-test for proportions
Ken Plummer4.5K views
Loftus and palmer by Sophie Gunns
Loftus and palmerLoftus and palmer
Loftus and palmer
Sophie Gunns2.6K views

Similar to Mixed Effects Models - Autocorrelation

Correlation coefficient and it’s use in day to.pptx by
Correlation coefficient and it’s use in day to.pptxCorrelation coefficient and it’s use in day to.pptx
Correlation coefficient and it’s use in day to.pptxPrathamSiddannavar
4 views9 slides
Integrated Math 2 Section 1-4 and 1-5 by
Integrated Math 2 Section 1-4 and 1-5Integrated Math 2 Section 1-4 and 1-5
Integrated Math 2 Section 1-4 and 1-5Jimbo Lamb
506 views44 slides
Illogical frameworks by
Illogical frameworksIllogical frameworks
Illogical frameworksSteve Powell
217 views15 slides
Rates Of Reaction Essay Example by
Rates Of Reaction Essay ExampleRates Of Reaction Essay Example
Rates Of Reaction Essay ExampleCustom Papers Online Singapore
5 views22 slides
Topic 5 (multiple regression) by
Topic 5 (multiple regression)Topic 5 (multiple regression)
Topic 5 (multiple regression)Ryan Herzog
42 views19 slides
Topic 5 (multiple regression) by
Topic 5 (multiple regression)Topic 5 (multiple regression)
Topic 5 (multiple regression)Ryan Herzog
126 views19 slides

Similar to Mixed Effects Models - Autocorrelation(20)

Correlation coefficient and it’s use in day to.pptx by PrathamSiddannavar
Correlation coefficient and it’s use in day to.pptxCorrelation coefficient and it’s use in day to.pptx
Correlation coefficient and it’s use in day to.pptx
Integrated Math 2 Section 1-4 and 1-5 by Jimbo Lamb
Integrated Math 2 Section 1-4 and 1-5Integrated Math 2 Section 1-4 and 1-5
Integrated Math 2 Section 1-4 and 1-5
Jimbo Lamb506 views
Illogical frameworks by Steve Powell
Illogical frameworksIllogical frameworks
Illogical frameworks
Steve Powell217 views
Topic 5 (multiple regression) by Ryan Herzog
Topic 5 (multiple regression)Topic 5 (multiple regression)
Topic 5 (multiple regression)
Ryan Herzog42 views
Topic 5 (multiple regression) by Ryan Herzog
Topic 5 (multiple regression)Topic 5 (multiple regression)
Topic 5 (multiple regression)
Ryan Herzog126 views
· Self-Assessment· InterpretationValues and Moral Survey of St by LesleyWhitesidefv
· Self-Assessment· InterpretationValues and Moral Survey of St· Self-Assessment· InterpretationValues and Moral Survey of St
· Self-Assessment· InterpretationValues and Moral Survey of St
Resourcd File by Resourcd
Resourcd FileResourcd File
Resourcd File
Resourcd178 views
B1 nurturing your relationship by acornorganic
B1 nurturing your relationshipB1 nurturing your relationship
B1 nurturing your relationship
acornorganic841 views
What is A/B-testing? An Introduction by Axelisys Limited
What is A/B-testing? An IntroductionWhat is A/B-testing? An Introduction
What is A/B-testing? An Introduction
Axelisys Limited950 views
Correlation Tutorial by hokapelli
Correlation TutorialCorrelation Tutorial
Correlation Tutorial
hokapelli3.5K views
BI 102 Lab 2 Writing AssignmentHow did oxygen generation by Elodea.docx by CruzIbarra161
BI 102 Lab 2 Writing AssignmentHow did oxygen generation by Elodea.docxBI 102 Lab 2 Writing AssignmentHow did oxygen generation by Elodea.docx
BI 102 Lab 2 Writing AssignmentHow did oxygen generation by Elodea.docx
CruzIbarra1612 views
Cause and effect essay by Mara Luna
Cause and effect essayCause and effect essay
Cause and effect essay
Mara Luna12.1K views
HSC Chemistry Revision Module 5.pptx by IreneSeulgi1
HSC Chemistry Revision Module 5.pptxHSC Chemistry Revision Module 5.pptx
HSC Chemistry Revision Module 5.pptx
IreneSeulgi180 views
IELTS Task 2 Agree or Disagree Lesson by British Council
IELTS Task 2 Agree or Disagree Lesson IELTS Task 2 Agree or Disagree Lesson
IELTS Task 2 Agree or Disagree Lesson
British Council6.9K views

More from Scott Fraundorf

Mixed Effects Models - Power by
Mixed Effects Models - PowerMixed Effects Models - Power
Mixed Effects Models - PowerScott Fraundorf
127 views60 slides
Mixed Effects Models - Missing Data by
Mixed Effects Models - Missing DataMixed Effects Models - Missing Data
Mixed Effects Models - Missing DataScott Fraundorf
88 views67 slides
Mixed Effects Models - Logit Models by
Mixed Effects Models - Logit ModelsMixed Effects Models - Logit Models
Mixed Effects Models - Logit ModelsScott Fraundorf
127 views71 slides
Mixed Effects Models - Level-2 Variables by
Mixed Effects Models - Level-2 VariablesMixed Effects Models - Level-2 Variables
Mixed Effects Models - Level-2 VariablesScott Fraundorf
119 views41 slides
Mixed Effects Models - Data Processing by
Mixed Effects Models - Data ProcessingMixed Effects Models - Data Processing
Mixed Effects Models - Data ProcessingScott Fraundorf
100 views39 slides
Scott_Fraundorf_Resume by
Scott_Fraundorf_ResumeScott_Fraundorf_Resume
Scott_Fraundorf_ResumeScott Fraundorf
24 views2 slides

More from Scott Fraundorf(6)

Mixed Effects Models - Missing Data by Scott Fraundorf
Mixed Effects Models - Missing DataMixed Effects Models - Missing Data
Mixed Effects Models - Missing Data
Scott Fraundorf88 views
Mixed Effects Models - Logit Models by Scott Fraundorf
Mixed Effects Models - Logit ModelsMixed Effects Models - Logit Models
Mixed Effects Models - Logit Models
Scott Fraundorf127 views
Mixed Effects Models - Level-2 Variables by Scott Fraundorf
Mixed Effects Models - Level-2 VariablesMixed Effects Models - Level-2 Variables
Mixed Effects Models - Level-2 Variables
Scott Fraundorf119 views
Mixed Effects Models - Data Processing by Scott Fraundorf
Mixed Effects Models - Data ProcessingMixed Effects Models - Data Processing
Mixed Effects Models - Data Processing
Scott Fraundorf100 views

Recently uploaded

REPRESENTATION - GAUNTLET.pptx by
REPRESENTATION - GAUNTLET.pptxREPRESENTATION - GAUNTLET.pptx
REPRESENTATION - GAUNTLET.pptxiammrhaywood
138 views26 slides
Java Simplified: Understanding Programming Basics by
Java Simplified: Understanding Programming BasicsJava Simplified: Understanding Programming Basics
Java Simplified: Understanding Programming BasicsAkshaj Vadakkath Joshy
322 views155 slides
Collective Bargaining and Understanding a Teacher Contract(16793704.1).pptx by
Collective Bargaining and Understanding a Teacher Contract(16793704.1).pptxCollective Bargaining and Understanding a Teacher Contract(16793704.1).pptx
Collective Bargaining and Understanding a Teacher Contract(16793704.1).pptxCenter for Integrated Training & Education
95 views57 slides
Narration lesson plan by
Narration lesson planNarration lesson plan
Narration lesson planTARIQ KHAN
61 views11 slides
GCSE Music by
GCSE MusicGCSE Music
GCSE MusicWestHatch
45 views50 slides
JQUERY.pdf by
JQUERY.pdfJQUERY.pdf
JQUERY.pdfArthyR3
81 views22 slides

Recently uploaded(20)

REPRESENTATION - GAUNTLET.pptx by iammrhaywood
REPRESENTATION - GAUNTLET.pptxREPRESENTATION - GAUNTLET.pptx
REPRESENTATION - GAUNTLET.pptx
iammrhaywood138 views
Narration lesson plan by TARIQ KHAN
Narration lesson planNarration lesson plan
Narration lesson plan
TARIQ KHAN61 views
JQUERY.pdf by ArthyR3
JQUERY.pdfJQUERY.pdf
JQUERY.pdf
ArthyR381 views
The Accursed House by Émile Gaboriau by DivyaSheta
The Accursed House  by Émile GaboriauThe Accursed House  by Émile Gaboriau
The Accursed House by Émile Gaboriau
DivyaSheta223 views
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively by PECB
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks EffectivelyISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
ISO/IEC 27001 and ISO/IEC 27005: Managing AI Risks Effectively
PECB 623 views
Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant... by Ms. Pooja Bhandare
Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant...Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant...
Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant...
Ms. Pooja Bhandare133 views
Relationship of psychology with other subjects. by palswagata2003
Relationship of psychology with other subjects.Relationship of psychology with other subjects.
Relationship of psychology with other subjects.
palswagata200352 views
The basics - information, data, technology and systems.pdf by JonathanCovena1
The basics - information, data, technology and systems.pdfThe basics - information, data, technology and systems.pdf
The basics - information, data, technology and systems.pdf
JonathanCovena1146 views
Classification of crude drugs.pptx by GayatriPatra14
Classification of crude drugs.pptxClassification of crude drugs.pptx
Classification of crude drugs.pptx
GayatriPatra14101 views
GCSE Spanish by WestHatch
GCSE SpanishGCSE Spanish
GCSE Spanish
WestHatch48 views
EILO EXCURSION PROGRAMME 2023 by info33492
EILO EXCURSION PROGRAMME 2023EILO EXCURSION PROGRAMME 2023
EILO EXCURSION PROGRAMME 2023
info33492109 views
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx by ISSIP
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptxEIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx
EIT-Digital_Spohrer_AI_Intro 20231128 v1.pptx
ISSIP386 views

Mixed Effects Models - Autocorrelation

  • 1. Course Business ! Lab materials on Canvas ! Package to install for today’s analyses: languageR
  • 2. Week 11.2: Autocorrelation ! Autocorrelation ! Introduction ! Testing for Autocorrelation ! Visualizing Autocorrelation ! Direction & Lag ! Why Does Autocorrelation Matter? ! Lab
  • 3. Longitudinal Designs • Two big questions mixed-effects models can help us answer about longitudinal data: 1) What is the overall trajectory of change across time? " Monday: Growth curve analysis 2) How does an observation at one time point relate to the next time point? " Today: Autocorrelation
  • 4. Autocorrelation • Previously, we looked at general trajectory across time • e.g., kids who are 28 months old have larger vocabs than kids who are 20 months old • But, there may be relations among specific observations • Does reading to your kids a lot one month increase their vocab growth the next month? • Does being in a positive mood one day carry over to the next day? • Does purchasing a particular brand once make you more likely to purchase it again?
  • 5. relationship.csv • One member of a dating couple rates their warmth towards the partner • For each of 10 consecutive days • First, let’s see if WarmthToday consistently increases or decreases across the 10 Days of the study • model.time <- lmer(WarmthToday ~ 1 + Day + (1 + Day|Couple), data=relationship)
  • 6. relationship.csv • No linear increase or decrease in warmth over the 10 days • Makes sense … this is a relatively short timescale
  • 7. Autocorrelation • We found no overall increase/decrease • Nevertheless, succeeding days might be more similar, even if there is no overall trend 1 2 3 4 5 L I N E A R T R E N D
  • 8. Autocorrelation • We found no overall increase/decrease • Nevertheless, succeeding days might be more similar, even if there is no overall trend • If you have warm feelings towards your partner one day, maybe warmer the next, too + 2 3 4 5 L I N E A R T R E N D
  • 9. Autocorrelation • We found no overall increase/decrease • Nevertheless, succeeding days might be more similar, even if there is no overall trend • If you have warm feelings towards your partner one day, maybe warmer the next, too + + 3 4 5 L I N E A R T R E N D
  • 10. Autocorrelation • We found no overall increase/decrease • Nevertheless, succeeding days might be more similar, even if there is no overall trend • If you have warm feelings towards your partner one day, maybe warmer the next, too • If you have negative feelings, maybe less warm the next day + + 3 - 5 L I N E A R T R E N D
  • 11. Autocorrelation • We found no overall increase/decrease • Nevertheless, succeeding days might be more similar, even if there is no overall trend • If you have warm feelings towards your partner one day, maybe warmer the next, too • If you have negative feelings, maybe less warm the next day + + 3 - - L I N E A R T R E N D
  • 12. Autocorrelation • We found no overall increase/decrease • Nevertheless, succeeding days might be more similar, even if there is no overall trend • If you have warm feelings towards your partner one day, maybe warmer the next, too • If you have negative feelings, maybe less warm the next day + + 3 - -
  • 13. Autocorrelation • relationship %>% head(n=10) Couple 01
  • 14. Autocorrelation • These are examples of autocorrelation Couple 01 Couple 02
  • 15. Autocorrelation "Maybe in order to understand mankind, we have to look at that word itself: MANKIND. Basically, it's made up of two separate words, 'mank' and 'ind.' What do these words mean? It's a mystery, and that's why so is mankind.” -- Jack Handey
  • 16. Autocorrelation To understand autocorrelation, we have to look at the two separate words that make it up auto (self) + correlation • Autocorrelation refers to a variable correlating with itself, over time • Examples: • Positive mood in the morning # Positive mood in the afternoon • RT on the previous trial # RT on this trial due to waxing & waning of attention
  • 17. Autocorrelation • These are examples of autocorrelation Couple 01 Couple 02
  • 18. Week 11.2: Autocorrelation ! Autocorrelation ! Introduction ! Testing for Autocorrelation ! Visualizing Autocorrelation ! Direction & Lag ! Why Does Autocorrelation Matter? ! Lab
  • 19. Testing for Autocorrelation • Is there autocorrelation in relationship warmth? • We want to test whether yesterday’s warmth predicts today’s warmth • So, we need to add WarmthYesterday as a variable • With package languageR… • relationship %>% mutate(WarmthYesterday = lags.fnc(relationship, time='Day', depvar='WarmthToday', group='Couple’, lag=1)) -> relationship • For each observation, get the value of WarmthToday from 1 day previous and store in WarmthYesterday Variable that identifies the time point Dependent variable Variable with the level-2 grouping factor (e.g., subjects or schools) Dataframe name Baayen & Milin, 2010
  • 20. Testing for Autocorrelation • Is there autocorrelation in relationship warmth? • We want to test whether yesterday’s warmth predicts today’s warmth • So, we need to add WarmthYesterday as a variable • relationship %>% head(n=13) Day 1 for each couple gets the couple’s mean Baayen & Milin, 2010
  • 21. Testing for Autocorrelation • Is there autocorrelation in relationship warmth? • Now, include WarmthYesterday in our model • model.auto <- lmer(WarmthToday ~ 1 + Day + WarmthYesterday + (1 + Day + WarmthYesterday|Couple), data=relationship)
  • 22. Testing for Autocorrelation • Non-significant linear effect: No consistent increase/decrease in warmth over these 10 days • But, significant autocorrelation: Adjacent days are more similar in warmth towards partner • Random walk 1 2 3 4 5 L I N E A R T R E N D X
  • 23. Autocorrelation • These are examples of autocorrelation Couple 01 Couple 02
  • 24. Week 11.2: Autocorrelation ! Autocorrelation ! Introduction ! Testing for Autocorrelation ! Visualizing Autocorrelation ! Direction & Lag ! Why Does Autocorrelation Matter? ! Lab
  • 25. Visualization of Autocorrelation • Visualization of the autocorrelation • With package languageR: • acf.fnc(xxx , time='xxx ', x=' ', group=' ') Variable that identifies the time point Dependent variable Variable with the level-2 grouping factor (e.g., subjects or schools). Needs to be a FACTOR variable Dataframe name Baayen & Milin, 2010
  • 26. Visualization of Autocorrelation • Visualization of the autocorrelation • With package languageR: • acf.fnc(relationship, time='Day', x='WarmthToday', group='Couple') Variable that identifies the time point Dependent variable Variable with the level-2 grouping factor (e.g., subjects or schools). Needs to be a FACTOR variable Dataframe name Baayen & Milin, 2010
  • 27. Lag Acf -0.5 0.0 0.5 1.0 0 2 4 6 8 Couple01 Couple02 0 2 4 6 8 Couple03 Couple04 0 2 4 6 8 Couple05 Couple06 0 2 4 6 8 Couple07 Couple08 Couple09 Couple10 Couple11 Couple12 Couple13 -0.5 0.0 0.5 1.0 Couple14 -0.5 0.0 0.5 1.0 Couple15 Couple16 Couple17 Couple18 Couple19 Couple20 Couple21 Couple22 Couple23 Couple24 Couple25 Couple26 Couple27 -0.5 0.0 0.5 1.0 Couple28 -0.5 0.0 0.5 1.0 Couple29 Couple30 Couple31 Couple32 Couple33 Couple34 Couple35 Couple36 0 2 4 6 8 Couple37 Couple38 0 2 4 6 8 Couple39 -0.5 0.0 0.5 1.0 Couple40 One box per couple Height of the second line indicates strength of autocorrelation for that couple
  • 28. Week 11.2: Autocorrelation ! Autocorrelation ! Introduction ! Testing for Autocorrelation ! Visualizing Autocorrelation ! Direction & Lag ! Why Does Autocorrelation Matter? ! Lab
  • 29. Direction of Autocorrelation • Positive autocorrelation—Having more of something at time t means you have more of it at time t+1 • More warmth on day 3 # More warmth on day 4 • Longer RT on one trial # Longer RT on the next trial • Negative autocorrelation—Having more at time t means you have less at t+1 • e.g., homeostatic processes • Very hungry at time t # Get something to eat # Not hungry at time t+1 • Stock prices: Price increases # People sell the stock # Price decreases • Both analyzed the same way—just look at the sign to understand the effect
  • 30. Positive autocorrelation. This bar would be < 0 if it were a negative autocorrelation. Lag Acf -0.5 0.0 0.5 1.0 0 2 4 6 8 Couple01 Couple02 0 2 4 6 8 Couple03 Couple04 0 2 4 6 8 Couple05 Couple06 0 2 4 6 8 Couple07 Couple08 Couple09 Couple10 Couple11 Couple12 Couple13 -0.5 0.0 0.5 1.0 Couple14 -0.5 0.0 0.5 1.0 Couple15 Couple16 Couple17 Couple18 Couple19 Couple20 Couple21 Couple22 Couple23 Couple24 Couple25 Couple26 Couple27 -0.5 0.0 0.5 1.0 Couple28 -0.5 0.0 0.5 1.0 Couple29 Couple30 Couple31 Couple32 Couple33 Couple34 Couple35 Couple36 0 2 4 6 8 Couple37 Couple38 0 2 4 6 8 Couple39 -0.5 0.0 0.5 1.0 Couple40
  • 31. Autocorrelation: Lag • Autocorrelation can happen at different time scales or lags • Most common is lag 1: an observation correlates with the next one 1 2 3 4 5 Autocorrelation: Lag • Autocorrelation can happen at different time scales or lags • Most common is lag 1: an observation correlates with the next one 1 2 3 4 5
  • 32. Autocorrelation: Lag • Autocorrelation can happen at different time scales or lags • Most common is lag 1: an observation correlates with the next one • Lag 2: an observation correlates not with the next observation, but the one two time points later • Like the (false) idea that twins “skip a generation” • Effects that recur, but not immediately (e.g., earthquakes) 1 2 3 4 5
  • 33. Autocorrelation: Lag • Autocorrelation can happen at different time scales or lags • Most common is lag 1: an observation correlates with the next one • Lag 2: an observation correlates not with the next observation, but the one two time points later • Like the (false) idea that twins “skip a generation” • Lag 3, Lag 4, etc… • Mood might have a lag 7 autocorrelation – weekly change (sad Monday, happy Friday) • But, be careful with autocorrelations >1—is there a theoretically plausible reason to expect them?
  • 34. Lag 1 autocorrelation Lag 2 autocorrelation Lag 3 autocorrelation Leftmost line is lag 0—i.e., the correlation of an observation with itself This will always be 1 It’s shown for purposes of comparison
  • 35. Lag Acf -0.5 0.0 0.5 1.0 0 2 4 6 8 Couple01 Couple02 0 2 4 6 8 Couple03 Couple04 0 2 4 6 8 Couple05 Couple06 0 2 4 6 8 Couple07 Couple08 Couple09 Couple10 Couple11 Couple12 Couple13 -0.5 0.0 0.5 1.0 Couple14 -0.5 0.0 0.5 1.0 Couple15 Couple16 Couple17 Couple18 Couple19 Couple20 Couple21 Couple22 Couple23 Couple24 Couple25 Couple26 Couple27 -0.5 0.0 0.5 1.0 Couple28 -0.5 0.0 0.5 1.0 Couple29 Couple30 Couple31 Couple32 Couple33 Couple34 Couple35 Couple36 0 2 4 6 8 Couple37 Couple38 0 2 4 6 8 Couple39 -0.5 0.0 0.5 1.0 Couple40
  • 36. Testing Autocorrelation, continued • Does our lag 1 autocorrelation account for the sequential dependency? • Examine the autocorrelation of the model residuals • relationship %>% mutate(resids = resid(model.auto)) -> relationship • Now run acf.fnc() on resids rather than WarmthToday Baayen & Milin, 2010
  • 37. Lag Acf -0.5 0.0 0.5 1.0 0 2 4 6 8 Couple01 Couple02 0 2 4 6 8 Couple03 Couple04 0 2 4 6 8 Couple05 Couple06 0 2 4 6 8 Couple07 Couple08 Couple09 Couple10 Couple11 Couple12 Couple13 -0.5 0.0 0.5 1.0 Couple14 -0.5 0.0 0.5 1.0 Couple15 Couple16 Couple17 Couple18 Couple19 Couple20 Couple21 Couple22 Couple23 Couple24 Couple25 Couple26 Couple27 -0.5 0.0 0.5 1.0 Couple28 -0.5 0.0 0.5 1.0 Couple29 Couple30 Couple31 Couple32 Couple33 Couple34 Couple35 Couple36 0 2 4 6 8 Couple37 Couple38 0 2 4 6 8 Couple39 -0.5 0.0 0.5 1.0 Couple40 No consistent autocorrelation remaining in the data
  • 38. Week 11.2: Autocorrelation ! Autocorrelation ! Introduction ! Testing for Autocorrelation ! Visualizing Autocorrelation ! Direction & Lag ! Why Does Autocorrelation Matter? ! Lab
  • 39. Why Does Autocorrelation Matter? • Autocorrelation can be an interesting research question in its own right • Important for model assumptions • A simple growth-curve model: • Assumes that time matters only insofar as there’s a general increase/decrease with time • Otherwise, all observations from a couple equally similar or dissimilar … error terms independent = Warmth Yi(j) γ00 Overall baseline Time γ10x1(j) + U0j Random intercept for couple + Error term— independent, identically distributed Ei(j) +
  • 40. Why Does Autocorrelation Matter? • Autocorrelation can be an interesting research question in its own right • Important for model assumptions • Assumption all observations from a couple equally similar or dissimilar … error terms independent • Not true if there’s autocorrelation … observations similar in time dependent on one another • Underestimates standard error # inflates Type I error 1 2 3 4 5 L I N E A R T R E N D
  • 41. Week 11.2: Autocorrelation ! Autocorrelation ! Introduction ! Testing for Autocorrelation ! Visualizing Autocorrelation ! Direction & Lag ! Why Does Autocorrelation Matter? ! Lab