Skip to content

Commit bed6481

Browse files
committed
Update vignettes with new functionality
1 parent f9b2cc7 commit bed6481

File tree

5 files changed

+240
-10
lines changed

5 files changed

+240
-10
lines changed

R/internal.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@
285285
# To create ellipsis shape and avoid overlapping between both of them,
286286
# set the height to 80% of the SE (minimum scaled in x-axis or y-axis range)
287287
width <- (100 - start_binary_endpoint) * min(binary_meta$se) / 100
288-
y_range <- (max(actv_y, ctrl_y) + 10) * min(binary_meta$se) / 100
288+
y_range <- ((max(actv_y, ctrl_y) + 10) * min(binary_meta$se) / 100) * 0.6
289289
y_height <- min(c(0.4 * abs(actv_y - ctrl_y), 0.8 * min(width, y_range)))
290290

291291
# Create ellipsis centered around proportion estimate (x0) as well as

R/internal_winOdds.R

+13-5
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@
5454
GROUP = "outcome")
5555

5656
endpoints <- c(step_outcomes, last_outcome)
57-
labs <- c(Reduce(paste, as.character(endpoints[1:(length(endpoints) - 1)]),
58-
accumulate = TRUE), "All")
57+
labs <- c(sapply(head(seq_along(endpoints), -1), function(i) {
58+
paste(endpoints[1:i], collapse = " +\n")
59+
}), "All")
5960

6061
hce_dat <- hce_dat %>%
6162
dplyr::mutate_at(dplyr::vars(outcome), factor, levels = c(endpoints, "X"))
@@ -208,11 +209,18 @@
208209

209210
if (theme != "none") {
210211
plot <- plot +
211-
theme_bw() +
212-
theme(legend.position = "bottom", legend.title = element_blank()) +
212+
ggplot2::geom_vline(xintercept =
213+
seq(0.5, length(levels(wins_forest$GROUP)) + 1.5,
214+
1),
215+
linetype = 2, linewidth = 0.3, color = "darkgray") +
213216
scale_color_manual(values = c("black", "grey50")) +
214217
scale_fill_manual(values = c("black", "grey50")) +
215-
ylab("Win Odds / Win Ratio")
218+
ylab("Win Odds / Win Ratio") +
219+
theme_bw() +
220+
theme(legend.position = "bottom",
221+
legend.title = element_blank(),
222+
panel.grid.major.y = ggplot2::element_blank(),
223+
panel.grid.minor.y = ggplot2::element_blank())
216224
}
217225

218226
return(plot)

