-
Notifications
You must be signed in to change notification settings - Fork 0
/
fsgd.R
141 lines (116 loc) · 6.6 KB
/
fsgd.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
#------------------------------------------------------------------#
# Loading packages ####
#------------------------------------------------------------------#
library(tidyverse)
library(openxlsx)
#------------------------------------------------------------------#
# Loading data ####
#------------------------------------------------------------------#
# Data ready for FreeSurfer
data_all <- read.xlsx("all_data_clean_final.xlsx")
fsgd <- as.data.frame(c("GroupDescriptorFile 1",
"Title",
"MeasurementName",
"Class",
"Class",
"Class",
"Class",
"Variables"))
# Revisions to account for sleep medicine
## need to create a categorical variable that merges sex with sleep medicine
data_all <- data_all %>%
unite(sex_sleep_med, c(sex, sleep_medication_psqi), remove = FALSE)
# Creating fsgd files
# ------------------------------------------------------------ #
# Sleep Time #
# ------------------------------------------------------------ #
#### Sleep time average ####
sleep_time_avg <- fsgd
sleep_time_avg[2, 2] <- "sleep_time_avg"
sleep_time_avg[3, 2] <- "thickness"
sleep_time_avg[4, 2] <- "female_yes"
sleep_time_avg[5, 2] <- "female_no"
sleep_time_avg[6, 2] <- "male_yes"
sleep_time_avg[7, 2] <- "male_no"
sleep_time_avg[8, 2:6] <- c("sleep_time_avg", "age", "moca", NA, NA)
sleep_time_avg[9:121, 2:6] <- data_all[c("id", "sex_sleep_med", "sleep_time_avg", "age", "moca")]
sleep_time_avg[9:121, 1] <- "Input"
write.table(sleep_time_avg, "fs_analysis/a_fsgd/final/sleep_time_avg.fsgd", sep = "\t", na = "", row.names = FALSE, col.names = FALSE, quote = FALSE)
#### Sleep time variability ####
sleep_time_sd <- fsgd
sleep_time_sd[2, 2] <- "sleep_time_sd_lg"
sleep_time_sd[3, 2] <- "thickness"
sleep_time_sd[4, 2] <- "female_yes"
sleep_time_sd[5, 2] <- "female_no"
sleep_time_sd[6, 2] <- "male_yes"
sleep_time_sd[7, 2] <- "male_no"
sleep_time_sd[8, 2:6] <- c("sleep_time_sd_lg", "age", "moca", NA, NA)
sleep_time_sd[9:121, 2:6] <- data_all[c("id", "sex_sleep_med", "sleep_time_sd_lg", "age", "moca")]
sleep_time_sd[9:121, 1] <- "Input"
write.table(sleep_time_sd, "fs_analysis/a_fsgd/final/sleep_time_sd.fsgd", sep = "\t", na = "", row.names = FALSE, col.names = FALSE, quote = FALSE)
# ------------------------------------------------------------ #
# Sleep Efficiency #
# ------------------------------------------------------------ #
## Sleep efficiency average
sleep_efficiency_avg <- fsgd
sleep_efficiency_avg[2, 2] <- "sleep_efficiency_avg"
sleep_efficiency_avg[3, 2] <- "thickness"
sleep_efficiency_avg[4, 2] <- "female_yes"
sleep_efficiency_avg[5, 2] <- "female_no"
sleep_efficiency_avg[6, 2] <- "male_yes"
sleep_efficiency_avg[7, 2] <- "male_no"
sleep_efficiency_avg[8, 2:6] <- c("sleep_efficiency_avg", "age", "moca", NA, NA)
sleep_efficiency_avg[9:121, 2:6] <- data_all[c("id", "sex_sleep_med", "sleep_efficiency_avg", "age", "moca")]
sleep_efficiency_avg[9:121, 1] <- "Input"
write.table(sleep_efficiency_avg, "fs_analysis/a_fsgd/final/sleep_efficiency_avg.fsgd", sep = "\t", na = "", row.names = FALSE, col.names = FALSE, quote = FALSE)
## Sleep efficiency variability
sleep_efficiency_sd <- fsgd
sleep_efficiency_sd[2, 2] <- "sleep_efficiency_sd_lg"
sleep_efficiency_sd[3, 2] <- "thickness"
sleep_efficiency_sd[4, 2] <- "female_yes"
sleep_efficiency_sd[5, 2] <- "female_no"
sleep_efficiency_sd[6, 2] <- "male_yes"
sleep_efficiency_sd[7, 2] <- "male_no"
sleep_efficiency_sd[8, 2:6] <- c("sleep_efficiency_sd_lg", "age", "moca", NA, NA)
sleep_efficiency_sd[9:121, 2:6] <- data_all[c("id", "sex_sleep_med", "sleep_efficiency_sd_lg", "age", "moca")]
sleep_efficiency_sd[9:121, 1] <- "Input"
write.table(sleep_efficiency_sd, "fs_analysis/a_fsgd/final/sleep_efficiency_sd.fsgd", sep = "\t", na = "", row.names = FALSE, col.names = FALSE, quote = FALSE)
# ------------------------------------------------------------ #
# Fragmentation index #
# ------------------------------------------------------------ #
## Fragmentation index average
fragmentation_index_avg <- fsgd
fragmentation_index_avg[2, 2] <- "fragmentation_index_avg"
fragmentation_index_avg[3, 2] <- "thickness"
fragmentation_index_avg[4, 2] <- "female_yes"
fragmentation_index_avg[5, 2] <- "female_no"
fragmentation_index_avg[6, 2] <- "male_yes"
fragmentation_index_avg[7, 2] <- "male_no"
fragmentation_index_avg[8, 2:6] <- c("fragmentation_index_avg", "age", "moca", NA, NA)
fragmentation_index_avg[9:121, 2:6] <- data_all[c("id", "sex_sleep_med", "fragmentation_index_avg", "age", "moca")]
fragmentation_index_avg[9:121, 1] <- "Input"
write.table(fragmentation_index_avg, "fs_analysis/a_fsgd/final/fragmentation_index_avg.fsgd", sep = "\t", na = "", row.names = FALSE, col.names = FALSE, quote = FALSE)
## Fragmentation index variability
fragmentation_index_sd <- fsgd
fragmentation_index_sd[2, 2] <- "fragmentation_index_sd_lg"
fragmentation_index_sd[3, 2] <- "thickness"
fragmentation_index_sd[4, 2] <- "female_yes"
fragmentation_index_sd[5, 2] <- "female_no"
fragmentation_index_sd[6, 2] <- "male_yes"
fragmentation_index_sd[7, 2] <- "male_no"
fragmentation_index_sd[8, 2:6] <- c("fragmentation_index_sd_lg", "age", "moca", NA, NA)
fragmentation_index_sd[9:121, 2:6] <- data_all[c("id", "sex_sleep_med", "fragmentation_index_sd_lg", "age", "moca")]
fragmentation_index_sd[9:121, 1] <- "Input"
write.table(fragmentation_index_sd, "fs_analysis/a_fsgd/final/fragmentation_index_sd.fsgd", sep = "\t", na = "", row.names = FALSE, col.names = FALSE, quote = FALSE)
## Fragmentation index variability adjusting for average
fragmentation_index_sd_avg <- fsgd
fragmentation_index_sd_avg[2, 2] <- "fragmentation_index_sd_lg"
fragmentation_index_sd_avg[3, 2] <- "thickness"
fragmentation_index_sd_avg[4, 2] <- "female_yes"
fragmentation_index_sd_avg[5, 2] <- "female_no"
fragmentation_index_sd_avg[6, 2] <- "male_yes"
fragmentation_index_sd_avg[7, 2] <- "male_no"
fragmentation_index_sd_avg[8, 2:7] <- c("fragmentation_index_sd_lg", "age", "moca", "fragmentation_index_avg", NA, NA)
fragmentation_index_sd_avg[9:121, 2:7] <- data_all[c("id", "sex_sleep_med", "fragmentation_index_sd_lg", "age", "moca", "fragmentation_index_avg")]
fragmentation_index_sd_avg[9:121, 1] <- "Input"
write.table(fragmentation_index_sd_avg, "fs_analysis/a_fsgd/final/fragmentation_index_sd_avg.fsgd", sep = "\t", na = "", row.names = FALSE, col.names = FALSE, quote = FALSE)