-
Notifications
You must be signed in to change notification settings - Fork 0
/
e2.qmd
304 lines (225 loc) · 13.8 KB
/
e2.qmd
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
302
303
304
---
title: "Experiment 2"
categories: [Analyses, R, Bayesian]
toc: false
format-links: false
page-layout: full
code-fold: true
cold-tools: true
lightbox: true
execute:
warning: false
format:
html: default
---
```{r}
pacman::p_load(dplyr,purrr,tidyr,tibble,ggplot2,
brms,tidybayes, rstanarm,emmeans,broom,bayestestR,
stringr, here,conflicted, patchwork, knitr,kableExtra)
#options(brms.backend="cmdstanr",mc.cores=4)
options(dplyr.summarise.inform = FALSE)
walk(c("brms","dplyr","bayestestR"), conflict_prefer_all, quiet = TRUE)
walk(c("Display_Functions","org_functions"), ~ source(here::here(paste0("Functions/", .x, ".R"))))
e2 <- readRDS(here("data/e2_08-04-23.rds"))
e2Sbjs <- e2 |> group_by(id,condit) |> summarise(n=n())
testE2 <- e2 |> filter(expMode2 == "Test")
nbins=5
trainE2 <- e2 |> filter(expMode2=="Train") |> group_by(id,condit, vb) |>
mutate(Trial_Bin = cut( gt.train, breaks = seq(1, max(gt.train),length.out=nbins+1),include.lowest = TRUE, labels=FALSE))
trainE2_max <- trainE2 |> filter(Trial_Bin == nbins, bandInt==600)
# e2 |> group_by(condit, bandOrder) |> summarise(n_distinct(id))
```
### Methods & Procedure
The task and procedure of Experiment 2 was identical to Experiment 1, with the exception that the training and testing bands were reversed (see @fig-design-e2). The Varied group trained on bands 100-300, 350-550, 600-800, and the constant group trained on band 600-800. Both groups were tested from all six bands. A total of 110 participants completed the experiment (Varied: 55, Constant: 55).
```{dot}
//| label: fig-design-e2
//| fig-cap: "Experiment 2 Design. Constant and Varied participants complete different training conditions. The training and testing bands are the reverse of Experiment 1. "
//| fig-width: 8.0
//| fig-height: 2.5
//| fig-responsive: false
//|
//|
/////| column: screen-inset-right
digraph {
graph [layout = dot, rankdir = LR]
node [shape = rectangle, style = filled]
data1 [label = " Varied Training \n100-300\n350-550\n600-800", fillcolor = "#FF0000"]
data2 [label = " Constant Training \n600-800", fillcolor = "#00A08A"]
Test3 [label = " Final Test \n Novel With Feedback \n800-1000\n1000-1200\n1200-1400", fillcolor = "#ECCBAE"]
data1 -> Test1
data2 -> Test1
subgraph cluster {
label = "Test Phase \n(Counterbalanced Order)"
Test1 [label = "Test \nNovel Bands \n800-1000\n1000-1200\n1200-1400", fillcolor = "#ECCBAE"]
Test2 [label = " Test \n Varied Training Bands \n100-300\n350-550\n600-800", fillcolor = "#ECCBAE"]
Test1 -> Test2
}
Test2 -> Test3
}
```
### Results
```{r}
#| label: fig-e2-train-dev
#| fig-cap: Experiment 2 Training Stage. Deviations from target band across training blocks. Lower values represent greater accuracy.
#| eval: TRUE
p1 <- trainE2 |> ggplot(aes(x = Trial_Bin, y = dist, color = condit)) +
stat_summary(geom = "line", fun = mean) +
stat_summary(geom = "errorbar", fun.data = mean_se, width = .4, alpha = .7) +
facet_wrap(~vb)+
scale_x_continuous(breaks = seq(1, nbins + 1)) +
theme(legend.title=element_blank()) +
labs(y = "Deviation", x="Training Block")
#ggsave(here("Assets/figs/e2_train_deviation.png"), p1, width = 8, height = 4,bg="white")
p1
```
```{r}
bmm_e2_train <- trainE2_max %>%
brm(dist ~ condit,
file=here("data/model_cache/e2_train_deviation"),
data = .,
iter = 2000,
chains = 4,
control = list(adapt_delta = .94, max_treedepth = 13))
mtr2 <- as.data.frame(describe_posterior(bmm_e2_train, centrality = "Mean"))[, c(1,2,4,5,6)]
colnames(mtr2) <- c("Term", "Estimate","95% CrI Lower", "95% CrI Upper", "pd")
cdtr2 <- get_coef_details(bmm_e2_train, "conditVaried")
# mtr2 |> mutate(across(where(is.numeric), \(x) round(x, 2))) |>
# tibble::remove_rownames() |>
# mutate(Term = stringr::str_remove(Term, "b_")) |>
# kable(escape=F,booktabs=T)
```
::: {#tbl-e2-train-dist}
| Term | Estimate | 95% CrI Lower | 95% CrI Upper | pd |
|:-------------|---------:|--------------:|--------------:|----:|
| Intercept | 91.01 | 80.67 | 101.26 | 1 |
| conditVaried | 36.15 | 16.35 | 55.67 | 1 |
: **Experiment 2 - End of training performance**. The Intercept represents the average of the baseline (constant condition), and the conditVaried coefficient reflects the difference between the constant and varied groups. A larger positive coefficient indicates a greater deviation (lower accuracy) for the varied group. {.sm}
:::
\
*Training*. @fig-e2-train-dev presents the deviations across training blocks for both constant and varied training groups. We again compared training performance on the band common to both groups (600-800). The full model results are shown in Table 1. The varied group had a significantly greater deviation than the constant group in the final training block, ( $\beta$ = `r cdtr2$estimate`, 95% CrI \[`r cdtr2$conf.low`, `r cdtr2$conf.high`\]; pd = `r cdtr2$pd`).
```{r}
modelFile <- paste0(here::here("data/model_cache/"), "e2_dist_Cond_Type_RF_2")
bmtd2 <- brm(dist ~ condit * bandType + (1|bandInt) + (1|id),
data=testE2, file=modelFile,
iter=5000,chains=4, control = list(adapt_delta = .94, max_treedepth = 13))
# mted2 <- as.data.frame(describe_posterior(bmtd2, centrality = "Mean"))[, c(1,2,4,5,6)]
# colnames(mted2) <- c("Term", "Estimate","95% CrI Lower", "95% CrI Upper", "pd")
# mted2 |> mutate(across(where(is.numeric), \(x) round(x, 2))) |>
# tibble::remove_rownames() |>
# mutate(Term = stringr::str_remove(Term, "b_")) |>
# kable(booktabs=TRUE)
cd2ted1 <- get_coef_details(bmtd2, "conditVaried")
cd2ted2 <-get_coef_details(bmtd2, "bandTypeExtrapolation")
cd2ted3 <-get_coef_details(bmtd2, "conditVaried:bandTypeExtrapolation")
```
::: {#tbl-e2-bmm-dist}
| Term | Estimate | 95% CrI Lower | 95% CrI Upper | pd |
|:-----------------------------------|---------:|--------------:|--------------:|-----:|
| Intercept | 190.91 | 125.03 | 259.31 | 1.00 |
| conditVaried | -20.58 | -72.94 | 33.08 | 0.78 |
| bandTypeExtrapolation | 38.09 | -6.94 | 83.63 | 0.95 |
| conditVaried:bandTypeExtrapolation | 82.00 | 41.89 | 121.31 | 1.00 |
: **Experiment 2 testing accuracy**. Main effects of condition and band type (training vs. extrapolation), and the interaction between the two factors. Larger coefficient estimates indicate larger deviations from the baselines (constant & trained bands) - and a positive interaction coefficient indicates disproporionate deviation for the varied condition on the extrapolation bands {.striped .hover .sm}
:::
\ \
*Testing Accuracy.* The analysis of testing accuracy examined deviations from the target band as influenced by training condition (Varied vs. Constant) and band type (training vs. extrapolation bands). The results, summarized in @tbl-e2-bmm-dist, reveal no significant main effect of training condition ($\beta$ = `r cd2ted1$estimate`, 95% CrI \[`r cd2ted1$conf.low`, `r cd2ted1$conf.high`\]; pd = `r cd2ted1$pd`). However, the interaction between training condition and band type was significant ($\beta$ = `r cd2ted3$estimate`, 95% CrI \[`r cd2ted3$conf.low`, `r cd2ted3$conf.high`\]; pd = `r cd2ted3$pd`), with the varied group showing disproportionately larger deviations compared to the constant group on the extrapolation bands (see @fig-e2-test-dev).
```{r}
#| label: fig-e2-test-dev
#| fig-cap: A) Deviations from target band during testing without feedback stage. B) Estimated marginal means for the interaction between training condition and band type. Error bars represent 95% confidence intervals.
#| eval: TRUE
condEffects <- function(m,xvar){
m |> ggplot(aes(x = {{xvar}}, y = .value, color = condit, fill = condit)) +
stat_dist_pointinterval() +
stat_halfeye(alpha=.1, height=.5) +
theme(legend.title=element_blank(),axis.text.x = element_text(angle = 45, hjust = 0.5, vjust = 0.5))
}
pe2td <- testE2 |> ggplot(aes(x = vb, y = dist,fill=condit)) +
stat_summary(geom = "bar", position=position_dodge(), fun = mean) +
stat_summary(geom = "errorbar", position=position_dodge(.9), fun.data = mean_se, width = .4, alpha = .7) +
theme(legend.title=element_blank(),axis.text.x = element_text(angle = 45, hjust = 0.5, vjust = 0.5)) +
labs(x="Band", y="Deviation From Target")
pe2ce <- bmtd2 |> emmeans( ~condit + bandType) |>
gather_emmeans_draws() |>
condEffects(bandType) + labs(y="Absolute Deviation From Band", x="Band Type")
p2 <- (pe2td + pe2ce) + plot_annotation(tag_levels= 'A')
#ggsave(here::here("Assets/figs", "e2_test-dev.png"), p2, width=8, height=4, bg="white")
p2
```
```{r}
##| label: tbl-e2-bmm-vx
##| tbl-cap: "Experiment 2. Bayesian Mixed Model Predicting Vx as a function of condition (Constant vs. Varied) and Velocity Band"
e2_vxBMM <- brm(vx ~ condit * bandInt + (1 + bandInt|id),
data=test,file=paste0(here::here("data/model_cache", "e2_testVxBand_RF_5k")),
iter=5000,chains=4,silent=0,
control=list(adapt_delta=0.94, max_treedepth=13))
#GetModelStats(e2_vxBMM ) |> kable(escape=F,booktabs=T, caption="Fit to all 6 bands")
cd2 <- get_coef_details(e2_vxBMM, "conditVaried")
sc2 <- get_coef_details(e2_vxBMM, "bandInt")
intCoef2 <- get_coef_details(e2_vxBMM, "conditVaried:bandInt")
```
::: {#tbl-e2-bmm-vx}
| Term | Estimate | 95% CrI Lower | 95% CrI Upper | pd |
|:-------------|---------:|--------------:|--------------:|-----:|
| Intercept | 362.64 | 274.85 | 450.02 | 1.00 |
| conditVaried | -8.56 | -133.97 | 113.98 | 0.55 |
| Band | 0.71 | 0.58 | 0.84 | 1.00 |
| condit\*Band | -0.06 | -0.24 | 0.13 | 0.73 |
Experiment 2. Bayesian Mixed Model Predicting Vx as a function of condition (Constant vs. Varied) and Velocity Band {.striped .hover .sm}
:::
*Testing Discrimination.* Finally, to assess the ability of both conditions to discriminate between velocity bands, we fit a model predicting velocity as a function of training condition and velocity band, with random intercepts and random slopes for each participant. The full model results are shown in @tbl-e2-bmm-vx. The overall slope on target velocity band predictor was significantly positive, ($\beta$ = `r sc2$estimate`, 95% CrI \[`r sc2$conf.low`, `r sc2$conf.high`\]; pd= `r sc2$pd`), indicating that participants exhibited discrimination between bands. The interaction between slope and condition was not significant, ($\beta$ = `r intCoef2$estimate`, 95% CrI \[`r intCoef2$conf.low`, `r intCoef2$conf.high`\]; pd= `r intCoef2$pd`), suggesting that the two conditions did not differ in their ability to discriminate between bands (see @fig-e2-test-vx).
```{r}
#| label: fig-e2-test-vx
#| fig-cap: E2 testing x velocities. Translucent bands with dash lines indicate the correct range for each velocity band.
#| fig-width: 11
#| fig-height: 9
testE2 %>% group_by(id,vb,condit) |> plot_distByCondit()
```
```{r}
#| label: tbl-e2-bmm-vx
#| fig-cap: Conditional effect of training condition and Band. Ribbons indicate 95% HDI. The steepness of the lines serves as an indicator of how well participants discriminated between velocity bands.
#| fig-height: 9
#| fig-width: 11
condEffects <- function(m,xvar){
m |> ggplot(aes(x = {{xvar}}, y = .value, color = condit, fill = condit)) +
stat_dist_pointinterval() +
stat_halfeye(alpha=.1, height=.5) +
theme(legend.title=element_blank(),axis.text.x = element_text(angle = 45, hjust = 0.5, vjust = 0.5))
}
pe2vce <- e2_vxBMM |> emmeans( ~condit + bandInt,re_formula=NA,
at = list(bandInt = c(100, 350, 600, 800, 1000, 1200))) |>
gather_emmeans_draws() |>
condEffects(bandInt) +
stat_lineribbon(alpha = .25, size = 1, .width = c(.95)) +
scale_x_continuous(breaks = c(100, 350, 600, 800, 1000, 1200),
labels = levels(testE2$vb),
limits = c(0, 1400)) +
scale_y_continuous(expand=expansion(add=100),breaks=round(seq(0,2000,by=200),2)) +
theme(legend.title=element_blank()) +
labs(y="Velcoity", x="Band")
fe <- fixef(e2_vxBMM)[,1]
fixed_effect_bandInt <- fixef(e2_vxBMM)[,1]["bandInt"]
fixed_effect_interaction <- fixef(e2_vxBMM)[,1]["conditVaried:bandInt"]
re <- data.frame(ranef(e2_vxBMM, pars = "bandInt")$id[, ,'bandInt']) |>
rownames_to_column("id") |>
left_join(e2Sbjs,by="id") |>
mutate(adjust= fixed_effect_bandInt + fixed_effect_interaction*(condit=="Varied"),slope = Estimate + adjust )
pid_den2 <- ggplot(re, aes(x = slope, fill = condit)) +
geom_density(alpha=.5) +
geom_vline(xintercept = 1, linetype="dashed",alpha=.5) +
xlim(c(min(re$slope)-.3, max(re$slope)+.3))+
theme(legend.title=element_blank()) +
labs(x="Slope Coefficient",y="Density")
pid_slopes2 <- re |> mutate(id=reorder(id,slope)) |>
ggplot(aes(y=id, x=slope,fill=condit,color=condit)) +
geom_pointrange(aes(xmin=Q2.5+adjust, xmax=Q97.5+adjust)) +
geom_vline(xintercept = 1, linetype="dashed",alpha=.5) +
theme(legend.title=element_blank(),
axis.text.y = element_text(size=6) ) +
labs(x="Estimated Slope", y="Participant") +
ggh4x::facet_wrap2(~condit,axes="all",scales="free_y")
p3 <- (pe2vce + pid_den2 + pid_slopes2) + plot_annotation(tag_levels= 'A')
#ggsave(here::here("Assets/figs", "e2_test-vx.png"), p3,width=9,height=11, bg="white",dpi=600)
p3
```
### Experiment 2 Summary
Experiment 2 extended the findings of Experiment 1 by examining the effects of training variability on extrapolation performance in a visuomotor function learning task, but with reversed training and testing bands. Similar to Experiment 1, the Varied group exhibited poorer performance during training and testing. However unlike experiment 1, the Varied group did not show a significant difference in discrimination between bands.