-
Notifications
You must be signed in to change notification settings - Fork 0
/
MWF_Gait_Models_Revisions.Rmd
853 lines (714 loc) · 26.5 KB
/
MWF_Gait_Models_Revisions.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
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
---
title: "MWF_GaitModels"
author: "Narlon Cassio"
date: "January 13, 2022"
output:
pdf_document:
toc: yes
number_sections: yes
toc_depth: 5
word_document:
toc: yes
toc_depth: 5
geometry: "left = 1cm, right = 1cm, top = 1cm, bottom = 2.5cm"
header-includes:
- \usepackage{caption}
- \usepackage{pdflscape}
- \newcommand{\blandscape}{\begin{landscape}}
- \newcommand{\elandscape}{\end{landscape}}
editor_options:
chunk_output_type: console
---
\newpage
```{r setup, include = FALSE}
knitr::opts_chunk$set(
message = FALSE,
fig.height = 5, fig.width = 6, fig.align="center"
)
```
\small
# Loading packages
```{r, }
#------------------------------------------------------------------#
# Loading packages ####
#------------------------------------------------------------------#
library(tidyverse)
library(tableone)
library(gvlma)
library(openxlsx)
library(broom)
library(psych)
library(emmeans)
library(knitr)
library(rstatix)
library(performance)
library(lavaan)
```
# Loading data
```{r, message = FALSE}
#------------------------------------------------------------------#
# Loading data ####
#------------------------------------------------------------------#
# Outcome and descriptive data
all_data_clean <- read.xlsx("all_data_clean_final.xlsx")
mwf_wm_eroded <- read.xlsx("mwf_merged_eroded.xlsx")
## Adding eroded MWF data for whole-brain
all_data_clean <- left_join(all_data_clean, mwf_wm_eroded)
write.xlsx(all_data_clean, "all_data_clean_final.xlsx")
```
# Data analysis
## Descriptives
```{r, }
# Demographics
kable(digits = 2, caption = "Demographics",
describe(all_data_clean[c("age",
"height",
"weight",
"overall_fall_risk_score")], fast = TRUE, IQR = TRUE))
# Non-normal variables
kable(print(printToggle = FALSE, CreateTableOne(data = all_data_clean, c("bmi", "moca", "mmse"),
includeNA = TRUE), nonnormal = c("bmi","moca", "mmse")))
## Categorical demographics data
kable(print(printToggle = FALSE, CreateTableOne(data = all_data_clean, c("sex", "fazekas_score", "education_r"))))
kable(print(printToggle = FALSE,
CreateTableOne(data = all_data_clean,
c("fci_1_arthritis",
"fci_2_osteoporosis",
"fci_3_asthma",
"fci_4_copd_ards_or_emphysema",
"fci_5_angina",
"fci_6_congestive_heart_failure_or_heart_disease",
"fci_7_heart_attack_myocardial_infarct",
"fci_8_neurological_disease",
"fci_9_stroke_or_tia",
"fci_10_peripheral_vascular_disease",
"fci_11_diabetes_type_i_and_ii",
"fci_12_upper_gastrointestinal_disease",
"fci_13_depression",
"fci_14_anxiety_or_panic_disorders",
"fci_15_visual_impairment",
"fci_16_hearing_impairment",
"fci_17_degenerative_disc_disease",
"fci_18_obesity_and_or_body_mass_index_30",
"fci_19_thyroid_disease",
"fci_20_cancer",
"fci_21_hypertension",
"fci_total")), noSpaces = TRUE))
## Total Functional commorbidity index
kable(print(printToggle = FALSE, CreateTableOne(data = all_data_clean, c("fci_total"),
includeNA = TRUE), nonnormal = c("fci_total")))
# Myelin water fraction
kable(digits = 3, caption = "Myelin water fraction",
describe(all_data_clean[c("MWF_TOT_WM_mean","MWF_TOT_WM_eroded_mean",
"ALL_mean",
"Ant_CR_mean",
"Post_CR_mean",
"Sup_CR_mean",
"BCC_mean",
"GCC_mean",
"SCC_mean",
"Cingulum_mean",
"Ext_Cap_mean",
"Fornix_mean",
"Sag_Strat_mean",
"Ant_IC_mean",
"Post_IC_mean",
"Retro_IC_mean",
"Post_TR_mean",
"SLF_mean",
"Frontal_WM_all_mean",
"Parietal_WM_all_mean")], fast = TRUE, IQR = TRUE))
# Other structural data
kable(print(printToggle = FALSE, CreateTableOne(data = all_data_clean, c("wmh_cm3", "wmh_cm3_lg","eicv_cm3"),
includeNA = TRUE), nonnormal = c("wmh_cm3")))
# Gait measures
kable(digits = 3, caption = "Gait parameters",
describe(all_data_clean[c("velocity_ST",
"step_length_avg_ST",
"cycle_time_avg_ST",
"cycle_time_cov_ST",
"cycle_time_cov_ST_lg")], fast = TRUE, IQR = TRUE))
```
### Comparing participants between studies
```{r }
all_data_clean <- all_data_clean %>%
mutate(cohort = ifelse(str_detect(id, "FALLERS2_..."), "CogMob2", "RVCI"))
kable(print(printToggle = FALSE, CreateTableOne(
data = all_data_clean, c(
"age","height", "weight",
"sex", "fazekas_score", "education_r",
"bmi", "moca", "mmse","fci_total",
"fci_1_arthritis",
"fci_2_osteoporosis",
"fci_3_asthma",
"fci_4_copd_ards_or_emphysema",
"fci_5_angina",
"fci_6_congestive_heart_failure_or_heart_disease",
"fci_7_heart_attack_myocardial_infarct",
"fci_8_neurological_disease",
"fci_9_stroke_or_tia",
"fci_10_peripheral_vascular_disease",
"fci_11_diabetes_type_i_and_ii",
"fci_12_upper_gastrointestinal_disease",
"fci_13_depression",
"fci_14_anxiety_or_panic_disorders",
"fci_15_visual_impairment",
"fci_16_hearing_impairment",
"fci_17_degenerative_disc_disease",
"fci_18_obesity_and_or_body_mass_index_30",
"fci_19_thyroid_disease",
"fci_20_cancer",
"fci_21_hypertension"),
includeNA = TRUE, test = TRUE, strata = "cohort"), explain = TRUE, noSpaces = TRUE,
nonnormal = c("bmi", "moca", "mmse","fci_total")))
```
## Linear models
```{r, }
#------------------------------------------------------------------#
# Regression models ####
#------------------------------------------------------------------#
# Function to summarize lm output
lm_results <- function(x) {
my_list <- list()
my_list$Summary <- (summary(x))
my_list$Assumtions <- (gvlma(x))
return(my_list)
}
# Creating contrasts for multi-level categorical variables
all_data_clean <- within(all_data_clean, {
fazekas_c <- C(as.factor(fazekas_score), treatment, 2)
education_r_c <- C(as.factor(education_r), treatment, 3)
print(attributes(fazekas_c))
print(attributes(education_r_c))
})
```
\newpage
### Unadjusted
```{r, fig.height = 14, fig.width = 10, fig.align="center" }
## Select variable names for models
predictor_var <- colnames(all_data_clean[c(41:58,136)])
predictor_var %>% kable(col.names = "Predictor variables")
# List to store models
lm_var_mwf_1 = list()
# Run models in loop script
for (var in predictor_var){
# Formula
form <- paste("cycle_time_cov_ST_lg", "~", var)
# Print results to the list
lm_var_mwf_1[var] <- list(lm(form,
data = all_data_clean))
}
## Printing models
for (model in lm_var_mwf_1){
print(formula(model), showEnv = FALSE)
print(lm_results(model))
print(check_model(model))
}
```
### Adjusted
```{r, fig.height = 14, fig.width = 10, fig.align="center" }
## Select variable names for models
predictor_var <- colnames(all_data_clean[c(41:58,136)])
predictor_var %>% kable(col.names = "Predictor variables")
# List to store models
lm_var_mwf_2 = list()
# Run models in loop script
for (var in predictor_var){
# Formula
form <- paste(
"cycle_time_cov_ST_lg", "~", var,
"+ age + eicv_cm3 + sex + bmi + mmse") # Covariates
# Print results to the list
lm_var_mwf_2[var] <- list(lm(form,
data = all_data_clean))
}
## Printing models
for (model in lm_var_mwf_2){
print(formula(model), showEnv = FALSE)
print(lm_results(model))
print(check_model(model))
}
```
### Adjusted for WMH
```{r, fig.height = 14, fig.width = 10, fig.align="center" }
## Select variable names for models
predictor_var_wmh <- colnames(all_data_clean[c(43,44,48,54)])
predictor_var_wmh %>% kable(col.names = "Predictor variables")
# List to store models
lm_var_mwf_3 = list()
# Run models in loop script
for (var in predictor_var_wmh){
# Formula
form <- paste(
"cycle_time_cov_ST_lg", "~", var,
"+ age + eicv_cm3 + sex + bmi + mmse + wmh_cm3_lg") # Covariates
# Print results to the list
lm_var_mwf_3[var] <- list(lm(form,
data = all_data_clean))
}
## Printing models
for (model in lm_var_mwf_3){
print(formula(model), showEnv = FALSE)
print(lm_results(model))
print(check_model(model))
}
```
# Results
## Model summaries
```{r }
## Unadjusted
all_models_unadjusted_var = tibble()
for (model in lm_var_mwf_1){
output <- rbind(tidy(model, conf.int = TRUE, conf.level = 0.95))[2,]
output$outcome <- as.character(model$terms[[2]])
all_models_unadjusted_var <- rbind(all_models_unadjusted_var,output)
}
## Printing estimates
all_models_unadjusted_var %>%
arrange(p.value) %>%
kable(digits = 3)
```
```{r}
## Adjusted
all_models_adjusted_var = tibble()
for (model in lm_var_mwf_2){
output <- rbind(tidy(model, conf.int = TRUE, conf.level = 0.95))[2,]
output$outcome <- as.character(model$terms[[2]])
all_models_adjusted_var <- rbind(all_models_adjusted_var,output)
}
## Printing estimates
all_models_adjusted_var %>%
arrange(p.value) %>%
kable(digits = 3)
```
```{r}
## Adjusted for WMH
all_models_adjusted_var_wmh = tibble()
for (model in lm_var_mwf_3){
output <- rbind(tidy(model, conf.int = TRUE, conf.level = 0.95))[2,]
output$outcome <- as.character(model$terms[[2]])
all_models_adjusted_var_wmh <- rbind(all_models_adjusted_var_wmh,output)
}
## Printing estimates
all_models_adjusted_var_wmh %>%
arrange(p.value) %>%
kable(digits = 3)
```
## Figures
### Gait and MWF
```{r, }
# Cingulum
ggplot(all_data_clean,aes(Cingulum_mean, cycle_time_cov_ST_lg)) +
geom_point(size = 3, colour = "turquoise2") +
ggtitle("Cingulum") +
geom_smooth(method = lm, se = TRUE, colour = "black", fill = "light blue") +
xlab(NULL) +
ylab("Cycle time variability (CoV%), \n log-transformed") +
scale_x_continuous(breaks = seq(0.00, 0.15, by = 0.02), limits = c(0.00, 0.13)) +
scale_y_continuous(breaks = seq(0.00, 2.6, by = 0.2), limits = c(0, 2.6)) +
theme_dark() +
theme(plot.background = element_rect(fill = "black", colour = NA),
panel.background = element_rect(fill = "black"),
panel.grid.major = element_line(colour = "grey20"),
panel.grid.minor = element_line(colour = "grey20"),
plot.title = element_text(size = 17, hjust = 0.5, colour = "white"),
axis.line = element_blank(),
axis.title.y = element_text (size = 17, colour = "white"),
axis.title.x = element_text (size = 17, colour = "white"),
axis.text = element_text(colour = "white", size = 15))
ggsave("plots/Cingulum_gait.png", width = 7, height = 5)
```
```{r, }
# Superior longitudinal fasciculus
ggplot(all_data_clean,aes(SLF_mean, cycle_time_cov_ST_lg)) +
geom_point(size = 3, colour = "turquoise2") +
ggtitle("Superior longitudinal fasciculus") +
geom_smooth(method = lm, se = TRUE, colour = "black", fill = "light blue") +
xlab(NULL) +
ylab("Cycle time variability (CoV%), \n log-transformed") +
scale_x_continuous(breaks = seq(0.00, 0.21, by = 0.02), limits = c(0.07, 0.21)) +
scale_y_continuous(breaks = seq(0.00, 2.6, by = 0.2), limits = c(0, 2.6)) +
theme_dark() +
theme(plot.background = element_rect(fill = "black", colour = NA),
panel.background = element_rect(fill = "black"),
panel.grid.major = element_line(colour = "grey20"),
panel.grid.minor = element_line(colour = "grey20"),
plot.title = element_text(size = 17, hjust = 0.5, colour = "white"),
axis.line = element_blank(),
axis.title.y = element_text (size = 17, colour = "white"),
axis.title.x = element_text (size = 17, colour = "white"),
axis.text = element_text(colour = "white", size = 15))
ggsave("plots/SLF_gait.png", width = 7, height = 5)
```
```{r, }
# Posterior corona radiata
ggplot(all_data_clean,aes(Post_CR_mean, cycle_time_cov_ST_lg)) +
geom_point(size = 3, colour = "turquoise2") +
ggtitle("Corona radiata, posterior") +
geom_smooth(method = lm, se = TRUE, colour = "black", fill = "light blue") +
xlab(NULL) +
ylab("Cycle time variability (CoV%), \n log-transformed") +
scale_x_continuous(breaks = seq(0.00, 0.20, by = 0.02), limits = c(0.07, 0.20)) +
scale_y_continuous(breaks = seq(0.00, 2.6, by = 0.2), limits = c(0, 2.6)) +
theme_dark() +
theme(plot.background = element_rect(fill = "black", colour = NA),
panel.background = element_rect(fill = "black"),
panel.grid.major = element_line(colour = "grey20"),
panel.grid.minor = element_line(colour = "grey20"),
plot.title = element_text(size = 17, hjust = 0.5, colour = "white"),
axis.line = element_blank(),
axis.title.y = element_text (size = 17, colour = "white"),
axis.title.x = element_text (size = 17, colour = "white"),
axis.text = element_text(colour = "white", size = 15))
ggsave("plots/PostCR_gait.png", width = 7, height = 5)
```
```{r, }
# Corpus callosum, body
ggplot(all_data_clean,aes(BCC_mean, cycle_time_cov_ST_lg)) +
geom_point(size = 3, colour = "turquoise2") +
ggtitle("Corpus callosum, body") +
geom_smooth(method = lm, se = TRUE, colour = "black", fill = "light blue") +
xlab(NULL) +
ylab("Cycle time variability (CoV%), \n log-transformed") +
scale_x_continuous(breaks = seq(0.00, 0.20, by = 0.02), limits = c(0.07, 0.20)) +
scale_y_continuous(breaks = seq(0.00, 2.6, by = 0.2), limits = c(0, 2.6)) +
theme_dark() +
theme(plot.background = element_rect(fill = "black", colour = NA),
panel.background = element_rect(fill = "black"),
panel.grid.major = element_line(colour = "grey20"),
panel.grid.minor = element_line(colour = "grey20"),
plot.title = element_text(size = 17, hjust = 0.5, colour = "white"),
axis.line = element_blank(),
axis.title.y = element_text (size = 17, colour = "white"),
axis.title.x = element_text (size = 17, colour = "white"),
axis.text = element_text(colour = "white", size = 15))
ggsave("plots/BCC_gait.png", width = 7, height = 5)
```
\newpage
#### WMH plots
```{r }
### Cingulum
ggplot(all_data_clean, aes(cycle_time_cov_ST_lg, wmh_cm3_lg)) +
geom_point(aes(col = Cingulum_mean), size = 3) +
geom_smooth(method = lm, se = TRUE, colour = "black") +
scale_colour_gradient(low = "yellow", high = "red") +
ggtitle(" ") +
labs(color = "Cingulum,\nMyelin water fraction") +
ylab("White matter hyperintensity,\nlog-transformed") +
xlab(" ") +
theme_light() +
theme(plot.title = element_text(size = 17, hjust = 0.5),
legend.position = c(0.80, 0.1),
legend.direction = "horizontal",
legend.title = element_text(),
legend.background = element_blank(),
axis.title.y = element_text (size = 15),
axis.title.x = element_text (size = 15),
axis.text = element_text(colour = "black", size = 13)) +
guides(colour = guide_colourbar(title.position="top", title.hjust = 0.5, barwidth = 10))
ggsave("plots/Cingulum_wmh.png", width = 7, height = 5)
### SLF
ggplot(all_data_clean, aes(cycle_time_cov_ST_lg, wmh_cm3_lg)) +
geom_point(aes(col = SLF_mean), size = 3) +
geom_smooth(method = lm, se = TRUE, colour = "black") +
scale_colour_gradient(low = "yellow", high = "red")+
ggtitle(" ") +
labs(color = "SLF,\nMyelin water fraction") +
ylab("White matter hyperintensity,\nlog-transformed") +
xlab(" ") +
theme_light() +
theme(plot.title = element_text(size = 17, hjust = 0.5),
legend.position = c(0.80, 0.1),
legend.direction = "horizontal",
legend.title = element_text(),
legend.background = element_blank(),
axis.title.y = element_text (size = 15),
axis.title.x = element_text (size = 15),
axis.text = element_text(colour = "black", size = 13)) +
guides(colour = guide_colourbar(title.position="top", title.hjust = 0.5, barwidth = 10))
ggsave("plots/SLF_wmh.png", width = 7, height = 5)
### Posterior corona radiata
ggplot(all_data_clean, aes(cycle_time_cov_ST_lg, wmh_cm3_lg)) +
geom_point(aes(col = Post_CR_mean), size = 3) +
geom_smooth(method = lm, se = TRUE, colour = "black") +
scale_colour_gradient(low = "yellow", high = "red")+
ggtitle(" ") +
labs(color = "Corona radiata, posterior,\nMyelin water fraction") +
ylab("White matter hyperintensity,\nlog-transformed") +
xlab(" ") +
theme_light() +
theme(plot.title = element_text(size = 17, hjust = 0.5),
legend.position = c(0.80, 0.1),
legend.direction = "horizontal",
legend.title = element_text(),
legend.background = element_blank(),
axis.title.y = element_text (size = 15),
axis.title.x = element_text (size = 15),
axis.text = element_text(colour = "black", size = 13)) +
guides(colour = guide_colourbar(title.position="top", title.hjust = 0.5, barwidth = 10))
ggsave("plots/PostCR_wmh.png", width = 7, height = 5)
### Corpus callosum, body
ggplot(all_data_clean, aes(cycle_time_cov_ST_lg, wmh_cm3_lg)) +
geom_point(aes(col = BCC_mean), size = 3) +
geom_smooth(method = lm, se = TRUE, colour = "black") +
scale_colour_gradient(low = "yellow", high = "red")+
ggtitle(" ") +
labs(color = "Corpus callosum, body,\nMyelin water fraction") +
ylab("White matter hyperintensity,\nlog-transformed") +
xlab("Cycle time variability (CoV%), log-transformed") +
theme_light() +
theme(plot.title = element_text(size = 17, hjust = 0.5),
legend.position = c(0.80, 0.1),
legend.direction = "horizontal",
legend.title = element_text(),
legend.background = element_blank(),
axis.title.y = element_text (size = 15),
axis.title.x = element_text (size = 15),
axis.text = element_text(colour = "black", size = 13)) +
guides(colour = guide_colourbar(title.position="top", title.hjust = 0.5, barwidth = 10))
ggsave("plots/BCC_wmh.png", width = 7, height = 5)
```
\newpage
# Models for other gait variables
## Gait velocity
```{r, fig.height = 14, fig.width = 10, fig.align="center" }
## Select variable names for models
predictor_var <- colnames(all_data_clean[41:58])
predictor_var %>% kable(col.names = "Predictor variables")
# List to store models
lm_vel_mwf_2 = list()
# Run models in loop script
for (var in predictor_var){
# Formula
form <- paste(
"velocity_ST", "~", var,
"+ age + eicv_cm3 + sex + bmi + mmse") # Covariates
# Print results to the list
lm_vel_mwf_2[var] <- list(lm(form,
data = all_data_clean))
}
```
### Models
```{r, fig.height = 14, fig.width = 10, fig.align="center" }
## Printing models
for (model in lm_vel_mwf_2){
print(formula(model), showEnv = FALSE)
print(lm_results(model))
}
```
### Results
```{r }
## Printing estimates
## Adjusted
all_models_adjusted_vel = tibble()
for (model in lm_vel_mwf_2){
output <- rbind(tidy(model, conf.int = TRUE, conf.level = 0.95))[2,]
output$outcome <- as.character(model$terms[[2]])
all_models_adjusted_vel <- rbind(all_models_adjusted_vel,output)
}
## Printing estimates
all_models_adjusted_vel %>%
arrange(p.value) %>%
kable(digits = 3)
```
## Step length
```{r, fig.height = 14, fig.width = 10, fig.align="center" }
## Select variable names for models
predictor_var <- colnames(all_data_clean[41:58])
predictor_var %>% kable(col.names = "Predictor variables")
# List to store models
lm_step_mwf_2 = list()
# Run models in loop script
for (var in predictor_var){
# Formula
form <- paste(
"step_length_avg_ST", "~", var,
"+ age + eicv_cm3 + sex + bmi + mmse") # Covariates
# Print results to the list
lm_step_mwf_2[var] <- list(lm(form,
data = all_data_clean))
}
```
### Models
```{r, fig.height = 14, fig.width = 10, fig.align="center" }
## Printing models
for (model in lm_step_mwf_2){
print(formula(model), showEnv = FALSE)
print(lm_results(model))
}
```
### Results
```{r }
## Printing estimates
## Adjusted
all_models_adjusted_step = tibble()
for (model in lm_step_mwf_2){
output <- rbind(tidy(model, conf.int = TRUE, conf.level = 0.95))[2,]
output$outcome <- as.character(model$terms[[2]])
all_models_adjusted_step <- rbind(all_models_adjusted_step, output)
}
## Printing estimates
all_models_adjusted_step %>%
arrange(p.value) %>%
kable(digits = 3)
```
# Multiple comparisons
```{r}
## Computing FDR
all_models_fdr <- rbind(
(all_models_adjusted_var %>%
mutate(outcome = "variability")),
(all_models_adjusted_vel %>%
mutate(outcome = "velocity")),
(all_models_adjusted_step %>%
mutate(outcome = "step")))
## Adjusting for FDR (assuming 3 tests per predictor)
## Using FDR at alpha = 0.05
all_models_fdr %>%
mutate(p.fdr = p.adjust(p.value, method = "fdr")) %>%
arrange(p.value) %>%
kable(digits = 3)
write.csv(all_models_fdr, "all_models_fdr.csv")
```
# WMH as predictor
## Gait variables
```{r }
all_data_clean <- all_data_clean %>% # centering variables to plot estimates
mutate(velocity_ST_c = scale(velocity_ST),
step_length_avg_ST_c = scale(step_length_avg_ST),
cycle_time_cov_ST_lg_c = scale(cycle_time_cov_ST_lg))
wmh_gait_lm <- list(
lm(velocity_ST_c ~ wmh_cm3_lg,
data = all_data_clean),
lm(step_length_avg_ST_c ~ wmh_cm3_lg,
data = all_data_clean),
lm(cycle_time_cov_ST_lg_c ~ wmh_cm3_lg,
data = all_data_clean))
```
### Models
```{r, fig.height = 14, fig.width = 10, fig.align="center" }
## Printing models
for (model in wmh_gait_lm){
print(formula(model), showEnv = FALSE)
print(lm_results(model))
}
```
### Results
```{r }
## Adjusted
wmh_gait_lm_estimates = tibble()
for (model in wmh_gait_lm){
output <- rbind(tidy(model, conf.int = TRUE, conf.level = 0.95,))[2,]
output$rsquared <- summary(model)$r.squared
output$outcome <- as.character(model$terms[[2]])
wmh_gait_lm_estimates <- rbind(wmh_gait_lm_estimates, output)
}
## Printing estimates
wmh_gait_lm_estimates %>%
arrange(p.value) %>%
kable(digits = 3)
```
## MWF variables
```{r }
## Select variable names for models
outcome_var <- colnames(all_data_clean[c(41:58,136)])
outcome_var %>% kable(col.names = "Outcome variables")
# List to store models
wmh_mwf_lm = list()
# Run models in loop script
for (var in outcome_var){
# Formula
form <- paste(var, "~ wmh_cm3_lg")
# Print results to the list
wmh_mwf_lm[var] <- list(lm(form,
data = all_data_clean))
}
```
### Models
```{r, fig.height = 14, fig.width = 10, fig.align="center" }
## Printing models
for (model in wmh_mwf_lm){
print(formula(model), showEnv = FALSE)
print(lm_results(model))
}
```
### Results
```{r }
## Printing estimates
wmh_mwf_lm_estimates = tibble()
for (model in wmh_mwf_lm){
output <- rbind(tidy(model, conf.int = TRUE, conf.level = 0.95))[2,]
output$rsquared <- summary(model)$r.squared
output$outcome <- as.character(model$terms[[2]])
wmh_mwf_lm_estimates <- rbind(wmh_mwf_lm_estimates, output)
}
## Printing estimates
wmh_mwf_lm_estimates %>%
arrange(p.value) %>%
kable(digits = 3)
```
### Plots
```{r}
wmh_gait_lm_estimates %>%
mutate(p.value_sig = ifelse(p.value < 0.001, paste("p < ", 0.001),
ifelse(p.value < 0.05,paste("p =",round(p.value, 3)),"")),
outcome = str_replace_all(outcome, c(
"velocity_ST_c" = "Gait velocity",
"step_length_avg_ST_c" = "Step length",
"cycle_time_cov_ST_lg_c" = "Cycle time variability"))) %>%
ggplot(aes(x = reorder(outcome, p.value), estimate, colour = outcome)) +
geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.2, size = 0.2, colour = "black") +
geom_point(size = 3) +
geom_hline(yintercept = 0, size = 0.2, linetype = "dashed") +
scale_y_continuous(labels = scales::number_format(accuracy = 0.1), limits = c(-0.8, 0.8), n.breaks = 9) +
coord_flip() +
xlab(NULL) +
ylab("Estimates (95% CI)") +
geom_text(aes(label = p.value_sig), colour = "black", size = 2.5, vjust = 2.25) +
theme_light() +
theme(legend.position = "none",
axis.text = element_text(colour = "black", size = 10),
axis.text.y = element_text(face="bold"),
axis.title = element_text(colour = "black", size = 10))
ggsave("plots/estimates_gait_mwf.png", width = 5, height = 5)
```
```{r, fig.height = 8, fig.width = 8, fig.align="center" }
wmh_mwf_lm_estimates %>%
filter(outcome != "MWF_TOT_WM_mean") %>%
mutate(p.value_sig = ifelse(p.value < 0.001, paste("p < ", 0.001),
ifelse(p.value < 0.05,paste("p =",round(p.value, 3)),"")),
outcome = str_replace_all(outcome, c(
"Ant_CR_mean" = "Corona Radiata, anterior",
"Ant_IC_mean" = "Internal Capsule, anterior",
"BCC_mean" = "Corpus Callosum, body",
"Cingulum_mean" = "Cingulum",
"Ext_Cap_mean" = "External Capsule",
"Fornix_mean" = "Fornix",
"GCC_mean" = "Corpus Callosum, genu",
"MWF_TOT_WM_eroded_mean" = "Whole-brain white matter",
"Post_CR_mean" = "Corona Radiata, posterior",
"Sup_CR_mean" = "Corona Radiata, superior",
"Post_IC_mean" = "Internal Capsule, posterior",
"Post_TR_mean" = "Thalamic Radiation, posterior",
"Retro_IC_mean" = "Internal Capsule, retrolenticular",
"Sag_Strat_mean" = "Sagittal Stratum",
"SCC_mean" = "Corpus Callosum, splenium",
"SLF_mean" = "Superior Longitudinal Fasciculus",
"Frontal_WM_all_mean" = "Frontal white matter",
"Parietal_WM_all_mean" = "Parietal white matter"))) %>%
ggplot(aes(x = reorder(outcome, p.value), estimate, colour = outcome)) +
geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.2, size = 0.2, colour = "black") +
geom_point(size = 3) +
geom_hline(yintercept = 0, size = 0.2, linetype = "dashed") +
scale_y_continuous(labels = scales::number_format(accuracy = 0.01), limits = c(-0.05, 0.05), n.breaks = 9) +
coord_flip() +
xlab(NULL) +
ylab("Estimates (95% CI)") +
geom_text(aes(label = p.value_sig), colour = "black", size = 2.5, vjust = 2.25) +
theme_light() +
theme(legend.position = "none",
axis.text = element_text(colour = "black", size = 10),
axis.text.y = element_text(face="bold"),
axis.title = element_text(colour = "black", size = 10))
ggsave("plots/estimates_wmh_mwf.png", width = 8, height = 8)
```