/
ae-specific-subgroup.Rmd
170 lines (129 loc) · 3.97 KB
/
ae-specific-subgroup.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
---
title: "Subgroup Analysis for Specific AE"
output: rmarkdown::html_vignette
vignette: >
%\VignetteEngine{knitr::rmarkdown}
%\VignetteIndexEntry{Subgroup Analysis for Specific AE}
%\VignetteEncoding{UTF-8}
---
```{r, include=FALSE}
knitr::opts_chunk$set(
comment = "#>",
collapse = TRUE,
out.width = "100%",
dpi = 150
)
```
```{r}
library(metalite.ae)
```
## Overview
The AE specific subgroup analysis aims to provide tables to summarize details of
adverse events by subgroup.
The development of AE specific subgroup analysis involves exported functions:
- `prepare_ae_specific_subgroup()`: prepare analysis raw datasets.
- `format_ae_specific_subgroup()`: prepare analysis (mock) outdata with proper format.
- `tlf_ae_specific_subgroup()`: transfer (mock) output dataset to RTF table.
### Analysis preparation
The `prepare_ae_specific_subgroup()` function is designed to be used for multiple purposes.
The input of the function is a `meta` object created by the metalite package.
```{r}
meta <- meta_ae_example()
```
The output of the function is an `outdata` object containing a list of analysis
raw datasets. Key arguments are `subgroup_var`, `subgroup_header`, and
`display_subgroup_total`.
```{r}
outdata <- prepare_ae_specific_subgroup(
meta,
population = "apat",
observation = "wk12",
parameter = "rel",
subgroup_var = "SEX",
subgroup_header = c("TRTA", "SEX"),
display_subgroup_total = TRUE
)
```
```{r}
outdata
```
The output dataset contains commonly used statistics within each `subgroup_var`.
```{r}
outdata$out_all$F
outdata$out_all$M
outdata$out_all$Total
```
The variable is indexed by the order of `outdata$group` and `outdata$subgroup`
within each `subgroup_var`.
```{r}
outdata$group
outdata$subgroup
```
The row is indexed by the order of `name` within each `subgroup_var` analysis output.
```{r}
head(data.frame(outdata$out_all$Total$order, outdata$out_all$Total$name))
```
- `n_pop`: participants in population within each `subgroup_var`.
```{r}
outdata$out_all$F$n_pop
outdata$out_all$M$n_pop
outdata$out_all$Total$n_pop
```
- `n`: number of subjects with AE within each `subgroup_var`.
```{r}
head(outdata$out_all$F$n)
head(outdata$out_all$M$n)
head(outdata$out_all$Total$n)
```
- `prop`: proportion of subjects with AE within each `subgroup_var`.
```{r}
head(outdata$out_all$F$prop)
head(outdata$out_all$M$prop)
head(outdata$out_all$Total$prop)
```
- `diff`: risk difference compared with the `reference_group` within each `subgroup_var`.
```{r}
head(outdata$out_all$Total$diff)
```
### Format output
After we have the raw analysis results, we can use `format_ae_specific_subgroup()`
to prepare the outdata to create RTF tables.
```{r}
tbl <- outdata |> format_ae_specific_subgroup()
head(tbl$tbl)
```
We can hide the total column:
```{r}
tbl <- outdata |> format_ae_specific_subgroup(display = c("n", "prop"))
head(tbl$tbl)
```
Adding risk difference:
```{r}
tbl <- outdata |> format_ae_specific_subgroup(display = c("n", "prop", "diff"))
head(tbl$tbl)
```
### Mock data preparation
We can also use `format_ae_specific_subgroup()` to create mock output data.
The purpose of the `mock` argument is not to create a comprehensive mock table template,
but a handy way to help users create a mock table that mimics the exact output layout.
Additional work is required to develop a flexible mock table generation tool
(for example, a dedicated mock table generation package).
```{r}
tbl <- outdata |> format_ae_specific_subgroup(mock = FALSE)
head(tbl$tbl)
```
### RTF tables
By using `tlf_ae_specific_subgroup()`, we can transfer the output from
`format_ae_specific_subgroup()` to an RTF or PDF table.
```{r}
outdata |>
format_ae_specific_subgroup() |>
tlf_ae_specific_subgroup(
meddra_version = "24.0",
source = "Source: [CDISCpilot: adam-adsl; adae]",
path_outtable = "rtf/ae0specific0sub0gender1.rtf"
)
```
```{r, out.width = "100%", out.height = "400px", echo = FALSE, fig.align = "center"}
knitr::include_graphics("pdf/ae0specific0sub0gender1.pdf")
```