-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataSHIELD_Training_DGEpi.R
220 lines (125 loc) · 5.75 KB
/
DataSHIELD_Training_DGEpi.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
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
#### Installation of developer tools library, so that packages can be installed directly from GitHub
install.packages("devtools")
#### Install DataSHIELD packages and dependencies if not already done
install.packages('DSI')
install.packages('DSOpal', dependencies=TRUE)
devtools::install_github("datashield/dsBaseClient", ref = "6.2.0")
devtools::install_github("sofiasiamp/datashieldDescriptives")
#### https://dsmolep.mdc-berlin.de/ui/index.html
#### https://hsz.dife.de/zopal/ui/index.html#!dashboard
#### Load DataSHIELD libraries
library(DSI)
library(DSOpal)
library(dsBaseClient)
#### Filling in information from DHO to connect to the Opal Servers
#### The server name (eg ActivE, EPIC) can be chosen independently by users
builder <- DSI::newDSLoginBuilder()
builder$append(server="ActivE", url="https://dsmolep.mdc-berlin.de",
user="dgepi2023",
password="DGEpi2023!",
table = "N4HWorkshop23.WS_ActivE")
builder$append(server="EPIC", url="https://hsz.dife.de/zopal",
user="N4HWS2301",
password="DifeWS$2023",
table = "N4HWorkshop23.WS_EPIC")
builder$append(server="EPIC_Mod", url="https://hsz.dife.de/zopal",
user="N4HWS2301",
password="DifeWS$2023",
table = "N4HWorkshop23.WS_EPIC_Mod")
logindata <- builder$build()
#### Performing actual login to each server
connections <- datashield.login(logins=logindata, assign = T, symbol = "D")
#### How do I get help on functions
?datashield.login
#### Part 1: How to explore a new dataset and/or new DataSHIELD Options
#### Part 1A: Administrative functions to find out which functions can be used, what the control settings are etc.
#### Get an overview of DataSHIELD client-side functions, allowed DataSHIELD server-side functions & discloure controls / settings
ds.listClientsideFunctions()
server_function <- DSI::datashield.methods(conns=connections)
disclosure_settings <- ds.listDisclosureSettings()
#### Part 1B: Functions that provide feedback on the datasets or variables - How does the dataset look like?
ds.colnames("D")
#### How to select to which of the connected Opal Servers an analysis request is sent
ds.colnames(x = "D",
datasources = connections[c(1,2)])
ds.class(x = "D$SEX")
ds.class(x = "D$AGE")
ds.class(x = "D$SMOKE_ST")
ds.class(x = "D$SOD_POT")
#### Fixing upload errors within DataSHIELD
ds.asNumeric(x.name = "D$AGE",
newobj = "AGE_Corr",
datasources = connections)
ds.asFactor(input.var.name = "D$SMOKE_ST",
newobj.name = "SMOKE_ST_Corr",
datasources = connections)
ds.dataFrame(x = c("D$SEX",
"AGE_Corr",
"SMOKE_ST_Corr",
"D$SOD_POT"),
newobj = "Data_Corr")
ds.ls()
#### Some functions allow different display upon execution
ds.dim(x = "Data_Corr",
type = "split")
ds.length(x = "Data_Corr$AGE_Corr")
ds.levels(x = "Data_Corr$SEX")
ds.numNA(x = "Data_Corr$SOD_POT")
#### Topic 2A: How can I transform the individual level data on the server side?
ds.abs(x = "Data_Corr$SOD_POT",
newobj = "SOD_POT_ABS")
ds.log(x = "Data_Corr$SOD_POT",
newobj = "SOD_POT_LOG")
ds.completeCases(x = "Data_Corr",
newobj = "Data_Corr_Clean")
#### Topic 3A: Aggregate Functions - receiving summary statistics
ds.mean(x = "Data_Corr$AGE_Corr",
type = "combine")
ds.meanSdGp(x = "Data_Corr$AGE_Corr",
y = "Data_Corr$SMOKE_ST_Corr")
ds.cor(x='Data_Corr$AGE_Corr',
y='Data_Corr$SOD_POT')
ds.summary(x = "Data_Corr$AGE_Corr",
datasources= connections)
ds.summary(x = "Data_Corr$SEX",
datasources= connections)
ds.summary(x = "Data_Corr$SMOKE_ST_Corr",
datasources= connections)
ds.summary(x = "Data_Corr$SOD_POT",
datasources= connections)
#### Topic 3B: Building Models
mod <- ds.glm(formula = "SOD_POT~AGE_Corr+SEX",
data = "Data_Corr",
family = "gaussian",
datasources = connections)
mod
mod2 <- ds.glm(formula = "SMOKE_ST_Corr~AGE_Corr+SEX",
data = "Data_Corr",
family = "binomial",
datasources = connections)
mod2
#### Topic 4: Plotting Graphs: How is this possible in DataSHIELD?
#### https://bmcmedinformdecismak.biomedcentral.com/articles/10.1186/s12911-022-01754-4
ds.histogram(x="Data_Corr$SOD_POT")
ds.scatterPlot(x='Data_Corr$AGE_Corr',
y='Data_Corr$SOD_POT')
#### Topic 5: Improved analyst experience by using datashieldDescriptives (work in progress)
#### This is a client-side only package that only modifies output from dsBaseClient functions
library(datashieldDescriptives)
ds.class(x = "D")
study_class_overview <- datashieldDescriptives::datashield_descriptive(df = "D",
dsfunction = ds.class,
opal_connection = connections,
save = FALSE)
datashieldDescriptives::datashield_descriptive(df = "Data_Corr",
dsfunction = ds.length,
opal_connection = connections,
save = FALSE)
ds_ws <- datashieldDescriptives::datashield_summary(df = "Data_Corr",
opal_connection = connections,
save = FALSE)
datashieldDescriptives::datashield_table(df = "Data_Corr",
opal_connection = connections)
#### Logging out
DSI::datashield.logout(connections)
#### Evaluation using QR Code