-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getting-started.Rmd
129 lines (104 loc) · 3.51 KB
/
getting-started.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
---
title: "Getting Started"
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
Suppose you need to create the table below, and need an ARD representation of the results to get started.
Here, we will review an examples for creating a basic demographics table.
To get started, load the **{cards}** package.
```{r setup}
library(cards)
```
### Demographics
```{r, echo=FALSE, message=FALSE}
gtsummary::theme_gtsummary_compact()
ADSL |>
dplyr::select(ARM, AGE, AGEGR1, SEX) |>
dplyr::mutate(
ARM = factor(ARM, levels = c("Placebo", "Xanomeline Low Dose", "Xanomeline High Dose")),
AGEGR1 = factor(AGEGR1, levels = c("<65", "65-80", ">80"), labels = c("<65", "65-80", ">80"))
) |>
gtsummary::tbl_summary(
by = ARM,
type = AGE ~ "continuous2",
statistic = AGE ~ c("{median} ({p25}, {p75})", "{mean} ({sd})", "{min} - {max}"),
value = SEX ~ "F",
label = list(SEX = "Female", AGEGR1 = "Age Group"),
digits = gtsummary::all_categorical() ~ 0L
) |>
gtsummary::add_stat_label() |>
gtsummary::bold_labels() |>
gtsummary::modify_header(gtsummary::all_stat_cols() ~ "**{level}** \nN = {n}") |>
gtsummary::modify_column_alignment(columns = -label, "right") |>
gtsummary::as_gt() |>
gt::cols_width(gtsummary::all_stat_cols() ~ gt::pct(23)) |>
gt::opt_table_font(stack = "monospace-code")
```
The table above has three types of data summaries: a **continuous** variable summary for `AGE`, a **categorical** variable summary for `AGEGR1`, and a **dichotomous** variable summary for `SEX`.
#### Continuous Summaries
To get a continuous variable summary, we will use the `ard_continuous()` function from the **{cards}** package.
```{r}
df_continuous_ard <-
ard_continuous(
ADSL,
by = ARM,
variables = AGE,
statistic = ~ continuous_summary_fns(c("median", "p25", "p75", "mean", "sd", "min", "max"))
)
df_continuous_ard |> head(5)
```
#### Categorical Summaries
To get the categorical variable summary, we will use the `ard_categorical()` function.
```{r}
df_categorical_ard <-
ard_categorical(
ADSL,
by = ARM,
variables = AGEGR1
)
df_categorical_ard |> head(5)
```
#### Dichotomous Summaries
To get the dichotomous variable summary, we will use `ard_dichotomous()`.
In this case, we want to show the Female (`"F"`) level of the `SEX` variable and specify this with the `values` argument.
```{r}
df_dichotomous_ard <-
ard_dichotomous(
ADSL,
by = ARM,
variables = SEX,
value = list(SEX = "F")
)
df_dichotomous_ard |> head(5)
```
#### Combine Results
As a last step, you can combine all of these objects into a single object using `bind_ard()`, which is similar to `dplyr::bind_rows()` and includes additional structural checks for our results.
```{r}
bind_ard(
df_continuous_ard,
df_categorical_ard,
df_dichotomous_ard
)
```
#### Shortcut
The `ard_stack()` function provides a shortcut to perform the calculations above in a single step.
In the example below, the `data` and `by` arguments are passed to each subsequent `ard_*()` function call.
Moreover, we will also be returned the univariate tabulation of the `by` variable, which would be used to add counts to the header row of the table.
```{r}
ard_stack(
data = ADSL,
.by = ARM,
ard_continuous(
variables = AGE,
statistic = ~ continuous_summary_fns(c("median", "p25", "p75", "mean", "sd", "min", "max"))
),
ard_categorical(variables = AGEGR1),
ard_dichotomous(variables = SEX, value = list(SEX = "F"))
)
```
### Adverse Events
_Example Coming Soon!_