-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
using-association-plot.Rmd
303 lines (281 loc) · 8.23 KB
/
using-association-plot.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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
---
title: "Using association plot"
author: "NEST CoreDev"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Using association plot}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
# `teal` application to use association plot with various datasets types
This vignette will guide you through the four parts to create a `teal` application using various types of datasets using the association plot module `tm_g_association()`:
1. Load libraries
2. Create data sets
3. Create an `app` variable
4. Run the app
## 1 - Load libraries
```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide"}
library(teal.modules.general) # used to create the app
library(dplyr) # used to modify data sets
```
## 2 - Create data sets
Inside this app 4 datasets will be used
1. `ADSL` A wide data set with subject data
2. `ADRS` A long data set with response data for subjects at different time points of the study
3. `ADTTE` A long data set with time to event data
4. `ADLB` A long data set with lab measurements for each subject
```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide"}
data <- teal_data()
data <- within(data, {
ADSL <- teal.modules.general::rADSL %>%
mutate(TRTDUR = round(as.numeric(TRTEDTM - TRTSDTM), 1))
ADRS <- teal.modules.general::rADRS
ADTTE <- teal.modules.general::rADTTE
ADLB <- teal.modules.general::rADLB %>%
mutate(CHGC = as.factor(case_when(
CHG < 1 ~ "N",
CHG > 1 ~ "P",
TRUE ~ "-"
)))
})
datanames <- c("ADSL", "ADRS", "ADTTE", "ADLB")
datanames(data) <- datanames
join_keys(data) <- default_cdisc_join_keys[datanames]
```
## 3 - Create an `app` variable
This is the most important section. We will use the `teal::init()` function to create an app. The data will be handed over using `teal.data::teal_data()`. The app itself will be constructed by multiple calls of `tm_g_association()` using different combinations of data sets.
```{r echo=TRUE, message=FALSE, warning=FALSE, results="hide"}
# configuration for a single wide dataset
mod1 <- tm_g_association(
label = "Single wide dataset",
ref = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["ADSL"]]),
selected = "AGE",
fixed = FALSE
)
),
vars = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variables:",
choices = variable_choices(data[["ADSL"]]),
selected = "BMRKR1",
multiple = TRUE,
fixed = FALSE
)
)
)
# configuration for two wide datasets
mod2 <- tm_g_association(
label = "Two wide datasets",
ref = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["ADSL"]], c("AGE", "SEX", "STRATA1", "RACE")),
selected = "STRATA1",
multiple = FALSE,
fixed = FALSE
)
),
vars = data_extract_spec(
dataname = "ADSL",
select = select_spec(
label = "Select variables:",
choices = variable_choices(data[["ADSL"]], c("AGE", "SEX", "RACE", "COUNTRY")),
selected = c("AGE", "COUNTRY", "RACE"),
multiple = TRUE,
fixed = FALSE
)
)
)
# configuration for multiple long datasets
mod3 <- tm_g_association(
label = "Multiple different long datasets",
ref = data_extract_spec(
dataname = "ADTTE",
select = select_spec(
label = "Select variables:",
choices = variable_choices(data[["ADTTE"]]),
selected = "AVAL",
multiple = FALSE,
fixed = FALSE
),
filter = filter_spec(
label = "Select endpoint:",
vars = "PARAMCD",
choices = value_choices(data[["ADTTE"]], "PARAMCD", "PARAM"),
selected = c("PFS", "EFS"),
multiple = TRUE
)
),
vars = data_extract_spec(
dataname = "ADRS",
reshape = TRUE,
select = select_spec(
label = "Select variable:",
choices = variable_choices(data[["ADRS"]], c("AVALC", "BMRKR1", "BMRKR2", "ARM")),
selected = "AVALC",
multiple = TRUE,
fixed = FALSE
),
filter = list(
filter_spec(
label = "Select endpoints:",
vars = "PARAMCD",
choices = value_choices(data[["ADRS"]], "PARAMCD", "PARAM"),
selected = "BESRSPI",
multiple = TRUE
),
filter_spec(
label = "Select endpoints:",
vars = "AVISIT",
choices = levels(data[["ADRS"]]$AVISIT),
selected = "SCREENING",
multiple = TRUE
)
)
)
)
# configuration for wide and long datasets
mod4 <- tm_g_association(
label = "Wide and long datasets",
ref = data_extract_spec(
dataname = "ADRS",
select = select_spec(
choices = variable_choices(data[["ADRS"]], c("AVAL", "AVALC")),
selected = "AVALC",
multiple = FALSE,
fixed = FALSE,
label = "Selected variable:"
),
filter = list(
filter_spec(
vars = "PARAMCD",
choices = value_choices(data[["ADRS"]], "PARAMCD", "PARAM"),
selected = levels(data[["ADRS"]]$PARAMCD),
multiple = TRUE,
label = "Select response"
),
filter_spec(
vars = "AVISIT",
choices = levels(data[["ADRS"]]$AVISIT),
selected = levels(data[["ADRS"]]$AVISIT),
multiple = TRUE,
label = "Select visit:"
)
)
),
vars = data_extract_spec(
dataname = "ADSL",
select = select_spec(
choices = variable_choices(data[["ADSL"]], c("SEX", "AGE", "RACE", "COUNTRY", "BMRKR1", "STRATA1", "ARM")),
selected = "AGE",
multiple = TRUE,
fixed = FALSE,
label = "Select variable:"
)
)
)
# configuration for the same long dataset (same subsets)
mod5 <- tm_g_association(
label = "Same long datasets (same subsets)",
ref = data_extract_spec(
dataname = "ADRS",
select = select_spec(
choices = variable_choices(data[["ADRS"]]),
selected = "AVALC",
multiple = FALSE,
fixed = FALSE,
label = "Select variable:"
)
),
vars = data_extract_spec(
dataname = "ADRS",
select = select_spec(
choices = variable_choices(data[["ADRS"]]),
selected = "PARAMCD",
multiple = TRUE,
fixed = FALSE,
label = "Select variable:"
)
)
)
# configuration for the same long dataset (different subsets)
mod6 <- tm_g_association(
label = "Same long datasets (different subsets)",
ref = data_extract_spec(
dataname = "ADLB",
filter = list(
filter_spec(
vars = "PARAMCD",
choices = value_choices(data[["ADLB"]], "PARAMCD", "PARAM"),
selected = levels(data[["ADLB"]]$PARAMCD)[1],
multiple = FALSE,
label = "Select lab:"
),
filter_spec(
vars = "AVISIT",
choices = levels(data[["ADLB"]]$AVISIT),
selected = levels(data[["ADLB"]]$AVISIT)[1],
multiple = FALSE,
label = "Select visit:"
)
),
select = select_spec(
choices = variable_choices(data[["ADLB"]], c("AVAL", "CHG2", "PCHG2")),
selected = "AVAL",
multiple = FALSE
)
),
vars = data_extract_spec(
dataname = "ADLB",
filter = list(
filter_spec(
vars = "PARAMCD",
choices = value_choices(data[["ADLB"]], "PARAMCD", "PARAM"),
selected = levels(data[["ADLB"]]$PARAMCD)[1],
multiple = FALSE,
label = "Select labs:"
),
filter_spec(
vars = "AVISIT",
choices = levels(data[["ADLB"]]$AVISIT),
selected = levels(data[["ADLB"]]$AVISIT)[1],
multiple = FALSE,
label = "Select visit:"
)
),
select = select_spec(
choices = variable_choices(data[["ADLB"]]),
selected = "STRATA1",
multiple = TRUE
)
)
)
# initialize the app
app <- init(
data = data,
modules = modules(
# tm_g_association ----
modules(
label = "Association plot",
mod1,
mod2,
mod3,
mod4,
mod5,
mod6
)
)
)
```
## 4 - Run the app
A simple `shiny::shinyApp()` call will let you run the app. Note that app is only displayed when running this code inside an `R` session.
```{r, echo=TRUE, results="hide", eval=base::interactive()}
shinyApp(app$ui, app$server, options = list(height = 1024, width = 1024))
```
<img src="images/app-using-association-plot.png" style="display: block; margin: 0px; width: 100%"/>