-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.R
185 lines (150 loc) · 6.52 KB
/
model.R
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
# all ses participants with FS meas: cortical.fs
# eTIV
eticv.model <- aov(EstimatedTotalIntraCranialVol ~ NEWSESGROUP +
AGE + GENDER + HPT + DIABETES + HPL,
data = cortical.fs)
summary(eticv.model)
emmeans::emmeans(eticv.model, specs = pairwise ~ NEWSESGROUP, adjust = 'Tukey')
# subcortical GMV
subgmv.model <- aov(SubCortGrayVol ~ NEWSESGROUP +
AGE + GENDER + HPT + DIABETES + HPL,
data = cortical.fs)
summary(subgmv.model)
emmeans::emmeans(subgmv.model, specs = pairwise ~ NEWSESGROUP, adjust = 'Tukey')
# cortex volume
cortex.model <- aov(CortexVol ~ NEWSESGROUP +
AGE + GENDER + HPT + DIABETES + HPL,
data = cortical.fs)
summary(cortex.model)
emmeans::emmeans(cortex.model, specs = pairwise ~ NEWSESGROUP, adjust = 'Tukey')
lhcortex.model <- aov(lhCortexVol ~ NEWSESGROUP +
AGE + GENDER + HPT + DIABETES + HPL,
data = cortical.fs)
summary(lhcortex.model)
emmeans::emmeans(lhcortex.model, specs = pairwise ~ NEWSESGROUP, adjust = 'Tukey')
rhcortex.model <- aov(rhCortexVol ~ NEWSESGROUP +
AGE + GENDER + HPT + DIABETES + HPL,
data = cortical.fs)
summary(rhcortex.model)
emmeans::emmeans(rhcortex.model, specs = pairwise ~ NEWSESGROUP, adjust = 'Tukey')
# cortical.fs is the final participants pool
# thickness ---------------------------------------------------------------
DKROI <- gsub('_thickness', '', DK)
thickness.model <- cortical.fs %>%
dplyr::select(ends_with('thickness')) %>%
map(~ aov(.x ~ SES + AGE + GENDER + EstimatedTotalIntraCranialVol +
HPT + DIABETES + HPL,
data = cortical.fs)) %>%
map(summary) %>%
map_dfr(~ as.data.frame(.[[1]][1,4:5]))
thickness.model['ROI'] <- DKROI
thickness.model['padj'] <- p.adjust(thickness.model$`Pr(>F)`, method = 'fdr')
colnames(thickness.model)[2] = 'punadj'
thickness.results <- subset(thickness.model, padj < 0.05)
# area --------------------------------------------------------------------
areaROI <- names(area.model) %>%
gsub('_area', '', .)
area.model <- cortical.fs %>%
dplyr::select(ends_with('area')) %>%
map(~ aov(.x ~ SES + AGE + GENDER + EstimatedTotalIntraCranialVol +
HPT + DIABETES + HPL,
data = cortical.fs)) %>%
map(summary) %>%
map_dfr(~ as.data.frame(.[[1]][1,4:5]))
area.model['ROI'] <- areaROI
area.model['padj'] <- p.adjust(area.model$`Pr(>F)`, method = 'fdr')
colnames(area.model)[2] = 'punadj'
area.results <- subset(area.model, padj < 0.05)
# volume ------------------------------------------------------------------
volume.model <- cortical.fs %>%
dplyr::select(ends_with('volume')) %>%
map(~ aov(.x ~ SES + AGE + GENDER + EstimatedTotalIntraCranialVol +
HPT + DIABETES + HPL,
data = cortical.fs)) %>%
map(summary) %>%
map_dfr(~ as.data.frame(.[[1]][1,4:5]))
volume.model['ROI'] <- DKROI
volume.model['padj'] <- p.adjust(volume.model$`Pr(>F)`, method = 'fdr')
colnames(volume.model)[2] = 'punadj'
volume.results <- subset(volume.model, padj < 0.05)
# plot
library(ggseg)
library(scico)
plot(dk)
dkplot <- dk$data
# aseg --------------------------------------------------------------------
library(ggseg)
plot(aseg)
asegROI <- names(cortical.fs)[238:276]
asegplot <- aseg$data
# 238-275 columns were aseg results
aseg.model <- cortical.fs %>%
dplyr::select(`Left-Lateral-Ventricle`:CC_Anterior) %>%
map(~ aov(.x ~ SES + AGE + GENDER + EstimatedTotalIntraCranialVol +
HPT + DIABETES + HPL,
data = cortical.fs)) %>%
map(summary) %>%
map_dfr(~ as.data.frame(.[[1]][1,4:5]))
aseg.model['ROI'] <- asegROI
aseg.model['padj'] <- p.adjust(aseg.model$`Pr(>F)`, method = 'fdr')
colnames(aseg.model)[2] = 'punadj'
aseg.results <- subset(aseg.model, padj < 0.05)
# plot
aseg.plot <- tibble(label = aseg$data$label) %>%
left_join(., select(aseg.results, ROI, 'F value'),
by = c('label' = 'ROI')) %>%
filter(!is.na(label)) %>%
rename(f = `F value`)
# mutate(f = ifelse(is.na(f), 0, f))
aseg.plot %>%
ggseg(atlas = 'aseg',
mapping = aes(fill = f),
position = 'stacked',) +
scale_fill_scico(palette = 'lajolla',
alpha = 0.8,
begin = 0.2,
end = 0.7,
direction = 1) +
labs(title = 'F value map of subcortical volume correlation with SES Score',
caption = 'All comparisions were adjusted by fdr.\nOnly significant regions after p-correction were shown.',
fill = 'F value') +
theme_void() +
theme(axis.title.x = element_text(size = 14),
axis.text.x = element_text(size = 12),
axis.ticks.x = element_blank(),
axis.line.x = element_blank(),
axis.title.y = element_text(size = 14),
axis.text.y = element_text(size = 12),
axis.line.y = element_blank(),
plot.title = element_text(size = 16, hjust = 0.5),
plot.caption = element_text(size = 12, hjust = 0),
legend.text = element_text(size = 8),
legend.title = element_text(size = 12))
# causal mediation: ses-brain-cog -----------------------------------------
install.packages('mediation')
install.packages('')
library(mediation)
# ses-cortex volume-cognition mediation model
workingdata <- cortical.fs %>%
subset(complete.cases(WORKING))
model.M <- lm(CortexVol ~ SES + AGE + GENDER + HPT + DIABETES + HPL,
data = cortical.fs)
model.M2 <- lm(INTELLECTURAL ~ SES + AGE + GENDER + HPT + DIABETES + HPL,
data = cortical.fs)
model.2 <- c('model.M', 'model.M2')
model.Y <- lm(WORKING ~ SES + CortexVol + AGE + GENDER + HPT + DIABETES + HPL,
data = cortical.fs)
out <- mediate(model.m = model.M2, model.y = model.Y,
treat = 'SES', mediator = 'CortexVol', boot = TRUE, sims = 1000)
summary(out)
plot(out.s)
# mediations
mediators.tmp <- c('INTELLECTURAL', 'PHYSICAL', 'SOCIAL')
outcome.tmp <- c('EPISODIC', 'WORKING', 'LOGIC', 'SPATIAL',
'LANGUAGE', 'ATTENTION', 'EXECUTIVE')
covars.tmp <- c('AGE + GENDER + HPT + DIABETES + HPL')
data.tmp <- list(cortical.fs = cortical.fs)
tmp <- mediations(datasets = data.tmp, treatment = 'SES', mediators = mediators.tmp,
outcome = outcome.tmp, covariates = covars.tmp,
conf.level = 0.95, sims = 1000)
tmp$EPISODIC.SES.INTELLECTURAL