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 - -
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
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
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
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
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?
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
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