-
Notifications
You must be signed in to change notification settings - Fork 0
/
plots.Rmd
690 lines (570 loc) · 35.5 KB
/
plots.Rmd
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
---
title: "plots"
output: html_document
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
Load packages and models
```{r}
# packages
library(pacman)
pacman::p_load(
brms,
tidyverse,
bayesplot,
viridis,
data.table,
ggplot2,
BayesCombo,
patchwork,
beepr,
graphics,
lmerTest,
loo,
rlist,
bayestestR,
tidybayes,
ggridges
)
# load models saved in environment, can be run in analysis.Rmd script
# brm_pd_disorder <- readRDS("envr/brm_pd_disorder_2020_20_11.rds")
# brm_pi_disorder <- readRDS("envr/brm_pi_disorder_2020_20_11.rds")
# brm_pv_disorder <- readRDS("envr/brm_pv_disorder_2020_20_11.rds")
# brm_pd_task <- readRDS("envr/brm_pd_task_2020_20_11.rds")
# brm_pi_task <- readRDS("envr/brm_pi_task_2020_20_11.rds")
# brm_pd_task <- readRDS("envr/brm_pv_task_2020_20_11.rds")
# brm_pd_lang <- readRDS("envr/brm_pd_lang_2020_20_11.rds")
# brm_pi_lang <- readRDS("envr/brm_pi_lang_2020_20_11.rds")
# brm_pd_lang <- readRDS("envr/brm_pv_lang_2020_20_11.rds")
# colors for forest plots
# ASD: "#E69F00"
# LHD: "#52854C"
# RHD: "#D16103"
# SCZ: "#0072B2"
```
## FOREST PLOTS
### PAUSE DURATION
```{r}
get_variables(brm_pd_disorder$posterior_model)
# get the effects for each study, and calculate their effect sizes by adding them to the intercept
pd_studies <- spread_draws(brm_pd_disorder$posterior_model,
r_expt_unique_dis[expt_unique_dis, Intercept],
b_disorderlhd,
b_disorderrhd,
b_disorderscz) %>%
separate(expt_unique_dis, c("expt_unique", "disorder"), "_") %>%
mutate(expt_unique_dis = paste0(toupper(disorder), ": ", expt_unique), disorder = toupper(disorder)) %>%
mutate(ES = ifelse(disorder == "RHD", (r_expt_unique_dis + b_disorderrhd),
ifelse(disorder == "LHD", (r_expt_unique_dis + b_disorderlhd),
ifelse(disorder == "SCZ", (r_expt_unique_dis + b_disorderscz), NA))))
# get the overall meta-analytic effect sizes, turn it into long format and make columns similar to the residuals
pd_betas <- spread_draws(brm_pd_disorder$posterior_model, b_disorderlhd, b_disorderrhd, b_disorderscz) %>%
pivot_longer(cols = c("b_disorderrhd", "b_disorderlhd", "b_disorderscz"), names_to = "expt_unique_dis") %>%
rename(ES = value) %>%
separate(expt_unique_dis, c("expt_unique", "disorder"), "_disorder") %>%
mutate(expt_unique_dis = paste0(toupper(disorder), ": ", "Overall Estimated Effect Size"),
disorder = toupper(disorder))
# info to know how to re-factor in next step
pd_studies %>% ungroup %>% group_by(disorder) %>%
summarise(length(unique(expt_unique)))
# combine study specific and overall MA ES, and factor them so that overall comes in the right place
pd_all <- bind_rows(pd_studies, pd_betas) %>%
ungroup() %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "LHD: Overall Estimated Effect Size", after = 5)) %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "RHD: Overall Estimated Effect Size", after = 13)) %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "SCZ: Overall Estimated Effect Size", after = Inf))
# calculate summary stats
pd_sum <- pd_all %>% group_by(expt_unique_dis, disorder, expt_unique) %>% mean_qi(ES)
# plot: 800x400
ggplot(pd_sum, aes(y = reorder(expt_unique_dis, desc(expt_unique_dis)), x = ES)) +
geom_point(aes(colour = disorder)) +
geom_point(data=subset(pd_sum, expt_unique == "b"),aes(colour = disorder), shape=18, size=5) +
geom_errorbarh(aes(xmin = .lower, xmax = .upper, colour = disorder), height=.3, size = 0.6) +
geom_text(data = mutate_if(pd_sum, is.numeric, round, 2), colour = "black",
aes(label = glue::glue("{ES} [{.lower}, {.upper}]"), x = Inf), hjust = "inward", size = 3.5) +
labs(x = "Effect Size (Hedge's g)", y = "Reference", title = "Pause Duration", colour = "Disorder") +
geom_vline(xintercept=0, color='black', linetype='dashed') +
scale_color_manual(values = c("#52854C", "#D16103", "#0072B2")) +
theme_bw() +
theme(axis.text.y = element_text(face = c("bold", rep("plain", 9), "bold", rep("plain", 7), "bold", rep("plain", 5))))
```
### PAUSE DURATION TASK TYPE
```{r}
get_variables(brm_pd_disorder$posterior_model)
# get the residuals for each study
pd_task_residuals <- spread_draws(brm_pd_task$posterior_model, r_expt_unique_dis[expt_unique_dis, Intercept],
`b_disorderlhd:task_typeconstrainedproduction`,
`b_disorderrhd:task_typeconstrainedproduction`) %>%
mutate(expt_unique_dis = gsub("..", ".", expt_unique_dis, fixed = T)) %>%
separate(expt_unique_dis, c("expt_unique", "disorder"), "_", remove = F) %>%
mutate(expt_unique_dis = paste0(toupper(disorder), ": ", expt_unique),
disorder = toupper(disorder))
# get task type info from data
pd_task_info <- brm_pd_task$data %>% ungroup() %>% select(dis_task, expt_unique_dis, task_type) %>%
mutate(expt_unique_dis = gsub(". ", " ", expt_unique_dis, fixed = T),
expt_unique_dis = gsub(" ", ".", expt_unique_dis, fixed = T)) %>%
separate(expt_unique_dis, c("expt_unique", "disorder"), "_", remove = F) %>%
mutate(expt_unique_dis = paste0(toupper(disorder), ": ", expt_unique),
disorder = toupper(disorder))
# merge residuals and info together and calculate effect sizes
pd_task_studies <- merge(pd_task_residuals, pd_task_info, by = c("expt_unique_dis", "disorder", "expt_unique")) %>%
mutate(ES = ifelse(dis_task == "lhd_constrained production", (r_expt_unique_dis + `b_disorderlhd:task_typeconstrainedproduction`),
ifelse(dis_task == "rhd_constrained production", (r_expt_unique_dis + `b_disorderrhd:task_typeconstrainedproduction`),
NA))) %>% filter(!is.na(ES))
# get the overall meta-analytic effect sizes, make it long format and create columns similar to residuals data
pd_task_betas <- spread_draws(brm_pd_task$posterior_model,
`b_disorderlhd:task_typeconstrainedproduction`,
`b_disorderrhd:task_typeconstrainedproduction`) %>%
pivot_longer(cols = c("b_disorderlhd:task_typeconstrainedproduction",
"b_disorderrhd:task_typeconstrainedproduction"), names_to = "expt_unique_dis") %>%
rename(ES = value) %>%
separate(expt_unique_dis, c("expt_unique", "disorder"), "_disorder") %>%
mutate(disorder = toupper(gsub(":task_typeconstrainedproduction", "", disorder, fixed = T)),
expt_unique_dis = paste0(toupper(disorder), ": ", "Overall Estimated Effect Size"))
# info to know how to re-factor in next step
pd_task_studies %>% ungroup %>% group_by(disorder) %>%
summarise(length(unique(expt_unique)))
# combine studies data and betas, and bring them in the right order
pd_task_all <- bind_rows(pd_task_studies, pd_task_betas) %>%
ungroup() %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "LHD: Overall Estimated Effect Size", after = 5)) %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "RHD: Overall Estimated Effect Size", after = 13))
# calculate summary stats
pd_task_sum <- pd_task_all %>% group_by(expt_unique_dis, disorder, expt_unique) %>% mean_qi(ES)
# plot: 800x400
ggplot(pd_task_sum, aes(y = reorder(expt_unique_dis, desc(expt_unique_dis)), x = ES)) +
geom_point(aes(colour = disorder)) +
geom_point(data=subset(pd_task_sum, expt_unique == "b"),aes(colour = disorder), shape=18, size=5) +
geom_errorbarh(aes(xmin = .lower, xmax = .upper, colour = disorder), height=.3, size = .6) +
geom_text(data = mutate_if(pd_task_sum, is.numeric, round, 2), colour = "black",
aes(label = glue::glue("{ES} [{.lower}, {.upper}]"), x = Inf), hjust = "inward", size = 3.5) +
labs(x = "Effect Size (Hedge's g)", y = "Reference", title = "Pause Duration: Constrained Production Task", colour = "Disorder") +
geom_vline(xintercept=0, color='black', linetype='dashed') +
scale_color_manual(values = c("#52854C", "#D16103")) +
theme_bw() +
theme(axis.text.y = element_text(face = c("bold", rep("plain", 7), "bold", rep("plain", 5))))
```
### PAUSE DURATION: LANGUAGE
```{r}
get_variables(brm_pd_lang$posterior_model)
# get the residuals for each study
pd_lang_residuals <- spread_draws(brm_pd_lang$posterior_model,
r_expt_unique_dis[expt_unique_dis, Intercept],
`b_disorderrhd:native_languageEnglish`,
`b_disorderscz:native_languageEnglish`) %>%
mutate(expt_unique_dis = gsub("..", ".", expt_unique_dis, fixed = T)) %>%
separate(expt_unique_dis, c("expt_unique", "disorder"), "_", remove = F) %>%
mutate(expt_unique_dis = paste0(toupper(disorder), ": ", expt_unique),
disorder = toupper(disorder))
# get language info from data
pd_lang_info <- brm_pd_lang$data %>% ungroup() %>% select(dis_lang, expt_unique_dis, native_language) %>%
mutate(expt_unique_dis = gsub(". ", " ", expt_unique_dis, fixed = T),
expt_unique_dis = gsub(" ", ".", expt_unique_dis, fixed = T)) %>%
separate(expt_unique_dis, c("expt_unique", "disorder"), "_", remove = F) %>%
mutate(expt_unique_dis = paste0(toupper(disorder), ": ", expt_unique),
disorder = toupper(disorder))
# merge info and values together and calculate effect sizes
pd_lang_studies <- merge(pd_lang_residuals, pd_lang_info, by = c("expt_unique_dis", "disorder", "expt_unique")) %>%
mutate(ES = ifelse(dis_lang == "rhd_English", (r_expt_unique_dis + `b_disorderrhd:native_languageEnglish`),
ifelse(dis_lang == "scz_English", (r_expt_unique_dis + `b_disorderscz:native_languageEnglish`),
NA))) %>% filter(!is.na(ES))
# get the overall meta-analytic effect sizes, make it long format, create similar columns to studies data
pd_lang_betas <- spread_draws(brm_pd_lang$posterior_model,
`b_disorderrhd:native_languageEnglish`,
`b_disorderscz:native_languageEnglish`) %>%
pivot_longer(cols = c("b_disorderrhd:native_languageEnglish",
"b_disorderscz:native_languageEnglish"), names_to = "expt_unique_dis") %>%
rename(ES = value) %>%
separate(expt_unique_dis, c("expt_unique", "disorder"), "_disorder") %>%
mutate(disorder = toupper(gsub(":native_languageEnglish", "", disorder, fixed = T)),
expt_unique_dis = paste0(toupper(disorder), ": ", "Overall Estimated Effect Size"))
# info to know how to re-factor in next step
pd_lang_studies %>% ungroup %>% group_by(disorder) %>%
summarise(length(unique(expt_unique)))
# combine study specific and overall MA ES
pd_lang_all <- bind_rows(pd_lang_studies, pd_lang_betas) %>%
ungroup() %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "RHD: Overall Estimated Effect Size", after = 5)) %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "SCZ: Overall Estimated Effect Size", after = Inf))
# calculate summary stats
pd_lang_sum <- pd_lang_all %>% group_by(expt_unique_dis, disorder, expt_unique) %>% mean_qi(ES)
# plot: 800x400
ggplot(pd_lang_sum, aes(y = reorder(expt_unique_dis, desc(expt_unique_dis)), x = ES)) +
geom_point(aes(colour = disorder)) +
geom_point(data=subset(pd_lang_sum, expt_unique == "b"),aes(colour = disorder), shape=18, size=5) +
geom_errorbarh(aes(xmin = .lower, xmax = .upper, colour = disorder), height=.3, size = .6) +
geom_text(data = mutate_if(pd_lang_sum, is.numeric, round, 2), colour = "black",
aes(label = glue::glue("{ES} [{.lower}, {.upper}]"), x = Inf), hjust = "inward", size = 3.5) +
labs(x = "Effect Size (Hedge's g)", y = "Reference", title = "Pause Duration: English", colour = "Disorder") +
geom_vline(xintercept=0, color='black', linetype='dashed') +
scale_color_manual(values = c("#D16103", "#0072B2")) +
theme_bw() +
theme(axis.text.y = element_text(face = c("bold", rep("plain", 7), "bold", rep("plain", 5))))
```
### PITCH
```{r}
get_variables(brm_pi_disorder$posterior_model)
# get the effects for each study, and calculate their effect sizes by adding them to the intercept,
# use regex because the way as in pause duration does not work for this model
pi_studies_1 <- gather_draws(brm_pi_disorder$posterior_model,`r_expt_unique_dis.*` , regex = T)
pi_studies_2 <- spread_draws(brm_pi_disorder$posterior_model, b_disorderasd, b_disorderrhd, b_disorderscz)
pi_studies <- merge(pi_studies_1, pi_studies_2) %>%
mutate(.variable = gsub("r_expt_unique_dis\\[|,Intercept\\]", "", .variable)) %>%
separate(.variable, c("expt_unique", "disorder"), "_") %>%
mutate(expt_unique_dis = paste0(toupper(disorder), ": ", expt_unique),
disorder = toupper(disorder),
ES = ifelse(disorder == "ASD", (.value + b_disorderasd),
ifelse(disorder == "RHD", (.value + b_disorderrhd),
ifelse(disorder == "SCZ", (.value + b_disorderscz), NA))))
# get the overall meta-analytic effect sizes, make it long format and add similar columns as in studies data
pi_betas <- spread_draws(brm_pi_disorder$posterior_model, b_disorderasd, b_disorderrhd, b_disorderscz) %>%
pivot_longer(cols = c("b_disorderasd", "b_disorderrhd", "b_disorderscz"), names_to = "expt_unique_dis") %>%
rename(ES = value) %>%
separate(expt_unique_dis, c("expt_unique", "disorder"), "_disorder") %>%
mutate(expt_unique_dis = paste0(toupper(disorder), ": ", "Overall Estimated Effect Size"),
disorder = toupper(disorder))
# to know how to re-factor in next step
pi_studies %>% ungroup %>% group_by(disorder) %>%
summarise(length(unique(expt_unique)))
# combine study specific and overall MA ES
pi_all <- bind_rows(pi_studies, pi_betas) %>%
ungroup() %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "ASD: Overall Estimated Effect Size", after = 25)) %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "RHD: Overall Estimated Effect Size", after = 36)) %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "SCZ: Overall Estimated Effect Size", after = 42))
# calculate summary stats
pi_sum <- pi_all %>% group_by(expt_unique_dis, disorder, expt_unique) %>% mean_qi(ES)
# plot: 800x600
ggplot(pi_sum, aes(y = reorder(expt_unique_dis, desc(expt_unique_dis)), x = ES)) +
geom_point(aes(colour = disorder)) +
#geom_point(data=subset(pi_sum, expt_unique == "b"), aes(colour = disorder), shape=18, size=5) +
geom_errorbarh(aes(xmin = .lower, xmax = .upper, colour = disorder), height=.3, size = .6) +
geom_text(data = mutate_if(pi_sum, is.numeric, round, 2), colour = "black",
aes(label = glue::glue("{ES} [{.lower}, {.upper}]"), x = Inf), hjust = "inward", size = 3) +
labs(x = "Effect Size (Hedge's g)", y = "Reference", title = "Pitch", colour = "Disorder") +
geom_vline(xintercept=0, color='black', linetype='dashed') +
scale_color_manual(values = c("#E69F00", "#D16103", "#0072B2")) +
theme_bw() +
theme(axis.text.y = element_text(face = c("bold", rep("plain", 5), "bold", rep("plain", 10), "bold", rep("plain", 25))))
```
### PITCH LANGUAGE
```{r}
get_variables(brm_pi_lang$posterior_model)
# get the effects for each study
# use regex because the way as in pause duration does not work for this model
pi_lang_residuals_1 <- gather_draws(brm_pi_lang$posterior_model,`r_expt_unique_dis.*` , regex = T)
pi_lang_residuals_2 <- spread_draws(brm_pi_lang$posterior_model, `b_disorderasd:native_languageEnglish`, `b_disorderrhd:native_languageEnglish`)
pi_lang_resiudals <- merge(pi_lang_residuals_1, pi_lang_residuals_2) %>%
mutate(.variable = gsub("r_expt_unique_dis\\[|,Intercept\\]", "", .variable),
.variable = gsub("..(", ".(", .variable, fixed = TRUE)) %>%
separate(.variable, c("expt_unique", "disorder"), "_") %>%
mutate(expt_unique_dis = paste0(toupper(disorder), ": ", expt_unique),
disorder = toupper(disorder))
# get language info from data
pi_lang_info <- brm_pi_lang$data %>% ungroup() %>% select(dis_lang, expt_unique_dis, native_language) %>%
mutate(expt_unique_dis = gsub(". ", " ", expt_unique_dis, fixed = T),
expt_unique_dis = gsub(" ", ".", expt_unique_dis, fixed = T)) %>%
separate(expt_unique_dis, c("expt_unique", "disorder"), "_", remove = F) %>%
mutate(expt_unique_dis = paste0(toupper(disorder), ": ", expt_unique),
disorder = toupper(disorder))
# merge language info and residuals and calculate their effect sizes
pi_lang_studies <- merge(pi_lang_resiudals, pi_lang_info, by = c("expt_unique_dis", "disorder", "expt_unique")) %>%
mutate(ES = ifelse(dis_lang == "asd_English", (.value + `b_disorderasd:native_languageEnglish`),
ifelse(dis_lang == "rhd_English", (.value + `b_disorderrhd:native_languageEnglish`),
NA))) %>% filter(!is.na(ES))
# get overall estimates, make it long format, and make similar columns to the studies data
pi_lang_betas <- spread_draws(brm_pi_lang$posterior_model,
`b_disorderasd:native_languageEnglish`,
`b_disorderrhd:native_languageEnglish`) %>%
pivot_longer(cols = c("b_disorderasd:native_languageEnglish",
"b_disorderrhd:native_languageEnglish"), names_to = "expt_unique_dis") %>%
rename(ES = value) %>%
separate(expt_unique_dis, c("expt_unique", "disorder"), "_disorder") %>%
mutate(disorder = toupper(gsub(":native_languageEnglish", "", disorder, fixed = T)),
expt_unique_dis = paste0(toupper(disorder), ": ", "Overall Estimated Effect Size"))
# to know how to re-factor in next step
pi_lang_studies %>% ungroup %>% group_by(disorder) %>%
summarise(length(unique(expt_unique)))
# combine studies and betas
pi_lang_all <- bind_rows(pi_lang_studies, pi_lang_betas) %>%
ungroup() %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "ASD: Overall Estimated Effect Size", after = 14)) %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "RHD: Overall Estimated Effect Size", after = Inf))
# calculate summary stats
pi_lang_sum <- pi_lang_all %>% group_by(expt_unique_dis, disorder, expt_unique) %>% mean_qi(ES)
# plot: 800x400
ggplot(pi_lang_sum, aes(y = reorder(expt_unique_dis, desc(expt_unique_dis)), x = ES)) +
geom_point(aes(colour = disorder)) +
geom_point(data=subset(pi_lang_sum, expt_unique == "b"), aes(colour = disorder), shape=18, size=5) +
geom_errorbarh(aes(xmin = .lower, xmax = .upper, colour = disorder), height=.3, size = .6) +
geom_text(data = mutate_if(pi_lang_sum, is.numeric, round, 2), colour = "black",
aes(label = glue::glue("{ES} [{.lower}, {.upper}]"), x = Inf), hjust = "inward", size = 3.5) +
labs(x = "Effect Size (Hedge's g)", y = "Reference", title = "Pitch: English", colour = "Disorder") +
geom_vline(xintercept=0, color='black', linetype='dashed') +
scale_color_manual(values = c("#E69F00", "#D16103")) +
theme_bw() +
theme(axis.text.y = element_text(face = c("bold", rep("plain", 10), "bold", rep("plain", 14))))
```
### PITCH VARIABILITY
```{r}
get_variables(brm_pv_disorder$posterior_model)
# get the effects for each study, and calculate their effect sizes by adding them to the intercept
# use regex because the easy thing does not work here
pv_studies_1 <- gather_draws(brm_pv_disorder$posterior_model,`r_expt_unique_dis.*` , regex = T)
pv_studies_2 <- spread_draws(brm_pv_disorder$posterior_model, b_disorderasd, b_disorderlhd, b_disorderrhd, b_disorderscz)
pv_studies <- merge(pv_studies_1, pv_studies_2) %>%
mutate(.variable = gsub("r_expt_unique_dis\\[|,Intercept\\]", "", .variable)) %>%
separate(.variable, c("expt_unique", "disorder"), "_") %>%
mutate(expt_unique_dis = paste0(toupper(disorder), ": ", expt_unique),
disorder = toupper(disorder),
ES = ifelse(disorder == "ASD", (.value + b_disorderasd),
ifelse(disorder == "LHD", (.value + b_disorderlhd),
ifelse(disorder == "RHD", (.value + b_disorderrhd),
ifelse(disorder == "SCZ", (.value + b_disorderscz), NA)))))
# get the overall meta-analytic effect sizes, make it long format and create similar columns as in data
pv_betas <- spread_draws(brm_pv_disorder$posterior_model, b_disorderasd, b_disorderlhd, b_disorderrhd, b_disorderscz) %>%
pivot_longer(cols = c("b_disorderasd", "b_disorderlhd", "b_disorderrhd", "b_disorderscz"), names_to = "expt_unique_dis") %>%
rename(ES = value) %>%
separate(expt_unique_dis, c("expt_unique", "disorder"), "_disorder") %>%
mutate(expt_unique_dis = paste0(toupper(disorder), ": ", "Overall Estimated Effect Size"),
disorder = toupper(disorder))
# to know how to re-factor in next step
pv_studies %>% ungroup %>% group_by(disorder) %>%
summarise(length(unique(expt_unique)))
# combine study specific and overall MA ES
pv_all <- bind_rows(pv_studies, pv_betas) %>%
ungroup() %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "ASD: Overall Estimated Effect Size", after = 30)) %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "LHD: Overall Estimated Effect Size", after = 44)) %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "RHD: Overall Estimated Effect Size", after = 74)) %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "SCZ: Overall Estimated Effect Size", after = 87))
# calculate summary stats
pv_sum <- pv_all %>% group_by(expt_unique_dis, disorder, expt_unique) %>% mean_qi(ES)
# plot: 1000x700
ggplot(pv_sum, aes(y = reorder(expt_unique_dis, desc(expt_unique_dis)), x = ES)) +
geom_point(aes(colour = disorder)) +
geom_point(data=subset(pv_sum, expt_unique == "b"), aes(colour = disorder), shape=18, size=5) +
geom_errorbarh(aes(xmin = .lower, xmax = .upper, colour = disorder), height=.3, size = .6) +
geom_text(data = mutate_if(pv_sum, is.numeric, round, 2), colour = "black",
aes(label = glue::glue("{ES} [{.lower}, {.upper}]"), x = Inf), hjust = "inward", size = 3) +
labs(x = "Effect Size (Hedge's g)", y = "Reference", title = "Pitch Variability", colour = "Disorder") +
geom_vline(xintercept=0, color='black', linetype='dashed') +
scale_color_manual(values = c("#E69F00", "#52854C", "#D16103", "#0072B2")) +
theme_bw() +
theme(axis.text.y = element_text(face = c("bold", rep("plain", 12), "bold", rep("plain", 29), "bold", rep("plain", 13), "bold", rep("plain", 30))))
```
### PITCH VARIABILITY TASK TYPE
```{r}
# free monological asd scz
# constrained rhd lhd
get_variables(brm_pv_task$posterior_model)
# get the values from the model
pv_task_residuals_1 <- gather_draws(brm_pv_task$posterior_model,`r_expt_unique_dis.*` , regex = T)
pv_task_residuals_2 <- spread_draws(brm_pv_task$posterior_model,
`b_disorderasd:task_typefreemonologicalproduction`,
`b_disorderscz:task_typefreemonologicalproduction`,
`b_disorderrhd:task_typeconstrainedproduction`,
`b_disorderlhd:task_typeconstrainedproduction`)
pv_task_residuals <- merge(pv_task_residuals_1, pv_task_residuals_2) %>%
mutate(.variable = gsub("r_expt_unique_dis\\[|,Intercept\\]", "", .variable),
.variable = gsub("..(", ".(", .variable, fixed = TRUE)) %>%
separate(.variable, c("expt_unique", "disorder"), "_") %>%
mutate(expt_unique_dis = paste0(toupper(disorder), ": ", expt_unique),
disorder = toupper(disorder))
# get language info from data
pv_task_info <- brm_pv_task$data %>% ungroup() %>% select(dis_task, expt_unique_dis, task_type) %>%
mutate(expt_unique_dis = gsub(". ", " ", expt_unique_dis, fixed = T),
expt_unique_dis = gsub(" ", ".", expt_unique_dis, fixed = T)) %>%
separate(expt_unique_dis, c("expt_unique", "disorder"), "_", remove = F) %>%
mutate(expt_unique_dis = paste0(toupper(disorder), ": ", expt_unique),
disorder = toupper(disorder))
# merge language info and studies and calculate effect sizes
pv_task_studies <- merge(pv_task_residuals, pv_task_info, by = c("expt_unique_dis", "disorder", "expt_unique")) %>%
mutate(ES = ifelse(dis_task == "asd_free monological production", (.value + `b_disorderasd:task_typefreemonologicalproduction`),
ifelse(dis_task == "scz_free monological production", (.value + `b_disorderscz:task_typefreemonologicalproduction`),
ifelse(dis_task == "rhd_constrained production", (.value + `b_disorderrhd:task_typeconstrainedproduction`),
ifelse(dis_task == "lhd_constrained production", (.value + `b_disorderlhd:task_typeconstrainedproduction`),
NA))))) %>%
filter(!is.na(ES))
# get overall estimates, long format and make similar columns to studies data
pv_task_betas <- spread_draws(brm_pv_task$posterior_model,
`b_disorderasd:task_typefreemonologicalproduction`,
`b_disorderscz:task_typefreemonologicalproduction`,
`b_disorderrhd:task_typeconstrainedproduction`,
`b_disorderlhd:task_typeconstrainedproduction`) %>%
pivot_longer(cols = c("b_disorderasd:task_typefreemonologicalproduction",
"b_disorderscz:task_typefreemonologicalproduction",
"b_disorderrhd:task_typeconstrainedproduction",
"b_disorderlhd:task_typeconstrainedproduction"), names_to = "expt_unique_dis") %>%
rename(ES = value) %>%
separate(expt_unique_dis, c("expt_unique", "disorder"), "_disorder") %>%
separate(disorder, c("disorder", "task_type"), ":task_type") %>%
mutate(task_type = ifelse(task_type == "freemonologicalproduction", "free monological production", "constrained production"),
disorder = toupper(disorder),
expt_unique_dis = paste0(toupper(disorder), ": ", "Overall Estimated Effect Size"))
# free: merge studies and betas
pv_task_free_all <- bind_rows(subset(pv_task_studies, task_type == "free monological production"),
subset(pv_task_betas, task_type == "free monological production")) %>%
ungroup() %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "ASD: Overall Estimated Effect Size", after = 20)) %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "SCZ: Overall Estimated Effect Size", after = Inf))
# constrained: merge studies and betas
pv_task_cons_all <- bind_rows(subset(pv_task_studies, task_type == "constrained production"),
subset(pv_task_betas, task_type == "constrained production")) %>%
ungroup() %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "LHD: Overall Estimated Effect Size", after = 12)) %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "RHD: Overall Estimated Effect Size", after = Inf))
# free: calculate summary stats
pv_task_free_sum <- pv_task_free_all %>% group_by(expt_unique_dis, disorder, expt_unique) %>% mean_qi(ES)
# constrained: calculate summary stats
pv_task_cons_sum <- pv_task_cons_all %>% group_by(expt_unique_dis, disorder, expt_unique) %>% mean_qi(ES)
# free: plot 2: 900 x 500
ggplot(pv_task_free_sum, aes(y = reorder(expt_unique_dis, desc(expt_unique_dis)), x = ES)) +
geom_point(aes(colour = disorder)) +
geom_point(data=subset(pv_task_free_sum, expt_unique == "b"), aes(colour = disorder), shape=18, size=5) +
geom_errorbarh(aes(xmin = .lower, xmax = .upper, colour = disorder), height=.3, size = .6) +
geom_text(data = mutate_if(pv_task_free_sum, is.numeric, round, 2), colour = "black",
aes(label = glue::glue("{ES} [{.lower}, {.upper}]"), x = Inf), hjust = "inward", size = 3.5) +
labs(x = "Effect Size (Hedge's g)", y = "Reference", title = "Pitch Variability: Free Monological Production Task", colour = "Disorder") +
geom_vline(xintercept=0, color='black', linetype='dashed') +
scale_color_manual(values = c("#E69F00", "#0072B2")) +
theme_bw() +
theme(axis.text.y = element_text(face = c("bold", rep("plain", 5), "bold", rep("plain", 20))))
# constrained: plot 2: 900 x 600
ggplot(pv_task_cons_sum, aes(y = reorder(expt_unique_dis, desc(expt_unique_dis)), x = ES)) +
geom_point(aes(colour = disorder)) +
geom_point(data=subset(pv_task_cons_sum, expt_unique == "b"), aes(colour = disorder), shape=18, size=5) +
geom_errorbarh(aes(xmin = .lower, xmax = .upper, colour = disorder), height=.3, size = .6) +
geom_text(data = mutate_if(pv_task_cons_sum, is.numeric, round, 2), colour = "black",
aes(label = glue::glue("{ES} [{.lower}, {.upper}]"), x = Inf), hjust = "inward", size = 3.5) +
labs(x = "Effect Size (Hedge's g)", y = "Reference", title = "Pitch Variability: Constrained Production Task", colour = "Disorder") +
geom_vline(xintercept=0, color='black', linetype='dashed') +
scale_color_manual(values = c("#52854C", "#D16103")) +
theme_bw() +
theme(axis.text.y = element_text(face = c("bold", rep("plain", 27), "bold", rep("plain", 12))))
```
### PITCH VARIABILITY LANGUAGE
```{r}
get_variables(brm_pv_lang$posterior_model)
# get the values from the model
pv_lang_residuals_1 <- gather_draws(brm_pv_lang$posterior_model,`r_expt_unique_dis.*` , regex = T)
pv_lang_residuals_2 <- spread_draws(brm_pv_lang$posterior_model,
`b_disorderasd:native_languageEnglish`,
`b_disorderlhd:native_languageEnglish`,
`b_disorderrhd:native_languageEnglish`,
`b_disorderscz:native_languageEnglish`)
pv_lang_residuals <- merge(pv_lang_residuals_1, pv_lang_residuals_2) %>%
mutate(.variable = gsub("r_expt_unique_dis\\[|,Intercept\\]", "", .variable),
.variable = gsub("..(", ".(", .variable, fixed = TRUE)) %>%
separate(.variable, c("expt_unique", "disorder"), "_") %>%
mutate(expt_unique_dis = paste0(toupper(disorder), ": ", expt_unique),
disorder = toupper(disorder))
# get language info from data
pv_lang_info <- brm_pv_lang$data %>% ungroup() %>% select(dis_lang, expt_unique_dis, native_language) %>%
mutate(expt_unique_dis = gsub(". ", " ", expt_unique_dis, fixed = T),
expt_unique_dis = gsub(" ", ".", expt_unique_dis, fixed = T)) %>%
separate(expt_unique_dis, c("expt_unique", "disorder"), "_", remove = F) %>%
mutate(expt_unique_dis = paste0(toupper(disorder), ": ", expt_unique),
disorder = toupper(disorder))
# merge language info and estimates
pv_lang_studies <- merge(pv_lang_residuals, pv_lang_info, by = c("expt_unique_dis", "disorder", "expt_unique")) %>%
mutate(ES = ifelse(dis_lang == "asd_English", (.value + `b_disorderasd:native_languageEnglish`),
ifelse(dis_lang == "lhd_English", (.value + `b_disorderlhd:native_languageEnglish`),
ifelse(dis_lang == "rhd_English", (.value + `b_disorderrhd:native_languageEnglish`),
ifelse(dis_lang == "scz_English", (.value + `b_disorderscz:native_languageEnglish`), NA))))) %>%
filter(!is.na(ES))
# get overall estimates, make it long format, and add columns similar to stdies
pv_lang_betas <- spread_draws(brm_pv_lang$posterior_model,
`b_disorderasd:native_languageEnglish`,
`b_disorderlhd:native_languageEnglish`,
`b_disorderrhd:native_languageEnglish`,
`b_disorderscz:native_languageEnglish`) %>%
pivot_longer(cols = c("b_disorderasd:native_languageEnglish",
"b_disorderlhd:native_languageEnglish",
"b_disorderrhd:native_languageEnglish",
"b_disorderscz:native_languageEnglish"), names_to = "expt_unique_dis") %>%
rename(ES = value) %>%
separate(expt_unique_dis, c("expt_unique", "disorder"), "_disorder") %>%
separate(disorder, c("disorder", "language"), ":native_language") %>%
mutate(disorder = toupper(disorder),
expt_unique_dis = paste0(toupper(disorder), ": ", "Overall Estimated Effect Size"))
# to know how to ref-actor
pv_lang_studies %>% ungroup %>% group_by(disorder) %>%
summarise(length(unique(expt_unique)))
# combine studies and betas
pv_lang_all <- bind_rows(pv_lang_studies, pv_lang_betas) %>%
ungroup() %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "ASD: Overall Estimated Effect Size", after = 17)) %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "LHD: Overall Estimated Effect Size", after = 29)) %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "RHD: Overall Estimated Effect Size", after = 48)) %>%
mutate(expt_unique_dis = fct_relevel(expt_unique_dis, "SCZ: Overall Estimated Effect Size", after = Inf))
# calculate summary stats
pv_lang_sum <- pv_lang_all %>% group_by(expt_unique_dis, disorder, expt_unique) %>% mean_qi(ES)
# plot: 7x11 in pdf
ggplot(pv_lang_sum, aes(y = reorder(expt_unique_dis, desc(expt_unique_dis)), x = ES)) +
geom_point(aes(colour = disorder)) +
geom_point(data=subset(pv_lang_sum, expt_unique == "b"), aes(colour = disorder), shape=18, size=5) +
geom_errorbarh(aes(xmin = .lower, xmax = .upper, colour = disorder), height=.3, size = .6) +
geom_text(data = mutate_if(pv_lang_sum, is.numeric, round, 2), colour = "black",
aes(label = glue::glue("{ES} [{.lower}, {.upper}]"), x = Inf), hjust = "inward", size = 3.5) +
labs(x = "Effect Size (Hedge's g)", y = "Reference", title = "Pitch Variability: English", colour = "Disorder") +
geom_vline(xintercept=0, color='black', linetype='dashed') +
scale_color_manual(values = c("#E69F00", "#52854C", "#D16103", "#0072B2")) +
theme_bw() +
theme(axis.text.y = element_text(face = c("bold", rep("plain", 11), "bold", rep("plain", 19), "bold", rep("plain", 11), "bold", rep("plain", 17))))
```
## FUNNEL PLOTS
```{r}
library(metafor)
# ASD: "#E69F00"
# LHD: "#52854C"
# RHD: "#D16103"
# SCZ: "#0072B2"
### PAUSE DURATION ###
# turn disorder into a factor
brm_pd_disorder$data$disorder <- as.factor(brm_pd_disorder$data$disorder)
# define forumla and run MA model
rma_formula <- as.formula("g_calc ~ 0 + disorder")
pd_metafor <- metafor::rma.mv(rma_formula, V = g_var_calc,
random = ~ 1 | same_sample / study_disorder / expt_unique_dis,
slab = disorder, data = brm_pd_disorder$data,
method = "REML")
# define colors for dots and plot them together with the funnel plot
pd_metafor$slab #scz, lhd, rhd
pd_colors <- c(rep("#0072B2", 9), rep("#52854C", 5), rep("#D16103", 7))
pd_funnel <- funnel(pd_metafor)
with(pd_funnel, points(x, y, col = pd_colors, pch = 19))
### PITCH ###
# turn disorder into a factor
brm_pi_disorder$data$disorder <- as.factor(brm_pi_disorder$data$disorder)
# define formula and run MA model
rma_formula <- as.formula("g_calc ~ 0 + disorder")
pi_metafor <- metafor::rma.mv(rma_formula, V = g_var_calc,
random = ~ 1 | same_sample / study_disorder / expt_unique_dis,
slab = disorder, data = brm_pi_disorder$data,
method = "REML")
# define colors for dots and plot them together with the funnel plot
pi_metafor$slab
#scz, asd, rhd
pi_colors <- c(rep("#0072B2", 5), rep("#E69F00", 25), rep("#D16103", 10))
pi_funnel <- funnel(pi_metafor)
with(pi_funnel, points(x, y, col = pi_colors, pch = 19))
### PITCH VARIABILITY ###
# turn disorder into a factor
brm_pv_disorder$data$disorder <- as.factor(brm_pv_disorder$data$disorder)
# define formula and run MA model
rma_formula <- as.formula("g_calc ~ 0 + disorder")
pv_metafor <- metafor::rma.mv(rma_formula, V = g_var_calc,
random = ~ 1 | same_sample / study_disorder / expt_unique_dis,
slab = disorder, data = brm_pv_disorder$data,
method = "REML")
# define colors for dots and plot them together with the funnel plot
pv_metafor$slab
#scz, asd, lhd, rhd
pv_colors <- c(rep("#0072B2", 12), rep("#E69F00", 30), rep("#52854C", 13), rep("#D16103", 29))
pv_funnel <- funnel(pv_metafor)
with(pv_funnel, points(x, y, col = pv_colors, pch = 19))
```