-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatistics.R
99 lines (79 loc) · 2.91 KB
/
statistics.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
# load data ---------------------------------------------------------------
library(tidyverse)
head(gm.ses)
head(cortical.ses)
# gm demographic ----------------------------------------------------------
gm.dg <- gm.ses %>%
group_by(SESGROUP) %>%
summarise(
across(.cols = c(AGE, MMSE:SOCIAL, EATING, SLEEPING, UCLA, GDS),
.fns = list(
mean = mean,
sd = sd),
na.rm = T),
across(.cols = c(HOUSING, MARRIAGE,SMOKING, DRINKING, HPT, DIABETES, HPL, MCI),
.fns = list(
yes = ~sum(. == '1', na.rm = T),
no = ~sum(. == '0', na.rm = T))),
across(.cols = c(GENDER),
.fns = list(
male = ~sum(. == 'Male'),
female = ~sum(. == 'Female')))
)
gm.dg <- subsample.gm %>%
group_by(NEWSESGROUP) %>%
summarise(
across(where(is.numeric) & !contains('_'),
.fns = list(
mean = mean,
sd = sd),
na.rm = T),
across(where(is.factor),
.fns = list(
yes = ~sum(. == '1', na.rm = T),
no = ~sum(. == '0', na.rm = T))),
across(.cols = c(GENDER),
.fns = list(
male = ~sum(. == 'Male'),
female = ~sum(. == 'Female')))
)
# gm demographic tests ----------------------------------------------------
# continous variables t tests
t.names <- names(gm.dg.model)
gm.dg.model <- subsample.gm %>%
select(where(is.numeric) & !contains('_')) %>%
map(~ t.test(.x ~ NEWSESGROUP,
data = subsample.gm)) %>%
map_dfr(., ~ list(low = .x$estimate[1], high = .x$estimate[2],
t = .x$statistic, p = .x$p.value)) %>%
# the map_dfr() function is expecting the output of the mapping function to be a list,
# but the data.frame() function is returning a data frame.
cbind(., t.names)
# factors chi tests
chi.names <- names(gm.dg.model)
gm.dg.model <- subsample.gm %>%
select(where(is.factor)) %>%
map(~ chisq.test(.x, subsample.gm$NEWSESGROUP,
correct = F)) %>%
map_dfr(., ~ list(chisq = .x$statistic, p = .x$p.value)) %>%
cbind(., chi.names)
# emmeans::emmeans(tiv.model, specs = pairwise ~ NEWSESGROUP:GENDER, adjust = 'Tukey')
# BNA results -------------------------------------------------------------
tmp <- gm.ses.60 %>%
group_by(NEWSESGROUP) %>%
summarise(
across(all_of(gm.ancova.results$ROI),
.fns = list(
mean = mean,
sd = sd),
na.rm = T))
# fs results --------------------------------------------------------------
area.results.roi <- area.results$ROI
tmp <- cortical.ses.60 %>%
group_by(NEWSESGROUP) %>%
summarise(
across(all_of(gsub('_thickness', '_volume',
volume.results$ROI)),
.fns = list(
mean = mean),
na.rm = T))