re-do age distribution
People remember switch trials worse than stay trials (p=0006) and this difference is larger in children than adults p = 0.036; in fact, the effect is only present in children p=0.004, but not adults p=0.9 or adolescents p=0.23.
Switching after longer time doing previous task led to even worse memory, with switches after 2 or more being particularly detrimental (age x switch): p = 0.009; but not after 1 switch: p = 0.43;
ggplot(to_plot[switch_1 != ""], aes(Age_cat, sum_mem, col = switch_1)) +
geom_point(position = position_dodge(width = 0.5))+
geom_errorbar(aes(ymin = sum_mem - se, ymax = sum_mem + se),
position = position_dodge(width = 0.5), width = 0, size = 1)+ labs(y= "Age group") +
ggtheme +
labs(x= "",y = "# details \nrecalled", col = "")
#ggsave(filename = "../Figures/switch_stay_mem.png", width = 8, height = 4)
m5 <- df[!Sub %in% c(to_exclude), summaryh(lmer(mem_acc ~ switch_2 * AgeC + (switch_2 * AgeC|Sub)))];m5
## boundary (singular) fit: see ?isSingular
## Warning: Model failed to converge with 1 negative eigenvalue: -1.2e+04
## term
## 1: (Intercept)
## 2: switch_2switch 1
## 3: switch_2switch 2
## 4: AgeC
## 5: switch_2switch 1:AgeC
## 6: switch_2switch 2:AgeC
## results
## 1: b = 0.72, SE = 0.02, t(88) = 47.38, p < .001, r = 0.98
## 2: b = −0.01, SE = 0.009, t(95) = −1.29, p = .202, r = 0.13
## 3: b = −0.02, SE = 0.009, t(2571) = −2.36, p = .018, r = 0.05
## 4: b = 0.006, SE = 0.003, t(62) = 1.75, p = .084, r = 0.22
## 5: b = 4e−04, SE = 0.002, t(170) = 0.23, p = .821, r = 0.02
## 6: b = 0.004, SE = 0.002, t(2338) = 2.28, p = .023, r = 0.05
switch_children <- df[!Sub %in% c(to_exclude), summaryh(lmer(sum_mem ~ switch_1 + (switch_1|Sub))), by = Age_cat];switch_children
## boundary (singular) fit: see ?isSingular
## Warning: Model failed to converge with 1 negative eigenvalue: -1.4e+03
## boundary (singular) fit: see ?isSingular
## Age_cat term
## 1: Child (Intercept)
## 2: Child switch_1switch
## 3: Adolescent (Intercept)
## 4: Adolescent switch_1switch
## 5: Adult (Intercept)
## 6: Adult switch_1switch
## results
## 1: b = 1.51, SE = 0.06, t(37) = 24.98, p < .001, r = 0.97
## 2: b = −0.08, SE = 0.03, t(603) = −3.05, p = .002, r = 0.12
## 3: b = 1.63, SE = 0.08, t(30) = 21.18, p < .001, r = 0.97
## 4: b = −0.04, SE = 0.03, t(30) = −1.26, p = .219, r = 0.22
## 5: b = 1.63, SE = 0.08, t(20) = 19.81, p < .001, r = 0.98
## 6: b = 0.004, SE = 0.04, t(108) = 0.09, p = .925, r = 0.009
ggplot(to_plot2[switch_2 != ""], aes(Age_cat, sum_mem, col = switch_2)) +
geom_point(position = position_dodge(width = 0.5))+
geom_errorbar(aes(ymin = sum_mem - se, ymax = sum_mem + se),
position = position_dodge(width = 0.5), width = 0, size = 1)+ labs(y= "Age group") +
ggtheme +
labs(x= "",y = "# details \nrecalled", col = "trial type")
#ggsave(filename = "../Figures/switch_stay_mem_2.png", width = 8, height = 4)
switch2_age <- df[!Sub %in% c(to_exclude), summaryh(lmer(sum_mem ~ switch_2 * AgeC + (switch_1 * AgeC|Sub)))];switch2_age
## boundary (singular) fit: see ?isSingular
## term
## 1: (Intercept)
## 2: switch_2switch 1
## 3: switch_2switch 2
## 4: AgeC
## 5: switch_2switch 1:AgeC
## 6: switch_2switch 2:AgeC
## results
## 1: b = 1.57, SE = 0.04, t(88) = 38.75, p < .001, r = 0.97
## 2: b = −0.04, SE = 0.02, t(2021) = −1.76, p = .079, r = 0.04
## 3: b = −0.07, SE = 0.02, t(2359) = −3.07, p = .002, r = 0.06
## 4: b = 0.02, SE = 0.009, t(75) = 2.10, p = .039, r = 0.24
## 5: b = 0.004, SE = 0.005, t(1192) = 0.83, p = .405, r = 0.02
## 6: b = 0.01, SE = 0.005, t(1365) = 2.69, p = .007, r = 0.07
For remembered items, individuals remembered more details on stay than switches >1), p = 0.03, though this effect did not differ by age p = 0.1., However, only children show the effect (p=0.011),not adolescents or adults (ps > .28).
Same idea with switches that happen after more than 2 trials of the previous task.
#remembered_only_switch <- df[!Sub %in% c(to_exclude) & sum_mem > 0, summaryh(lmer(sum_mem ~ switch_1 * AgeC + (switch_1 * AgeC|Sub)))];remembered_only_switch
#remembered_only_switch_sep <- df[!Sub %in% c(to_exclude) & sum_mem > 0, summaryh(lmer(sum_mem ~ switch_1 + (switch_1|Sub))), by = Age_cat];remembered_only_switch_sep
#switch_children <- df[!Sub %in% c(to_exclude) & sum_mem > 0, summaryh(lmer(sum_mem ~ switch_2 * AgeC + #(switch_2 * AgeC|Sub)))]; switch_children
#switch_children_sep2 <- df[!Sub %in% c(to_exclude) & sum_mem > 0, summaryh(lmer(sum_mem ~ switch_2+ (switch_2 |Sub))), by = Age_cat]; switch_children_sep2
to_plot = df[sum_mem > 0, .(sum_mem = mean(sum_mem)), by = .(Sub, Age, Age_cat, switch_1)]
to_plot = seWithin(data = to_plot[switch_1 != ""], measurevar = "sum_mem", idvar = 'Sub', betweenvars = 'Age_cat', withinvars = 'switch_1')
## Automatically converting the following non-factors to factors: Age_cat, switch_1
## Joining, by = c("Sub", "Age_cat")Joining, by = c("Age_cat", "switch_1", "N")Factors have been converted to characters.
## Confidence intervals: 0.95
##
## Age_cat switch_1 N sum_mem sd se ci
## 1: Adolescent stay 32 2.167988 0.10115977 0.01788269 0.03647199
## 2: Adolescent switch 32 2.131120 0.10115977 0.01788269 0.03647199
## 3: Adult stay 21 2.241667 0.09436557 0.02059226 0.04295469
## 4: Adult switch 21 2.245252 0.09436557 0.02059226 0.04295469
## 5: Child stay 39 2.148982 0.07204310 0.01153613 0.02335367
## 6: Child switch 39 2.095018 0.07204310 0.01153613 0.02335367
to_plot$Age_cat <- relevel(x = as.factor(to_plot$Age_cat), ref = "Child")
ggplot(to_plot[switch_1 != ""], aes(Age_cat, sum_mem, col = switch_1)) +
geom_point(position = position_dodge(width = 0.5))+
geom_errorbar(aes(ymin = sum_mem - se, ymax = sum_mem + se),
position = position_dodge(width = 0.5), width = 0, size = 1)+ labs(y= "Age group") +
ggtheme +
labs(x= "",y = "# details \nrecalled", col = "")
What about just forgotten and remembered? In general, there’s a negative effect of switching (p=.046), but the effect isn’t different by age (p=.17). The effect is only there in children, marginally.
For switch2, there is a general effect p = 0.04, and an interaction p = 0.029. Children show the effect p=0.01, but not adults or adolescents p > 0.6.
# switch 1 for remembered versus forgotten
to_plot = df[, .(mem_acc = mean(mem_acc)), by = .(Sub, Age, Age_cat, switch_1)]
to_plot = seWithin(data = to_plot[switch_1 != ""], measurevar = "mem_acc", idvar = 'Sub', betweenvars = 'Age_cat', withinvars = 'switch_1')
## Automatically converting the following non-factors to factors: Age_cat, switch_1
## Joining, by = c("Sub", "Age_cat")Joining, by = c("Age_cat", "switch_1", "N")Factors have been converted to characters.
## Confidence intervals: 0.95
##
## Age_cat switch_1 N mem_acc sd se ci
## 1: Adolescent stay 31 0.7436316 0.04903251 0.008806499 0.01798527
## 2: Adolescent switch 31 0.7301481 0.04903251 0.008806499 0.01798527
## 3: Adult stay 21 0.7244542 0.03431898 0.007489015 0.01562181
## 4: Adult switch 21 0.7217002 0.03431898 0.007489015 0.01562181
## 5: Child stay 35 0.7075545 0.04701456 0.007946910 0.01615006
## 6: Child switch 32 0.6916022 0.04908724 0.008677480 0.01769784
to_plot$Age_cat <- relevel(x = as.factor(to_plot$Age_cat), ref = "Child")
ggplot(to_plot[switch_1 != ""], aes(Age_cat, mem_acc, col = switch_1)) +
geom_point(position = position_dodge(width = 0.5))+
geom_errorbar(aes(ymin = mem_acc - se, ymax = mem_acc + se),
position = position_dodge(width = 0.5), width = 0, size = 1)+ labs(y= "Age group") +
ggtheme +
labs(x= "",y = "memory accuracy", col = "")
mem_acc_switch <- df[!Sub %in% c(to_exclude), summaryh(glmer(mem_acc ~ switch_1 * AgeC + (switch_1 * AgeC|Sub), family = "binomial"))]; mem_acc_switch
## boundary (singular) fit: see ?isSingular
## term
## 1: (Intercept)
## 2: switch_1switch
## 3: AgeC
## 4: switch_1switch:AgeC
## results
## 1: b = 1.07, SE = 0.08, z(15868) = 12.60, p < .001, r = 0.28
## 2: b = −0.07, SE = 0.04, z(15868) = −1.68, p = .092, r = −0.02
## 3: b = 0.03, SE = 0.02, z(15868) = 1.54, p = .124, r = 0.01
## 4: b = 0.01, SE = 0.009, z(15868) = 1.07, p = .284, r = 0
mem_acc_switch_set <- df[!Sub %in% c(to_exclude), summaryh(glmer(mem_acc ~ switch_1 + (switch_1|Sub), family = "binomial")), by = Age_cat]; mem_acc_switch_set
## boundary (singular) fit: see ?isSingular
## boundary (singular) fit: see ?isSingular
## Age_cat term
## 1: Child (Intercept)
## 2: Child switch_1switch
## 3: Adolescent (Intercept)
## 4: Adolescent switch_1switch
## 5: Adult (Intercept)
## 6: Adult switch_1switch
## results
## 1: b = 0.95, SE = 0.12, z(6673) = 7.65, p < .001, r = 0.25
## 2: b = −0.10, SE = 0.06, z(6673) = −1.62, p = .106, r = −0.03
## 3: b = 1.23, SE = 0.16, z(5482) = 7.62, p < .001, r = 0.32
## 4: b = −0.07, SE = 0.08, z(5482) = −0.94, p = .348, r = −0.02
## 5: b = 1.07, SE = 0.17, z(3712) = 6.46, p < .001, r = 0.28
## 6: b = −0.003, SE = 0.08, z(3712) = −0.04, p = .971, r = 0
#switch two for remembered vs. forgotten
to_plot = df[, .(mem_acc = mean(mem_acc)), by = .(Sub, Age, Age_cat, switch_2)]
to_plot = seWithin(data = to_plot[switch_2 != ""], measurevar = "mem_acc", idvar = 'Sub', betweenvars = 'Age_cat', withinvars = 'switch_2')
## Automatically converting the following non-factors to factors: Age_cat, switch_2
## Joining, by = c("Sub", "Age_cat")Joining, by = c("Age_cat", "switch_2", "N")Factors have been converted to characters.
## Confidence intervals: 0.95
##
## Age_cat switch_2 N mem_acc sd se ci
## 1: Adolescent stay 31 0.7436316 0.05600191 0.010058240 0.02054167
## 2: Adolescent switch 1 31 0.7260715 0.06355723 0.011415215 0.02331298
## 3: Adolescent switch 2 31 0.7350678 0.05663564 0.010172061 0.02077412
## 4: Adult stay 21 0.7244542 0.03914752 0.008542690 0.01781974
## 5: Adult switch 1 21 0.7214622 0.05478632 0.011955354 0.02493843
## 6: Adult switch 2 21 0.7225276 0.04494256 0.009807270 0.02045761
## 7: Child stay 35 0.7075545 0.05478601 0.009260526 0.01881965
## 8: Child switch 1 32 0.7111810 0.05975776 0.010563780 0.02154497
## 9: Child switch 2 36 0.6664244 0.05502838 0.009171397 0.01861893
to_plot$Age_cat <- relevel(x = as.factor(to_plot$Age_cat), ref = "Child")
ggplot(to_plot[switch_2 != ""], aes(Age_cat, mem_acc, col = switch_2)) +
geom_point(position = position_dodge(width = 0.5))+
geom_errorbar(aes(ymin = mem_acc - se, ymax = mem_acc + se),
position = position_dodge(width = 0.5), width = 0, size = 1)+ labs(y= "Age group") +
ggtheme +
labs(x= "",y = "memory accuracy", col = "")
#mem_acc_switch2 <- df[!Sub %in% c(to_exclude), summaryh(glmer(mem_acc ~ switch_2 * AgeC + (switch_2 * AgeC|Sub), family = "binomial"))];mem_acc_switch2
#mem_acc_switch2_set <- df[!Sub %in% c(to_exclude), summaryh(lmer(mem_acc ~ switch_2 + (switch_2|Sub), family = "binomial")), by = Age_cat];mem_acc_switch2_set
Is there a general effect of switching, such that memory get parametrically worse the more difficult the switch?
NO, not when you remove stay trials. Ignore the below (it includes stay trials as switch_0) Details: from 0-1 In general, memory gets worse the longer you have been doing the previous task; Moreover, the effect of switching is more detrimental in children than adults (or across age, continuously); in fact, switching doesn’t parametrically impair memory in adults, but it does in children
Details: Among remembered items: No age interaction p = 0.4, but a general effect p = 0.23; only children are affected p = 0.01
Remembered or forgotten: marginally general effect p = 0.71; interaction p = 0.03; effect is present in children only p = 0.04, but not adults or adolescents ps > 0.4.
#para_switch <- df[, summaryh(lmer(sum_mem ~ switch_all_num * AgeC + (switch_all_num * AgeC ||Sub)))];para_switch
#para_switch2 <- df[switch_1 == 'switch', summaryh(lmer(sum_mem ~ switch_all_num * AgeC + (switch_all_num * AgeC||Sub)))];para_switch2
#para_switch_sep <- df[, summaryh(lmer(sum_mem ~ switch_all_num + (switch_all_num ||Sub))), by = Age_cat];para_switch_sep
#para_switch2 <- df[sum_mem > 0, summaryh(lmer(sum_mem ~ switch_all_num * AgeC + (switch_all_num * AgeC ||Sub)))];para_switch2
#para_switch_sep2 <- df[sum_mem > 0, summaryh(lmer(sum_mem ~ switch_all_num + (switch_all_num ||Sub))), by = Age_cat];para_switch_sep2
#para_switch3 <- df[, summaryh(lmer(mem_acc ~ switch_all_num * AgeC + (switch_all_num * AgeC ||Sub)))];para_switch3
#para_switch_sep3 <- df[, summaryh(lmer(mem_acc ~ switch_all_num + (switch_all_num ||Sub))), by = Age_cat];para_switch_sep3
remembered_items = df[sum_mem > 0, ]
remembered_items[mem_acc == 1, .(details = mean(sum_mem)), by= .(Sub, Age)][, summaryh(lm(details ~ Age))]
## term results
## 1: (Intercept) b = 1.99, SE = 0.08, t(90) = 24.92, p < .001, r = 0.93
## 2: Age b = 0.01, SE = 0.005, t(90) = 2.24, p = .028, r = 0.23
remembered_items[mem_acc == 1, .(details = mean(sum_mem)), by= .(Sub, Age_cat)]%>%
ggplot(aes(Age_cat, details)) +
stat_summary()
## No summary function supplied, defaulting to `mean_se()`
remembered_items[, .(mem_acc = mean(mem_acc)), by= .(Sub, Age)][, summaryh(lm(mem_acc ~ Age))]
## term
## 1: (Intercept)
## 2: Age
## results
## 1: b = 1.00, SE = 0, t(90) = 1507120436109185.25, p < .001, r = 1.00
## 2: b = 0, SE = 0, t(90) = 1.46, p = .148, r = 0.15
df[, .(mem_acc = mean(mem_acc)), by= .(Sub, Age_cat)]%>%
ggplot(aes(Age_cat, mem_acc)) +
stat_summary()
## Warning: Removed 8 rows containing non-finite values (stat_summary).
## No summary function supplied, defaulting to `mean_se()`
remembered_items[sum_mem > 1.7 & mem_acc == 1, summaryh(lm(sum_mem ~ AgeC))]
## term results
## 1: (Intercept) b = 2.43, SE = 0.005, t(9519) = 476.37, p < .001, r = 0.98
## 2: AgeC b = 0.006, SE = 0.001, t(9519) = 5.14, p < .001, r = 0.05
to_plot <- remembered_items[, .(mean_memory = mean(sum_mem)), by = .(Sub, Age)]
class(to_plot$mean_memory)
## [1] "numeric"
ggplot(to_plot, aes(Age, mean_memory)) +
geom_point() +
stat_smooth(formula = y~x, method = "lm")
to_plot = df[, .(proportion = .N), by = .(Sub, Age_cat, sum_mem)]
to_plot$Age_cat <- relevel(as.factor(to_plot$Age_cat), ref = "Child")
to_plot[!is.na(sum_mem)]%>%
ggplot(aes(as.factor(sum_mem), proportion, col = Age_cat)) +
stat_summary(position = position_dodge(0.5))
## No summary function supplied, defaulting to `mean_se()`
df[, QuestionEC := ifelse(Question == 1, -.05, 0.5)]
df[, unique(QuestionEC)]
## [1] -0.05 0.50
Task performance (categorization accuracy) on switch versus stay trials
df[is.na(RT), Acc := 0 ]
df[is.na(RT), acc_miss := 0]
df[!is.na(RT), acc_miss := 1]
df$Age_cat <- relevel(as.factor(df$Age_cat), ref = "Child")
# stay versus switch task accuracy
df[!is.na(switch_1), .(mean_acc = mean(Acc)), by = .(Sub, switch_1, Age_cat)]%>%
ggplot(aes(Age_cat, mean_acc, col = switch_1)) +
stat_summary(position = position_dodge(0.5)) +
ggtheme
## No summary function supplied, defaulting to `mean_se()`
df[!is.na(switch_1), .(mean_acc = mean(acc_miss)), by = .(Sub, switch_1, Age_cat)]%>%
ggplot(aes(Age_cat, mean_acc, col = switch_1)) +
stat_summary(position = position_dodge(0.5)) +
ggtheme
## No summary function supplied, defaulting to `mean_se()`
#df[, summaryh(glmer(Acc ~ switch_1 + (switch_1|Sub), family = "binomial")), by = Age_cat]
#df[, summaryh(glmer(Acc ~ switch_1 * Age_cat + (switch_1* Age_cat|Sub), family = "binomial"))]
# stay versus switch task accuracy
df[!is.na(switch_2), .(mean_acc = mean(Acc)), by = .(Sub, switch_2, Age_cat)]%>%
ggplot(aes(Age_cat, mean_acc, col = switch_2)) +
stat_summary(position = position_dodge(0.5)) +
ggtheme +
labs(x = "", col = "")
## No summary function supplied, defaulting to `mean_se()`
df[!is.na(switch_2), .(mean_acc = mean(acc_miss)), by = .(Sub, switch_2, Age_cat)]%>%
ggplot(aes(Age_cat, mean_acc, col = switch_2)) +
stat_summary(position = position_dodge(0.5)) +
ggtheme +
labs(x = "", col = "")
## No summary function supplied, defaulting to `mean_se()`
#df[, summaryh(glmer(Acc ~ switch_2 + (switch_2|Sub), family = "binomial")), by = Age_cat]
#df[, summaryh(glmer(Acc ~ switch_2 * Age_cat + (switch_2* Age_cat|Sub), family = "binomial"))]
errors
df$error_prox2 <- NULL
## Warning in set(x, j = name, value = value): Column 'error_prox2' does not
## exist to remove
df[, acc_lag := lag(Acc), by = .(Sub, block)]
df[acc_lag ==0, error_prox := 'post 1']
df[, acc_lead1 := lead(Acc), by = .(Sub, block)]
df[, acc_lead2 := lag(acc_lead1), by = .(Sub, block)]
df[, acc_lead3 := lag(acc_lead2), by = .(Sub, block)]
df[acc_lead1 ==0, error_prox := 'pre1']
df[acc_lead2 ==0, error_prox := 'pre2']
df[acc_lead3 ==0, error_prox := 'pre3']
df[is.na(error_prox), error_prox := "baseline"]
df[, mean(mem_acc), by = .(Sub, error_prox, Age_cat)]%>%
ggplot(aes(Age_cat, V1, col = error_prox)) +
stat_summary(position = position_dodge(0.5))
## Warning: Removed 21 rows containing non-finite values (stat_summary).
## No summary function supplied, defaulting to `mean_se()`
df[!is.na(RT), acc_lag2 := lag(Acc), by = .(Sub, block)]
df[acc_lag2 ==0, error_prox2 := 'post 1']
df[!is.na(RT), acc_lead1b := lead(Acc), by = .(Sub, block)]
df[, acc_lead2b := lag(acc_lead1b), by = .(Sub, block)]
df[, acc_lead3b := lag(acc_lead2b), by = .(Sub, block)]
df[acc_lead1b ==0, error_prox2 := 'pre1']
df[acc_lead2b ==0, error_prox2 := 'pre2']
df[acc_lead3b ==0, error_prox2 := 'pre3']
df[is.na(error_prox2) & !is.na(RT), error_prox2 := "baseline"]
df[, mean(mem_acc), by = .(Sub, error_prox2, Age_cat)]%>%
ggplot(aes(Age_cat, V1, col = error_prox2)) +
stat_summary(position = position_dodge(0.5))
## Warning: Removed 23 rows containing non-finite values (stat_summary).
## No summary function supplied, defaulting to `mean_se()`