R/winOddsPlots.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ cumulative_plot.maraca <- function(x, theme = "maraca", ...) {
225225
plot_forest <- .create_forest_plot(wins_forest, theme)
226226

227227
plot <- patchwork:::"|.ggplot"(plot_bar, plot_forest) +
228-
patchwork::plot_layout(widths = c(3, 1), nrow = 1)
228+
patchwork::plot_layout(widths = c(2.5, 1), nrow = 1)
229229

230230
# Add class to plot - cumulativePlot
231231
class(plot) <- c("cumulativePlot", class(plot))

vignettes/otherEndpoints.Rmd

+180
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
---
2+
title: "Maraca Plots - Alternative Endpoints"
3+
author: "Monika Huhn"
4+
date: "`r Sys.Date()`"
5+
output: rmarkdown::html_vignette
6+
vignette: >
7+
%\VignetteIndexEntry{Maraca Plots - Alternative Endpoints}
8+
%\VignetteEngine{knitr::rmarkdown}
9+
\usepackage[utf8]{inputenc}
10+
---
11+
12+
```{r setup, include = FALSE}
13+
knitr::opts_chunk$set(echo = TRUE, collapse = TRUE)
14+
library(dplyr)
15+
library(maraca)
16+
```
17+
18+
The maraca package can also be used for hierarchical endpoints containing other type of endpoints than
19+
time-to-event and continuous. Currently binary endpoints are also supported with further type of
20+
endpoints under development
21+
22+
23+
## Binary endpoints
24+
25+
### Last outcome
26+
27+
First we go through an example where the final outcome instead of being continuous, is a binary outcome.
28+
As an example, this could for example be weight loss above a certain threshold at the end of the study.
29+
The way the outcome should be included in the data is as a numeric vector with 1 for those patients that
30+
had the outcome and 0 for those that had not.
31+
32+
We do not have any example dataset with a final binary endpoint included in the package, so for
33+
this vignette we modify an existing dataset:
34+
35+
```{r}
36+
data("hce_scenario_a")
37+
# Create data with binary version of continuous final endpoint
38+
bin_data <- hce_scenario_a
39+
# Index of all continuous outcome rows
40+
idx_cont <- bin_data$GROUP == "Continuous outcome"
41+
# Rename outcome
42+
bin_data[idx_cont,"GROUP"] <- "Binary outcome"
43+
# Binary version (>= 0/< 0)
44+
bin_data[idx_cont,"AVAL0"] <- bin_data[idx_cont,"AVAL0"] >= 0
45+
bin_data[idx_cont,"AVAL"] <- bin_data[idx_cont,"AVAL0"] +
46+
bin_data[idx_cont,"GROUPN"]
47+
head(bin_data)
48+
```
49+
50+
If we now want to create a maraca object for this data, we need to slightly update
51+
the default code. By default, maraca expects the last outcome to be continuous. In
52+
order for the function to know that the last outcome is binary, we have to update
53+
the parameter `last_type`. The parameter currently accepts the inputs `"binary"` and
54+
`"continuous"`.
55+
```{r}
56+
column_names <- c(
57+
outcome = "GROUP",
58+
arm = "TRTP",
59+
value = "AVAL0"
60+
)
61+
62+
step_outcomes <- c("Outcome I", "Outcome II",
63+
"Outcome III", "Outcome IV")
64+
65+
last_outcome <- "Binary outcome"
66+
67+
arm_levels <- c(active = "Active",
68+
control = "Control")
69+
70+
mar <- maraca(
71+
bin_data, step_outcomes, last_outcome,
72+
arm_levels, column_names,
73+
fixed_followup_days = 3*365,
74+
compute_win_odds = TRUE,
75+
# Important change: Add information that last endpoint is
76+
# not continuous (the default)
77+
last_type = "binary"
78+
)
79+
```
80+
81+
The maraca object can now be plotted. A binary endpoint is plotted
82+
as an ellipsis. The point in the middle of the ellipsis indicates the
83+
proportion that has met the binary endpoint. The width of the ellipsis
84+
(x-axis range) shows the confidence interval.
85+
Specifying `vline_type = "mean"` (the default) will add vertical lines
86+
indicating the proportions in each treatment group for easier readibility.
87+
Note that `vline_type = "median"` (the default for continuous endpoints)
88+
will result in an error. The same is true for setting `density_plot_type` to
89+
anything other than `"default"`.
90+
```{r fig.width = 7, fig.height = 6}
91+
plot(mar)
92+
```
93+
94+
95+
### Step outcome
96+
97+
What if the binary outcome is not the last outcome of the hierarchical endpoint
98+
but rather one (or several) of the previous outcomes? So rather than solely having
99+
time-to-event endpoints within the step function part of the plot, we also have
100+
at least one binary (so not time depending) variable.
101+
To include a binary variable, we expect the data for this outcome to include only
102+
patients that had the outcome and they all have to have the original analysis value 1.
103+
104+
Let's create a dataset with 2 binary outcomes.
105+
```{r}
106+
data("hce_scenario_a")
107+
# Create data with binary version of continuous final endpoint
108+
bin_data2 <- hce_scenario_a
109+
# Index of all continuous outcome rows
110+
idx_bin <- bin_data2$GROUP %in% c("Outcome III", "Outcome IV")
111+
# Binary version (>= 0/< 0), coded as 1
112+
bin_data2[idx_bin,"AVAL0"] <- bin_data2[idx_bin,"AVAL0"] >= 500
113+
bin_data2[idx_bin,"AVAL"] <- bin_data2[idx_bin,"AVAL0"] +
114+
bin_data2[idx_bin,"GROUPN"]
115+
# Remove 0 rows (only include patients that had the outcome)
116+
bin_data2 <- bin_data2[bin_data2$AVAL0 != 0,]
117+
head(bin_data2)
118+
```
119+
120+
Again we need to slightly update the default code if we want to create a maraca object
121+
for this data. By default, maraca expects all the step outcomes to be time-to-event
122+
endpoints. In order for the function to know that there are binary outcomes, we have to
123+
update the parameter `step_types`. The parameter currently accepts the inputs `"binary"` and
124+
`"tte"`. If all the step outcomes are of the same type, the user can give the type as a string
125+
(such as by default `step_types = "tte"`). If there are different endpoint types, then the user
126+
has to provide a vector with one element for each step outcome.
127+
Similarly, the fixed-follow up time can be given as a single number or a vector. Note that the
128+
fixed-follow-up time is only needed for time-to-event endpoints, so if providing a vector then
129+
it should contain one value for each time-to-event endpoint.
130+
```{r}
131+
column_names <- c(
132+
outcome = "GROUP",
133+
arm = "TRTP",
134+
value = "AVAL0"
135+
)
136+
137+
step_outcomes <- c("Outcome I", "Outcome II",
138+
"Outcome III", "Outcome IV")
139+
140+
last_outcome <- "Continuous outcome"
141+
142+
arm_levels <- c(active = "Active",
143+
control = "Control")
144+
145+
mar <- maraca(
146+
bin_data2, step_outcomes, last_outcome,
147+
arm_levels, column_names,
148+
fixed_followup_days = 3*365,
149+
compute_win_odds = TRUE,
150+
# Important change: Add information that last endpoint is
151+
# not continuous (the default)
152+
step_types = c("tte","tte","binary","binary")
153+
)
154+
```
155+
156+
Again, we can plot the final object.
157+
```{r fig.width = 7, fig.height = 6}
158+
plot(mar)
159+
```
160+
161+
162+
As with all maraca objects, the different plotting parameters can be
163+
used.
164+
165+
```{r fig.width = 7, fig.height = 6}
166+
plot(mar, continuous_grid_spacing_x = 20,
167+
theme = "color1")
168+
```
169+
170+
Also, the win odds plots can be created as usual.
171+
```{r fig.width = 7, fig.height = 6}
172+
component_plot(mar,
173+
theme = "color2")
174+
```
175+
176+
```{r fig.width = 7, fig.height = 6}
177+
cumulative_plot(mar,
178+
theme = "color1")
179+
```
180+

vignettes/winOdds.Rmd

+45-3
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,51 @@ hce_dat <- simHCE(n = 2500, TTE_A = Rates_A, TTE_P = Rates_P,
7676
component_plot(hce_dat)
7777
```
7878

79+
## Cumulative plot
80+
81+
Furthermore, there is also a plot called `"cumulative_plot"`.
82+
Similar as above, this plot shows the different components that
83+
make up the win odds calculation. Different to the component plot,
84+
this plot shows the endpoint cumulated instead (adding one
85+
hierarchical endpoint at a time).
86+
As explained above, the plot shows how
87+
often patients in the active arm "won" or "lost" against the other
88+
arm or if they had a "tie".
89+
90+
As before, in order to use the `cumulative_plot`, we have to first create a
91+
`maraca` object. Important here is to set the argument
92+
`compute_win_odds = TRUE`, so that the necessary calculations
93+
are included.
94+
```{r}
95+
maraca_dat <- maraca(
96+
data = hce_scenario_a,
97+
step_outcomes = c("Outcome I", "Outcome II", "Outcome III", "Outcome IV"),
98+
last_outcome = "Continuous outcome",
99+
fixed_followup_days = 3 * 365,
100+
column_names = c(outcome = "GROUP", arm = "TRTP", value = "AVAL0"),
101+
arm_levels = c(active = "Active", control = "Control"),
102+
# Make sure to calculate the win odds
103+
compute_win_odds = TRUE
104+
)
105+
```
106+
107+
Now we can just plot the object using the `cumulative_plot()` function.
108+
```{r fig.width=7, fig.height=6}
109+
cumulative_plot(maraca_dat)
110+
```
111+
112+
It is also possible to use the `cumulative_plot()` function directly on
113+
an `hce` object (created using the
114+
[hce package](https://cran.r-project.org/package=hce)).
115+
116+
```{r fig.width=7, fig.height=6}
117+
cumulative_plot(hce_dat)
118+
```
119+
79120
## Styling
80121

81-
The resulting plot is a normal ggplot2 object that can be styled accordingly.
122+
The resulting plots for both the `component_plot()` and `cumulative_plot()` functions
123+
are normal ggplot2 objects that can be styled accordingly.
82124
There are also different themes available to style the plot.
83125

84126
The default style is called `theme = "maraca"`.
@@ -89,7 +131,7 @@ component_plot(maraca_dat, theme = "maraca")
89131
There are 2 different themes with different color
90132
schemes, `theme = "color1"` and `theme = "color2"`.
91133
```{r fig.width=7, fig.height=6}
92-
component_plot(maraca_dat, theme = "color1")
134+
cumulative_plot(maraca_dat, theme = "color1")
93135
```
94136

95137
```{r fig.width=7, fig.height=6}
@@ -98,5 +140,5 @@ component_plot(maraca_dat, theme = "color2")
98140

99141
There is also a theme without any styling `theme = "none"`.
100142
```{r fig.width=8, fig.height=6}
101-
component_plot(maraca_dat, theme = "none")
143+
cumulative_plot(maraca_dat, theme = "none")
102144
```

0 commit comments

Comments
 (0)