-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataSHIELD_Training.R
281 lines (157 loc) · 6.78 KB
/
DataSHIELD_Training.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
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
266
267
268
269
270
271
272
#### 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="gmds2023",
password="Gmds!2023",
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
ds.listClientsideFunctions()
#### Get an overview of allowed DataSHIELD server-side functions
server_function <- DSI::datashield.methods(conns=connections)
#### Get an overview of discloure controls / settings
ds.listDisclosureSettings()
#### Part 1B: Functions that provide feedback on the datasets or variables - How does the dataset look like?
?ds.colnames
ds.colnames("D")
#### How to select to which of the connected Opal Servers an analysis request is sent
ds.colnames(x = "D",
datasources = connections)
ds.colnames(x = "D",
datasources = connections[2])
ds.colnames(x = "D",
datasources = connections[c(1,2)])
ds.colnames(x = "D",
datasources = connections[-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 (mostly stemming from data dictionary, should be minimised
#### when using the harmonizr package)
?ds.asNumeric
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
ds.dim(x = "Data_Corr",
type = "split")
ds.dim(x = "Data_Corr",
type = "combined")
ds.dim(x = "Data_Corr",
type = "both")
ds.length(x = "Data_Corr$AGE_Corr")
ds.levels(x = "Data_Corr$SEX")
#### cannot enforce to form categorical variable our ot numerical because of disclosure risk
ds.asFactor(input.var.name = "Data_Corr$AGE_Corr",
newobj.name = "Factor_Age")
ds.numNA(x = "Data_Corr$SOD_POT")
#### Topic 2A: How can I transform the individual level data on the server side?
?ds.abs
ds.abs(x = "Data_Corr$SOD_POT")
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.meanSdGp
ds.mean(x = "Data_Corr$AGE_Corr",
type = "combine")
ds.var(x = "Data_Corr$AGE_Corr")
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
?ds.glm
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
ds.histogram(x="Data_Corr$SOD_POT")
ds.histogram(x="Data_Corr$AGE_Corr")
?ds.scatterPlot
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 = "Data_Corr$AGE_Corr")
datashieldDescriptives::datashield_descriptive(df = "Data_Corr",
dsfunction = ds.class,
opal_connection = connections,
save = FALSE)
datashieldDescriptives::datashield_descriptive(df = "Data_Corr",
dsfunction = ds.numNA,
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)
#### Link for Evaluation
#### https://www.soscisurvey.de/NFDI4Health_WS_FAIRifizierung/