-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkingMemoryAnalysis
More file actions
302 lines (249 loc) · 14.8 KB
/
Copy pathWorkingMemoryAnalysis
File metadata and controls
302 lines (249 loc) · 14.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#Load the packages and set the theme
library("tidyverse")
library("tidyr")
library("dplyr")
library("ggplot2")
library("cowplot")
library("afex")
library("ggbeeswarm")
library("emmeans")
theme_set(theme_bw(base_size = 15) + theme(legend.position="bottom"))
##################################################################
# TASK 2 #
##################################################################
##---------------------------------------------------------------------------------------------
## RQ1: "Does a longer versus a shorter gap lead to a retroactive or proactive memory benefit?"
##---------------------------------------------------------------------------------------------
##### OPERATIONALISATION OF THE RESEARCH QUESTIONS ####
# RQ1: a) "Does the duration of unfilled gaps (long vs short) significantly impact serial recall accuracy?"
# b) "Is the effect of gap length on serial recall accuracy moderated by whether the item appears before or after the gap (i.e., relative position)?
# c) "Does a specific gap length provide a retroactive benefit (better accuracy for items before the gap), or a proactive benefit (better accuracy for items after the gap)?"
# RQ2: a) "Does engaging in a secondary task during the gap impact serial recall accuracy VS unfilled gaps of equal length (2.5s)?"
# b) "Is this effect moderated by the relative position of the item to the gap?"
#Operationalising the Research Question:
#Retroactive Benefit = higher accuracy for pre-gap items in conditions with long unfilled gaps compared to short gaps or filled gaps
#Proactive Benefit = higher accuracy for post-gap items in conditions with long unfilled gaps compared to short gaps or filled gaps
#Control condition: filled gap helps control for the passage of time - if performance differs between filled and long gaps, it suggests that free time (not just time passing) is the critical driving force of the effect
# Within-subjects 2 x 3 ANOVA
#IV1 = amount of free time between trials (3 levels: long-gap, short-gap, filled gap)
#IV2 = relative position of serial position to the gap (2 levels: pre-gap or post-gap)
#DV = serial recall accuracy (0 = error, 1 = correct)
#Operationalisations of RQ:
#H1: type of gap (long, 2.5s vs short, 0.5s) has a significantly different effect on serial recall memory
#Test via main effects:
#whether gap length has sig effect on serial recall accuracy, holding relative serial position (retroactive vs proactive memory) constant
#whether or not a gap has sig effect on proactive or retroactive memory holding gap length constant
#H1: the effect of gap type depends on whether the gap is proactive vs retroactive?
#Test via interaction:
#whether the effect of gap length on serial recall accuracy (if there is one) significantly differs between retroactive vs proactive conditions
#simple eff/ contrasts to see where the diff of the diff is
#sign interaction would indicate that the effect of gap type on accuracy differs depending on whether the item is pre- or post-gap
##------------------------------------------------------------------------------
## RQ2: effect of filled vs unfilled gap type on proactive vs retroactive memory
##------------------------------------------------------------------------------
#### SORTING OUT THE DATA #####
#Loading in the data
data("wmgaps")
t2_data <- read_csv("data/wmgaps.csv")
glimpse(t2_data)
#Changing categorical variables into factors and re-labeling
t2_data <- t2_data %>%
mutate(
id = factor(id),
gap_type = factor(gap_type, levels = c("filled", "long", "short"),
labels = c("Filled", "Long", "Short")),
rel_pos = factor(rel_pos, levels = c("pre-gap", "post-gap"),
labels = c("Before Gap", "After Gap")),
)
glimpse(t2_data)
str(t2_data)
# Checking the factor levels:
# unique(t2_data$gap_type)
# unique(t2_data$rel_pos)
# unique(t2_data$id)
# unique(t2_data$accuracy) # I didn't change accuracy to a factor, even though it is binary categorical info, so proportion of correct responses can be calculated from it
#Count number of participants
t2_data %>%
summarise(n_ppnts = n_distinct(id))
#n_ppnts = 111
#Count total number of observations of accuracy
t2_data %>%
summarise(total_observations = n())
#there are 49950 observations, indicating each ppnt had multiple observations (within-subjects design)
# See how many non-missing value observations there are
t2_data %>%
filter(!is.na(accuracy)) %>%
summarise(non_missing_observations = n())
#there are no missing observations (non_missing_observations = 49950)
# Check there are the same number of observations per participant
t2_data %>%
group_by(id) %>%
count() %>%
ungroup() %>%
summarise(all_n_450 = all(n == 450))
#All participants had 450 observations each
# Check if each combination of condition has the same number of observations
t2_data %>%
group_by(gap_type, rel_pos) %>%
summarise(n = n()) %>%
summarise(equal_n_observation = all(n == first(n)))
#returns TRUE for all gap types
# Count number of data entries per subject for each serial position
t2_data %>%
group_by(id, serial_pos) %>%
summarise(n = n())
#All = 90; every participant provides 90 observations for each serial position
##### DESCRIPTIVE ANALYSES ####
# ANOVA models assume continuous data... so accuracy needs to be recalculated into something continuous no??
# Add columns for mean accuracy and standard deviation for each combination of gap type and relative position
t2_desc <- t2_data %>%
group_by(gap_type, rel_pos) %>%
summarise(
mean_accuracy = mean(accuracy),
sd_accuracy = sd(accuracy),
se_accuracy = sd(accuracy)/sqrt(length(accuracy)),
median_accuracy = median(accuracy)) %>%
ungroup()
t2_desc
glimpse(t2_desc)
#
# A tibble: 6 × 6
# gap_type rel_pos mean_accuracy sd_accuracy se_accuracy median_accuracy
# <fct> <fct> <dbl> <dbl> <dbl> <dbl>
# 1 Filled Before Gap 0.625 0.484 0.00531 1
# 2 Filled After Gap 0.511 0.500 0.00548 1
# 3 Long Before Gap 0.665 0.472 0.00517 1
# 4 Long After Gap 0.558 0.497 0.00544 1
# 5 Short Before Gap 0.672 0.469 0.00514 1
# 6 Short After Gap 0.484 0.500 0.00548 0
#Now lets visualise this data with a barchart, as the DV is discreet data
ggplot(t2_desc, aes(x = gap_type,
y = mean_accuracy,
fill = rel_pos)) +
geom_col(position = "dodge") +
scale_fill_manual(values = c("grey30", "grey70")) + #change fill of each bar to APA format (no colour)
labs(title = "Mean Response Accuracy by Gap Type and Relative Position of Items",
x = "Gap Type",
y = "Mean Accuracy",
fill = "Relative Position",
caption = "*Error bars show SE of accuracy") + #Rename title, x axis, y axis and legend title
geom_errorbar(aes(ymin = mean_accuracy - se_accuracy, #adding error bars (SE)
ymax = mean_accuracy + se_accuracy),
position = position_dodge(0.9),
width = 0.03,
alpha = 0.8,
size = 0.3) #making error bars not look silly
##### SET UP 2 X 3 REPEATED MEASURES ANOVA MODEL ####
a1_t2 <- aov_ez("id", "accuracy", t2_data,
within = c("gap_type", "rel_pos"))
a1_t2
# Response: accuracy
# Effect df MSE F ges p.value
# gap_type 1.64, 180.32 0.01 12.90 *** .012 <.001
# rel_pos 1, 110 0.01 348.36 *** .143 <.001
# gap_type:rel_pos 1.91, 210.52 0.00 25.56 *** .012 <.001
# Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘+’ 0.1 ‘ ’ 1
# Sphericity correction method: GG
#Very sig main effects and interaction.
#As interaction is sig, main effects are not clearly interpretable
#Lets look at the afex plot and follow-up tests
####### Plotting ANOVA results
plot1_t2 <- afex_plot(a1_t2, "gap_type", "rel_pos",
error = "within",
legend_title = "Relative Position",
data_geom = ggbeeswarm::geom_beeswarm,
data_arg = list(dodge.width = 0.5,
cex = 0.9)) +
labs(title = "Effect of Relative Position and Gap Type on Mean Accuracy",
x = "Gap Type",
y = "Accuracy")
plot1_t2
##### FOLLOW-UP ANALYSES ######
##### ESTIMATED MARGINAL MEANS #####
em_t2 <- emmeans(a1_t2, c("rel_pos", "gap_type"))
em_t2
# rel_pos gap_type emmean SE df lower.CL upper.CL
# Before.Gap Filled 0.625 0.0158 110 0.593 0.656
# After.Gap Filled 0.511 0.0177 110 0.475 0.546
# Before.Gap Long 0.665 0.0145 110 0.636 0.693
# After.Gap Long 0.558 0.0170 110 0.525 0.592
# Before.Gap Short 0.672 0.0135 110 0.645 0.699
# After.Gap Short 0.484 0.0166 110 0.451 0.517
# Confidence level used: 0.95
#Omnibus test of gap type on accuracy, accounting for rel pos
joint_tests(a1_t2, "gap_type")
# gap_type = Filled:
# model term df1 df2 F.ratio p.value
# rel_pos 1 110 145.630 <.0001
#
# gap_type = Long:
# model term df1 df2 F.ratio p.value
# rel_pos 1 110 119.278 <.0001
#
# gap_type = Short:
# model term df1 df2 F.ratio p.value
# rel_pos 1 110 261.362 <.0001
# Compare Before Gap vs After Gap for each gap type
pairs(em_t2, by = "gap_type", adjust = "holm")
# gap_type = Filled:
# contrast estimate SE df t.ratio p.value
# Before.Gap - After.Gap 0.114 0.00946 110 12.068 <.0001
#
# gap_type = Long:
# contrast estimate SE df t.ratio p.value
# Before.Gap - After.Gap 0.106 0.00974 110 10.921 <.0001
#
# gap_type = Short:
# contrast estimate SE df t.ratio p.value
# Before.Gap - After.Gap 0.188 0.01170 110 16.167 <.0001
#Sig effect of relative position of item to gap for long, short and filled gaps
##### RQ1 CONTRAST TIME #####
#Retroactive benefit = Long - short, before gap
#Proactive effect = Long - short, after gap
# rel_pos gap_type emmean SE df lower.CL upper.CL
# 1 Before.Gap Filled 0.625 0.0158 110 0.593 0.656
# 2 After.Gap Filled 0.511 0.0177 110 0.475 0.546
# 3 Before.Gap Long 0.665 0.0145 110 0.636 0.693
# 4 After.Gap Long 0.558 0.0170 110 0.525 0.592
# 5 Before.Gap Short 0.672 0.0135 110 0.645 0.699
# 6 After.Gap Short 0.484 0.0166 110 0.451 0.517
# Confidence level used: 0.95
con_list1 <- list(con1_retroactive = c(0,0,1,0,-1,0), #long before gap - short before gap
con1_proactive = c(0,0,0,1,0,-1)) #long after gap - short after gap
con1 <- contrast(em_t2, con_list1, adjust = "holm")
con1
# contrast estimate SE df t.ratio p.value
# con_retroactive -0.00769 0.00923 110 -0.833 0.407
# con_proactive 0.07423 0.00917 110 8.091 <.0001
# P value adjustment: holm method for 2 tests
#no significant difference between long vs short gaps for items appearing before the gap (p = 0.407) indicating no retroactive memory benefit
#this suggests that extra free time isn't being used to reherse or consolidate previously seen items
#long gaps improved recall accuracy of items after the gap significantly compared to short gaps (p < .0001)
#suggests a proactive memory benefit: long gaps improved memory of serial position only for items appearing after the gap
#this proactive benefit suggests that the extra time is likely used to recharge cognitive resources, preparing participants better for subsequent information
##### RQ2 CONTRAST TIME #####
#Retroactive Benefit: long - filled for items before gap
#Proactive Benefit: long - filled for items after gap
con_list2 <- list(con2_retroactive = c(-1,0,0,1,0,0), #long before - filled before
con2_proactive = c(0,-1,0,1,0,0)) #long after - filled after
con2 <- contrast(em_t2, con_list2, adjust = "holm")
con2
# contrast estimate SE df t.ratio p.value
# con2_retroactive -0.0664 0.0121 110 -5.503 <.001
# con2_proactive 0.0477 0.0124 110 3.856 <.001
# P value adjustment: holm method for 2 tests
#significant difference between long - filled gaps for items appearing both before and after the gap (p < .0001)
#however, the direction of this difference flips across the two conditions
#there is a strong negative difference between long - filled gaps on recall accuracy (p < .001): suggests that for items presented before the gap, recall accuracy was better for filled gaps than unfilled gaps
#not only do having longer gaps not affect memory performance for items before the gap, filling those gaps with another task actually increases this retroactive memory performance compared to unfilled gaps
#this suggests that having free time after an item actually impairs retroactive memory of it
#Surprisingly, engaging in a secondary task (filling the gap) might help maintain better recall of earlier items, countering the idea that more free time allows for better memory via memory consolidation processes
#This is counterintuitive if assumed that free time is expected to help memory via rehearsal/ consolidation, indicating a different latent memory process is at play here which does not require attentional resources, but infact benefits when attention is engaged in something else.
#In line with the previous results for RQ1, the difference in accuracy between long - filled was positive for items appearing after the gap, suggesting an unfilled gap improves performance only for items appearing after the gap
#this indicates that it is indeed the presence of free time, rather than purely the passing of time, contributing to the proactive memory benefit
#this indicates that there is a latent process at play during the gap, where having more time to restore memory resources for the upcoming items improves memory of them
#suggests that the latent processes involved during the gap is involved in cognitive restoration (that is, recharging resources for the upcoming items), rather than rehersal or consolidation processes of items previously seen
#interestingly, filling the 2.5s of free time with a secondary task actually improves retroactive memory... this is counterintuitive and not in line with the memory consolidation hypothesis
#one possible reason for this is... ????
#overall, results suggest that memory consolidation latent processes are not involved in serial recall memory performance for short temporal time scales like this one, and might require longer than 2.5s to come into play...
#if the gap was long enough e.g., overnight, for example, such that hippocampal replay can occur, then potentially a retroactive memory benefit will be seen. Not seen in short term working memory tasks like this one, more to do with long term memory.