-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_subject_numbers.Rmd
383 lines (303 loc) · 9.77 KB
/
1_subject_numbers.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
---
title: "CamCan Preliminary Analysis"
author: "Kyle Kurkela"
date: "`r Sys.Date()`"
output:
html_document:
toc: yes
toc_float: yes
df_print: paged
code_folding: hide
---
```{r echo = FALSE, message = FALSE}
suppressPackageStartupMessages(library(tidyverse))
```
```{r}
fd_mean_thresh <- 0.3
num_runs_thresh <- 1
age_thresh <- 50
```
```{r}
motion <- read_rds('motion.rds')
motion %>%
mutate(CCID = str_remove(CCID, 'sub-')) -> motion
head(motion)
```
```{r paged.print=TRUE}
df <- read_rds('data.rds')
motion %>%
filter(task == 'movie') %>%
group_by(CCID) %>%
summarise(BadMotion = sum(fd_mean > fd_mean_thresh), .groups = 'drop') %>%
mutate(BadMotion = BadMotion > 1) %>%
add_column(task = 'movie') -> movie
motion %>%
filter(task != 'movie') %>%
mutate(BadMotion = fd_mean > fd_mean_thresh) %>%
select(CCID, task, BadMotion) %>%
bind_rows(., movie) %>%
group_by(CCID) %>%
summarise(ExcludeMotion = sum(BadMotion) > num_runs_thresh, .groups = 'drop') -> motion.summary
df %>%
left_join(., motion.summary, by = 'CCID') %>%
mutate(ExcludeMotion = if_else(is.na(ExcludeMotion), FALSE, ExcludeMotion)) -> df
head(df)
```
Brief Variable Descriptions:
`CCID` = string, CamCan Subject ID
`anat_T1w`:`fmap_smt_NA` = logical, whether or not a specific MRI image exists
`DetPosPic`:`TotalDetRecalls` = double, number of detailed recalls during the Emotional Memory Task
`Age`:`MT_TR` = misc, demographic data provided by CamCan
`Ntrials`:`RA` = misc, Cattell Fluid Intelligence Test data
`additional_attention_orientation`:`additional_acer` = double, ACE-R test scores
## How many subjects do we have?
```{r}
# each row = subject
nrow(df)
```
## How many subjects are usuable?
```{r}
# Create a new column that indicates where each participants has at least one missing scan
df %>%
rowwise() %>%
mutate(AnyMissingMRI = !all(c_across(cols = anat_T1w:fmap_smt_NA))) %>%
ungroup() -> df
df %>%
ungroup() %>%
mutate(AgeExclusion = Age > age_thresh) -> df
# Determine who has missing Emotional Memory data
df %>%
rowwise() %>%
mutate(AnyMissingEmoMem = is.na(TotalDetRecalls)) -> df
# Determine who has missing Wechler Memory Data
df %>%
mutate(AnyMissingWechler = any(is.na(homeint_v219), is.na(homeint_v515), is.na(homeint_storyrecall_i), is.na(homeint_storyrecall_d))) -> df
# Determine who has missing Cattell data
df %>%
mutate(AnyMissingCattell = is.na(TotalScore)) -> df
# Determine who has missing ACR-R data
df %>%
mutate(AnyMissingAdd = is.na(additional_memory)) -> df
# Determine who meets preliminary inclusion criterion -- no missing data
df %>%
mutate(MeetsInclusionCriterion = !any(AnyMissingMRI, AnyMissingEmoMem, AgeExclusion, AnyMissingAdd, ExcludeMotion)) -> df
```
```{r}
# Hand Code a Sankey Diagram
# Hand write the nodes data frame
nodes <- data.frame(node = 0:11,
name = c('All Subjects',
'Has All MRI Data', 'Missing At Least One Image',
'Low Motion', 'High Motion',
str_glue('Under Age {age_thresh}'), str_glue('Over Age {age_thresh}'),
'Has Weschler', 'Missing Weschler',
'Has Emotional Memory', 'Missing Emotional Memory',
'Meets Inclusion Criteria'),
node_group = c('1', '1', '2', '1', '2', '1', '2', '1', '2', '1', '2', '1'))
# Links
## Missing MRI data
df %>%
ungroup() %>%
count(AnyMissingMRI) %>%
pull() -> val
links <- data.frame(source = c(0, 0), target = c(1,2), value = val)
## Gross Motion
df %>%
filter(!AnyMissingMRI) %>%
count(ExcludeMotion) %>%
pull(n) -> val
links %>%
add_row(source = c(1,1), target = c(3,4), value = val) -> links
## Age Restriction
df %>%
filter(!AnyMissingMRI) %>%
filter(!ExcludeMotion) %>%
count(AgeExclusion) %>%
pull(n) -> val
links %>%
add_row(source = c(3,3), target = c(5,6), value = val) -> links
## Missing Wechler
df %>%
filter(!AnyMissingMRI) %>%
filter(!ExcludeMotion) %>%
filter(!AgeExclusion) %>%
mutate(AnyMissingWechler = factor(AnyMissingWechler, levels = c(FALSE, TRUE), labels = c(FALSE, TRUE))) %>%
count(AnyMissingWechler) %>%
complete(AnyMissingWechler, fill = list(n = 0)) %>%
pull(n) -> val
links %>%
add_row(source = c(5,5), target = c(7,8), value = val) -> links
## Missing Missing Emo Mem
df %>%
filter(!AnyMissingMRI) %>%
filter(!ExcludeMotion) %>%
filter(!AgeExclusion) %>%
filter(!AnyMissingWechler) %>%
count(AnyMissingEmoMem) %>%
pull(n) -> val
links %>%
add_row(source = c(7,7), target = c(9,10), value = val) -> links
##
links %>%
add_row(source = 9, target = 11, value = val[1]) -> links
networkD3::sankeyNetwork(Links = links, Nodes = nodes,
Source = 'source',
Target = 'target',
Value = 'value',
NodeID = 'name',
units = 'subjects',
NodeGroup = 'node_group', sinksRight = FALSE, fontSize = 12)
```
Of the `r nrow(df)` subjects, `r df %>% pull(MeetsInclusionCriterion) %>% sum()` meet the preliminary inclusion of having no missing data on our variables of interest. See the Sankey Diagram above to see why participants were excluded.
## How correlated are the behavioral variables?
```{r paged.print=TRUE}
df %>%
filter(MeetsInclusionCriterion) %>%
mutate(Sex = factor(Sex)) %>%
mutate(Sex = as.numeric(Sex)) %>%
select(Age, Sex, TotalDetRecalls, TotalScore, additional_memory, homeint_storyrecall_d) %>%
corrr::correlate(quiet = TRUE)
```
## What is the demographics breakdown of the subjects who meet are inclusion criteria?
```{r}
df %>%
filter(MeetsInclusionCriterion) %>%
mutate(AgeBins = cut(Age, breaks = c(18, 28, 38, 48, 58, 68, 78, 89))) %>%
select(AgeBins, Sex) %>%
table()
```
## How much variability is there in the subjects who meet our inclusion criteria?
### Emotional Memory Recalls
```{r}
df %>%
filter(MeetsInclusionCriterion) %>%
ggplot(aes(x = TotalDetRecalls)) +
geom_histogram(bins = 30) +
labs(title = 'Emotional Memory: Number of Detailed Recalls')
```
```{r}
df %>%
filter(MeetsInclusionCriterion) %>%
pull(TotalDetRecalls) %>%
psych::describe() %>%
tibble() %>%
select(-vars)
```
### Emotional Memory Recalls
```{r}
df %>%
filter(MeetsInclusionCriterion) %>%
ggplot(aes(x = homeint_storyrecall_d)) +
geom_histogram(bins = 30) +
labs(title = 'Logical Portion of Wechler Memory Scale: Number of Items Recalled', subtitle = 'After 20 Min Delay')
```
```{r}
df %>%
filter(MeetsInclusionCriterion) %>%
pull(homeint_storyrecall_d) %>%
psych::describe() %>%
tibble() %>%
select(-vars)
```
## Is this variability related to Age?
### Emotional Memory
```{r}
df %>%
filter(MeetsInclusionCriterion) %>%
ggplot(aes(Age, TotalDetRecalls)) +
geom_point() +
geom_smooth(method = lm, formula = y ~ x) +
labs(title = 'Is Memory Ability Related to Age?', subtitle = 'Yes')
```
```{r}
df %>%
filter(MeetsInclusionCriterion) %>%
lm(TotalDetRecalls~Age, data = .) %>%
summary()
```
### Weschler
```{r}
df %>%
filter(MeetsInclusionCriterion) %>%
ggplot(aes(Age, homeint_storyrecall_d)) +
geom_point() +
geom_smooth(method = lm, formula = y ~ x) +
labs(title = 'Is Memory Ability Related to Age?', subtitle = 'Yes')
```
```{r}
df %>%
filter(MeetsInclusionCriterion) %>%
lm(homeint_storyrecall_d~Age, data = .) %>%
summary()
```
## Is this varaibility related to sex?
### Emotional Memory
```{r}
df %>%
filter(MeetsInclusionCriterion) %>%
ggplot(aes(Sex, TotalDetRecalls)) +
geom_boxplot() +
labs(title = 'Is memory related to sex?', subtitle = 'Yes')
```
```{r}
df %>%
filter(MeetsInclusionCriterion) %>%
t.test(TotalDetRecalls~Sex, data = .)
```
### Weschler
```{r}
df %>%
filter(MeetsInclusionCriterion) %>%
ggplot(aes(Sex, homeint_storyrecall_d)) +
geom_boxplot() +
labs(title = 'Is memory related to sex?', subtitle = 'Yes')
```
```{r}
df %>%
filter(MeetsInclusionCriterion) %>%
t.test(homeint_storyrecall_d~Sex, data = .)
```
## Motion
The functional scans for CamCan look as follows:
Movie Task
`CamCan/sub-CC#####/func/sub-CC#####_task-movie_echo-1_bold.nii`
`CamCan/sub-CC#####/func/sub-CC#####_task-movie_echo-2_bold.nii`
`CamCan/sub-CC#####/func/sub-CC#####_task-movie_echo-3_bold.nii`
`CamCan/sub-CC#####/func/sub-CC#####_task-movie_echo-4_bold.nii`
`CamCan/sub-CC#####/func/sub-CC#####_task-movie_echo-5_bold.nii`
Rest Task
`CamCan/sub-CC#####/func/sub-CC#####_task-rest_bold.nii`
SMT Task
`CamCan/sub-CC#####/func/sub-CC#####_task-SMT_bold.nii`
## What does gross motion look like for the different scans?
```{r}
motion %>%
filter(task == 'movie') %>%
group_by(CCID) %>%
summarise(BadMotion = sum(fd_mean > fd_mean_thresh), .groups = 'drop') %>%
mutate(BadMotion = BadMotion > num_runs_thresh) %>%
add_column(task = 'movie') -> movie
motion %>%
filter(task != 'movie') %>%
mutate(BadMotion = fd_mean > fd_mean_thresh) %>%
select(CCID, task, BadMotion) %>%
bind_rows(., movie) %>%
ggplot(aes(x = task, fill = BadMotion)) +
geom_bar() +
labs(y = 'Numbers of Subjects', x = 'Task')
```
## What does gross motion look like for the multi-echo movie data?
```{r}
motion %>%
filter(task == 'movie') %>%
group_by(CCID) %>%
summarise(BadMotion = sum(fd_mean > fd_mean_thresh), .groups = 'drop') %>%
mutate(MotionFilter = BadMotion == 0,
MotionFilter = factor(MotionFilter, levels = c(T,F), labels = c('Included', 'Excluded'))) %>%
ggplot(aes(x = BadMotion, fill = MotionFilter)) +
geom_histogram(bins = 30) +
labs(title = 'Number of Motion Corrupted Scans',
subtitle = "In CamCan's Multiecho Movie Watching Data",
y = 'Number of Subjects',
x = 'Number of Echos with fd_mean > 0.2')
```