-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsleep_thickness_descriptives.Rmd
265 lines (219 loc) · 9.54 KB
/
sleep_thickness_descriptives.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
---
title: "Sleep and Cortical Thickness: Descriptives"
author: "Narlon Cassio"
date: "June 18, 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 = 4, fig.width = 5, fig.align="center"
)
```
\small
# Loading packages
```{r, }
#------------------------------------------------------------------#
# Loading packages ####
#------------------------------------------------------------------#
library(tidyverse)
library(openxlsx)
library(broom)
library(psych)
library(knitr)
library(rstatix)
library(tableone)
```
# Loading data
```{r, message = FALSE}
#------------------------------------------------------------------#
# Loading data ####
#------------------------------------------------------------------#
# Outcome and descriptive data
all_data_clean <- read.xlsx("all_data_clean.xlsx")
all_data_clean_included <- all_data_clean %>%
filter(included=="YES")
```
# Data management
## Checking data --- Included subjects only
### Demographics
```{r, fig.height=8, fig.width=6}
# Checking variables
## Continous demographics data
all_data_clean %>% select("age","moca","mmse","height","weight","bmi", "psqi_total_score") %>%
describe(IQR = TRUE, fast = TRUE) %>%
kable(digits = 3)
## Histograms
all_data_clean_included %>%
select("id", "age", "moca", "mmse", "height", "weight", "bmi", "psqi_total_score") %>%
pivot_longer(values_to = "data", names_to = "measures", col = 2:8) %>%
ggplot(aes(data, fill = measures)) +
geom_histogram(colour = "black", binwidth = function(x) 2 * IQR(x) / (length(x)^(1/3))) +
facet_wrap(~measures, scales = "free", ncol = 2)+
theme_minimal() +
theme(legend.position = "none")
## Normality tests
kable(digits = 2, caption = "Normality test", all_data_clean %>%
shapiro_test(age, moca, mmse, height, weight, bmi, psqi_total_score))
## Categorical demographics data
kable(print(printToggle = FALSE, CreateTableOne(data = all_data_clean_included, c("sex", "education", "sleep_medication_psqi")),
missing = TRUE))
```
### Sleep data
```{r, fig.height=8, fig.width=6}
# Checking variables
# Distance, ambulation time, velocity, step count, cadence, double support time
kable(digits = 3, describe(all_data_clean_included[c("sleep_time_avg",
"sleep_time_sd",
"sleep_efficiency_avg",
"sleep_efficiency_sd",
"fragmentation_index_avg",
"fragmentation_index_sd")], IQR = TRUE, fast = TRUE))
## Histograms
all_data_clean_included %>%
select("sleep_time_avg", "sleep_time_sd",
"sleep_efficiency_avg", "sleep_efficiency_sd",
"fragmentation_index_avg", "fragmentation_index_sd") %>%
pivot_longer(values_to = "data", names_to = "measures", col = 1:6) %>%
ggplot(aes(data, fill = measures)) +
geom_histogram(colour = "black", binwidth = function(x) 2 * IQR(x) / (length(x)^(1/3))) +
facet_wrap(~measures, scales = "free", ncol = 2)+
theme_minimal() +
theme(legend.position = "none")
## Normality tests
kable(digits = 3, caption = "Normality test", all_data_clean_included %>%
shapiro_test(sleep_time_avg,
sleep_time_sd,
sleep_efficiency_avg,
sleep_efficiency_sd,
fragmentation_index_avg,
fragmentation_index_sd))
# Transforming non-normal variables
all_data_clean_included <- all_data_clean_included %>%
mutate(sleep_time_sd_lg = log1p(sleep_time_sd),
sleep_efficiency_sd_lg = log1p(sleep_efficiency_sd),
fragmentation_index_sd_lg = log1p(fragmentation_index_sd))
## Histograms
all_data_clean_included %>%
select("sleep_time_avg", "sleep_time_sd_lg",
"sleep_efficiency_avg", "sleep_efficiency_sd_lg",
"fragmentation_index_avg", "fragmentation_index_sd_lg") %>%
pivot_longer(values_to = "data", names_to = "measures", col = 1:6) %>%
ggplot(aes(data, fill = measures)) +
geom_histogram(colour = "black", binwidth = function(x) 2 * IQR(x) / (length(x)^(1/3))) +
facet_wrap(~measures, scales = "free", ncol = 2)+
theme_minimal() +
theme(legend.position = "none")
## Normality tests
kable(digits = 3, caption = "Normality test", all_data_clean_included %>%
shapiro_test(sleep_time_sd_lg,
sleep_efficiency_sd_lg,
fragmentation_index_sd_lg))
kable(digits = 3, describe(all_data_clean_included[c("sleep_time_sd_lg",
"sleep_efficiency_sd_lg",
"fragmentation_index_sd_lg")], IQR = TRUE, fast = TRUE))
```
### Cognition data
```{r, }
# Checking variables
kable(digits = 3, describe(all_data_clean_included[c("adas_cog_tot", "tmt_a", "tmt_b",
"tmt_bma", "dsst")], IQR = TRUE, fast = TRUE))
## Histograms
all_data_clean_included %>%
select("adas_cog_tot", "tmt_a", "tmt_b", "tmt_bma", "dsst") %>%
pivot_longer(values_to = "data", names_to = "measures", col = 1:5) %>%
ggplot(aes(data, fill = measures)) +
geom_histogram(colour = "black", binwidth = function(x) 2 * IQR(x) / (length(x)^(1/3))) +
facet_wrap(~measures, scales = "free", ncol = 2)+
theme_minimal() +
theme(legend.position = "none")
## Normality tests
kable(digits = 2, caption = "Normality test", all_data_clean_included %>%
shapiro_test(adas_cog_tot, tmt_a, tmt_b,
tmt_bma, dsst))
boxplot(all_data_clean_included$tmt_a)$out
boxplot(all_data_clean_included$tmt_b)$out
boxplot(all_data_clean_included$tmt_bma)$out
# Transforming non-normal variables
all_data_clean_included <- all_data_clean_included %>%
mutate(tmt_a_lg = log10(tmt_a),
tmt_b_lg = log10(tmt_b),
tmt_bma_lg = log10(tmt_bma))
boxplot(all_data_clean_included$tmt_a_lg)$out
boxplot(all_data_clean_included$tmt_b_lg)$out
boxplot(all_data_clean_included$tmt_bma_lg)$out
all_data_clean_included <- all_data_clean_included %>%
mutate(tmt_a_lg = ifelse(tmt_a_lg >= 1.87, NA, tmt_a_lg),
tmt_b_lg = ifelse(tmt_b_lg >= 2.47, NA, tmt_b_lg),
tmt_bma_lg = ifelse(tmt_bma_lg <= 0.99, NA, tmt_bma_lg),
tmt_bma_lg = ifelse(tmt_bma_lg >= 2.57, NA, tmt_bma_lg))
boxplot(all_data_clean_included$tmt_a_lg)$out
boxplot(all_data_clean_included$tmt_b_lg)$out
boxplot(all_data_clean_included$tmt_bma_lg)$out
## Normality tests
kable(digits = 2, caption = "Normality test", all_data_clean_included %>%
shapiro_test(tmt_a_lg, tmt_b_lg, tmt_bma_lg))
```
```{r, }
# Saving final dataset
write.xlsx(all_data_clean_included, "all_data_clean_final.xlsx")
```
# Comparing included vs excluded
```{r }
# Checking observations
kable(all_data_clean %>%
mutate(cohort = str_replace_all(id, c("FACTORIAL_..." = "FACT",
"RVCI_..." = "RVCI",
"BT_..." = "BT"))) %>%
group_by(cohort) %>%
count() %>%
ungroup(), caption = "Number of subjects with sleep data available across corhots")
## ADAS-Cog
kable(all_data_clean %>%
filter(is.na(adas_cog_tot)==FALSE) %>%
group_by(included) %>%
count() %>%
ungroup())
## TMT BmA data
kable(all_data_clean %>%
filter(is.na(tmt_bma)==FALSE) %>%
group_by(included) %>%
count() %>%
ungroup())
## DSST data
kable(all_data_clean %>%
filter(is.na(dsst)==FALSE) %>%
group_by(included) %>%
count() %>%
ungroup())
# Demographic information
kable(print(printToggle = FALSE, CreateTableOne(data = all_data_clean,
c("age", "sex", "psqi_total_score", "sleep_medication_psqi","sleep_dist_psqi", "height", "weight",
"bmi","education", "moca", "mmse",
"adas_cog_tot", "tmt_a", "tmt_b", "tmt_bma", "dsst"),
strata = "included", includeNA = TRUE, addOverall = TRUE),
nonnormal = c("bmi","moca", "mmse", "tmt_a", "tmt_b", "tmt_bma")), caption = "Demographic data: Comparing included vs excluded")
# Predictor data
kable(print(printToggle = FALSE, CreateTableOne(data = all_data_clean, c("sleep_time_avg", "sleep_time_sd",
"sleep_efficiency_avg", "sleep_efficiency_sd",
"fragmentation_index_avg", "fragmentation_index_sd"),
strata = "included", includeNA = TRUE, addOverall = TRUE),
nonnormal = c("sleep_time_sd","sleep_efficiency_sd", "fragmentation_index_sd")),
caption = "Predictor data: Comparing included vs excluded")
```