|
1 |
| ---- |
2 |
| -title: "Maraca Plots - Plotting win odds" |
3 |
| -author: "Monika Huhn" |
4 |
| -date: "10/10/2023" |
5 |
| -output: rmarkdown::html_vignette |
6 |
| -vignette: > |
7 |
| - %\VignetteIndexEntry{Maraca Plots - Plotting win odds} |
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(ggplot2) |
16 |
| -library(maraca) |
17 |
| -``` |
18 |
| - |
19 |
| -## Component plot |
20 |
| - |
21 |
| -The maraca package also contains an additional plot |
22 |
| -called `"component_plot"`. This one allows to plot the |
23 |
| -different components that make up the win odds calculation. |
24 |
| -More specifically, for each outcome, the plot shows how |
25 |
| -often patients in each treatment arm "won" against the other |
26 |
| -arm. For the time-to-event endpoints, this means counting how many |
27 |
| -patients of the other arm had no more prioritized event prior. |
28 |
| -For the continuous outcome this means counting how many patients had a lower value. |
29 |
| -The results are separated for each outcome (non-cumulative) |
30 |
| -and also include ties (patients from 2 treatment arms having same |
31 |
| -outcome at the same time/same continuous outcome value). |
32 |
| - |
33 |
| -Let us first read in some data. |
34 |
| -```{r maraca1, eval = TRUE} |
35 |
| -library(maraca) |
36 |
| -
|
37 |
| -data(hce_scenario_a) |
38 |
| -``` |
39 |
| - |
40 |
| -In order to use the `component_plot`, we have to first create a |
41 |
| -`maraca` object. Important here is to set the argument |
42 |
| -`compute_win_odds = TRUE`, so that the necessary calculations |
43 |
| -are included. |
44 |
| -```{r} |
45 |
| -maraca_dat <- maraca( |
46 |
| - data = hce_scenario_a, |
47 |
| - step_outcomes = c("Outcome I", "Outcome II", "Outcome III", "Outcome IV"), |
48 |
| - last_outcome = "Continuous outcome", |
49 |
| - fixed_followup_days = 3 * 365, |
50 |
| - column_names = c(outcome = "GROUP", arm = "TRTP", value = "AVAL0"), |
51 |
| - arm_levels = c(active = "Active", control = "Control"), |
52 |
| - # Make sure to calculate the win odds |
53 |
| - compute_win_odds = TRUE |
54 |
| -) |
55 |
| -``` |
56 |
| - |
57 |
| -Now we can just plot the object using the `component_plot()` function. |
58 |
| -```{r fig.width=7, fig.height=6} |
59 |
| -component_plot(maraca_dat) |
60 |
| -``` |
61 |
| - |
62 |
| -It is also possible to use the `component_plot()` function directly on |
63 |
| -an `hce` object (created using the |
64 |
| -[hce package](https://cran.r-project.org/package=hce)). |
65 |
| - |
66 |
| -```{r fig.width=7, fig.height=6} |
67 |
| -library(hce) |
68 |
| -
|
69 |
| -Rates_A <- c(1.72, 1.74, 0.58, 1.5, 1) |
70 |
| -Rates_P <- c(2.47, 2.24, 2.9, 4, 6) |
71 |
| -
|
72 |
| -hce_dat <- simHCE(n = 2500, TTE_A = Rates_A, TTE_P = Rates_P, |
73 |
| - CM_A = -3, CM_P = -6, CSD_A = 16, CSD_P = 15, fixedfy = 3, |
74 |
| - seed = 31337) |
75 |
| -
|
76 |
| -component_plot(hce_dat) |
77 |
| -``` |
78 |
| - |
79 |
| -## Cumulative plot |
80 |
| - |
81 |
| -Furthermore, there is also a plot called `"cumulative_plot"`. |
82 |
| -Similar to the `component_plot`, this plot shows the different HCE components that |
83 |
| -make up the win odds calculation. Different to the component plot, |
84 |
| -this plot provides insight into the contributed effect for each of the components as |
85 |
| -they are added in sequence (from top to bottom). |
86 |
| -Additionally, there is also a right-hand panel that shows a forest plot with the win odds |
87 |
| -and win ratio corresponding to the same cumulative sequence. To understand the contribution |
88 |
| -from each outcome, we artificially set all the less prioritized outcomes as ties and calculate |
89 |
| -the win odds/ratio. Thus, for each added outcome there will be less ties. |
90 |
| - |
91 |
| -As before, in order to use the `cumulative_plot`, we have to first create a |
92 |
| -`maraca` object. Important here is to set the argument |
93 |
| -`compute_win_odds = TRUE`, so that the necessary calculations |
94 |
| -are included. |
95 |
| -```{r} |
96 |
| -maraca_dat <- maraca( |
97 |
| - data = hce_scenario_a, |
98 |
| - step_outcomes = c("Outcome I", "Outcome II", "Outcome III", "Outcome IV"), |
99 |
| - last_outcome = "Continuous outcome", |
100 |
| - fixed_followup_days = 3 * 365, |
101 |
| - column_names = c(outcome = "GROUP", arm = "TRTP", value = "AVAL0"), |
102 |
| - arm_levels = c(active = "Active", control = "Control"), |
103 |
| - # Make sure to calculate the win odds |
104 |
| - compute_win_odds = TRUE |
105 |
| -) |
106 |
| -``` |
107 |
| - |
108 |
| -Now we can just plot the object using the `cumulative_plot()` function. |
109 |
| -```{r fig.width=7, fig.height=6} |
110 |
| -cumulative_plot(maraca_dat) |
111 |
| -``` |
112 |
| - |
113 |
| -It is also possible to use the `cumulative_plot()` function directly on |
114 |
| -an `hce` object (created using the |
115 |
| -[hce package](https://cran.r-project.org/package=hce)). |
116 |
| - |
117 |
| -```{r fig.width=7, fig.height=6} |
118 |
| -cumulative_plot(hce_dat) |
119 |
| -``` |
120 |
| - |
121 |
| -The user can also choose to only display one of the statistics (win odds or win ratio) |
122 |
| -by specifying so in the `include` parameter. |
123 |
| -```{r fig.width=7, fig.height=6} |
124 |
| -cumulative_plot(maraca_dat, include = "win odds") |
125 |
| -``` |
126 |
| - |
127 |
| -The y-axis can easily be reversed using the `reverse` parameter. |
128 |
| -```{r fig.width=7, fig.height=6} |
129 |
| -cumulative_plot(hce_dat, reverse = TRUE) |
130 |
| -``` |
131 |
| - |
132 |
| -## Styling |
133 |
| - |
134 |
| -The resulting plot for the `component_plot()` functions |
135 |
| -is a normal ggplot2 object that can be styled accordingly. |
136 |
| -```{r fig.width=7, fig.height=6} |
137 |
| -component_plot(maraca_dat) + |
138 |
| - ggplot2::scale_fill_manual(values = c("seagreen", "red", "grey"), name = NULL) |
139 |
| -``` |
140 |
| - |
141 |
| -Note that the `cumulative_plot()` function is using the |
142 |
| -patchwork package to combine 2 ggplot2 objects. They |
143 |
| -can be accessed as list items and styled accordingly. |
144 |
| -```{r fig.width=7, fig.height=6} |
145 |
| -p <- cumulative_plot(maraca_dat) |
146 |
| -p[[1]] <- p[[1]] + |
147 |
| - ggplot2::scale_fill_manual(values = c("seagreen", "red", "grey"), name = NULL) |
148 |
| -p |
149 |
| -``` |
150 |
| - |
151 |
| -For the users convenience, there are also different themes |
152 |
| -available to style the plot. |
153 |
| - |
154 |
| -The default style is called `theme = "maraca"`. |
155 |
| -```{r fig.width=7, fig.height=6} |
156 |
| -component_plot(maraca_dat, theme = "maraca") |
157 |
| -``` |
158 |
| - |
159 |
| -There are 2 different themes with different color |
160 |
| -schemes, `theme = "color1"` and `theme = "color2"`. |
161 |
| -```{r fig.width=7, fig.height=6} |
162 |
| -cumulative_plot(maraca_dat, theme = "color1") |
163 |
| -``` |
164 |
| - |
165 |
| -```{r fig.width=7, fig.height=6} |
166 |
| -component_plot(maraca_dat, theme = "color2") |
167 |
| -``` |
168 |
| - |
169 |
| -There is also a theme without any styling `theme = "none"` that |
170 |
| -can be used as a base when the user wants to style the plot themselves. |
171 |
| -```{r fig.width=8, fig.height=6} |
172 |
| -cumulative_plot(maraca_dat, theme = "none") |
173 |
| -``` |
| 1 | +--- |
| 2 | +title: "Maraca Plots - Plotting win odds" |
| 3 | +author: "Monika Huhn" |
| 4 | +date: "10/10/2023" |
| 5 | +output: rmarkdown::html_vignette |
| 6 | +vignette: > |
| 7 | + %\VignetteIndexEntry{Maraca Plots - Plotting win odds} |
| 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(ggplot2) |
| 16 | +library(maraca) |
| 17 | +``` |
| 18 | + |
| 19 | +## Component plot |
| 20 | + |
| 21 | +The maraca package also contains an additional plot |
| 22 | +called `"component_plot"`. This one allows to plot the |
| 23 | +different components that make up the win odds calculation. |
| 24 | +More specifically, for each outcome, the plot shows how |
| 25 | +often patients in each treatment arm "won" against the other |
| 26 | +arm. For the time-to-event endpoints, this means counting how many |
| 27 | +patients of the other arm had no more prioritized event prior. |
| 28 | +For the continuous outcome this means counting how many patients had a lower value. |
| 29 | +The results are separated for each outcome (non-cumulative) |
| 30 | +and also include ties (patients from 2 treatment arms having same |
| 31 | +outcome at the same time/same continuous outcome value). |
| 32 | + |
| 33 | +Let us first read in some data. |
| 34 | +```{r maraca1, eval = TRUE} |
| 35 | +library(maraca) |
| 36 | +
|
| 37 | +data(hce_scenario_a) |
| 38 | +``` |
| 39 | + |
| 40 | +In order to use the `component_plot`, we have to first create a |
| 41 | +`maraca` object. Important here is to set the argument |
| 42 | +`compute_win_odds = TRUE`, so that the necessary calculations |
| 43 | +are included. |
| 44 | +```{r} |
| 45 | +maraca_dat <- maraca( |
| 46 | + data = hce_scenario_a, |
| 47 | + step_outcomes = c("Outcome I", "Outcome II", "Outcome III", "Outcome IV"), |
| 48 | + last_outcome = "Continuous outcome", |
| 49 | + fixed_followup_days = 3 * 365, |
| 50 | + column_names = c(outcome = "GROUP", arm = "TRTP", value = "AVAL0"), |
| 51 | + arm_levels = c(active = "Active", control = "Control"), |
| 52 | + # Make sure to calculate the win odds |
| 53 | + compute_win_odds = TRUE |
| 54 | +) |
| 55 | +``` |
| 56 | + |
| 57 | +Now we can just plot the object using the `component_plot()` function. |
| 58 | +```{r fig.width=7, fig.height=6} |
| 59 | +component_plot(maraca_dat) |
| 60 | +``` |
| 61 | + |
| 62 | +It is also possible to use the `component_plot()` function directly on |
| 63 | +an `hce` object (created using the |
| 64 | +[hce package](https://cran.r-project.org/package=hce)). |
| 65 | + |
| 66 | +```{r fig.width=7, fig.height=6} |
| 67 | +library(hce) |
| 68 | +
|
| 69 | +Rates_A <- c(1.72, 1.74, 0.58, 1.5, 1) |
| 70 | +Rates_P <- c(2.47, 2.24, 2.9, 4, 6) |
| 71 | +
|
| 72 | +hce_dat <- simHCE(n = 2500, TTE_A = Rates_A, TTE_P = Rates_P, |
| 73 | + CM_A = -3, CM_P = -6, CSD_A = 16, CSD_P = 15, fixedfy = 3, |
| 74 | + seed = 31337) |
| 75 | +
|
| 76 | +component_plot(hce_dat) |
| 77 | +``` |
| 78 | + |
| 79 | +## Cumulative plot |
| 80 | + |
| 81 | +Furthermore, there is a plot called `"cumulative_plot"`. |
| 82 | +Similar to the `component_plot`, this plot shows the different HCE components that |
| 83 | +make up the win odds calculation. Different to the component plot, |
| 84 | +this plot provides insight into the contributed effect for each of the components as |
| 85 | +they are added in sequence (from top to bottom). |
| 86 | +Additionally, there is also a right-hand panel that shows a forest plot with the win odds |
| 87 | +and win ratio corresponding to the same cumulative sequence. To understand the contribution |
| 88 | +from each outcome, we artificially set all the less prioritized outcomes as ties and calculate |
| 89 | +the win odds/ratio. Thus, for each added outcome there will be less ties. |
| 90 | + |
| 91 | +As before, in order to use the `cumulative_plot`, we have to first create a |
| 92 | +`maraca` object. Important here is to set the argument |
| 93 | +`compute_win_odds = TRUE`, so that the necessary calculations |
| 94 | +are included. |
| 95 | +```{r} |
| 96 | +maraca_dat <- maraca( |
| 97 | + data = hce_scenario_a, |
| 98 | + step_outcomes = c("Outcome I", "Outcome II", "Outcome III", "Outcome IV"), |
| 99 | + last_outcome = "Continuous outcome", |
| 100 | + fixed_followup_days = 3 * 365, |
| 101 | + column_names = c(outcome = "GROUP", arm = "TRTP", value = "AVAL0"), |
| 102 | + arm_levels = c(active = "Active", control = "Control"), |
| 103 | + # Make sure to calculate the win odds |
| 104 | + compute_win_odds = TRUE |
| 105 | +) |
| 106 | +``` |
| 107 | + |
| 108 | +Now we can just plot the object using the `cumulative_plot()` function. |
| 109 | +```{r fig.width=7, fig.height=6} |
| 110 | +cumulative_plot(maraca_dat) |
| 111 | +``` |
| 112 | + |
| 113 | +It is also possible to use the `cumulative_plot()` function directly on |
| 114 | +an `hce` object (created using the |
| 115 | +[hce package](https://cran.r-project.org/package=hce)). |
| 116 | + |
| 117 | +```{r fig.width=7, fig.height=6} |
| 118 | +cumulative_plot(hce_dat) |
| 119 | +``` |
| 120 | + |
| 121 | +The user can also choose to only display one of the statistics (win odds or win ratio) |
| 122 | +by specifying so in the `include` parameter. |
| 123 | +```{r fig.width=7, fig.height=6} |
| 124 | +cumulative_plot(maraca_dat, include = "win odds") |
| 125 | +``` |
| 126 | + |
| 127 | +The y-axis can easily be reversed using the `reverse` parameter. |
| 128 | +```{r fig.width=7, fig.height=6} |
| 129 | +cumulative_plot(hce_dat, reverse = TRUE) |
| 130 | +``` |
| 131 | + |
| 132 | +## Styling |
| 133 | + |
| 134 | +The resulting plot for the `component_plot()` functions |
| 135 | +is a normal ggplot2 object that can be styled accordingly. |
| 136 | +```{r fig.width=7, fig.height=6} |
| 137 | +component_plot(maraca_dat) + |
| 138 | + ggplot2::scale_fill_manual(values = c("seagreen", "red", "grey"), name = NULL) |
| 139 | +``` |
| 140 | + |
| 141 | +Note that the `cumulative_plot()` function is using the |
| 142 | +patchwork package to combine 2 ggplot2 objects - the |
| 143 | +bar plot and the forest plot that together make up the |
| 144 | +`cumulative_plot()`. They |
| 145 | +can be accessed as list items and styled accordingly. |
| 146 | +```{r fig.width=7, fig.height=6} |
| 147 | +p <- cumulative_plot(maraca_dat) |
| 148 | +# Accessing the first ggplot2 object and adding styling (bar plot) |
| 149 | +p[[1]] <- p[[1]] + |
| 150 | + ggplot2::scale_fill_manual(values = c("seagreen", "red", "grey"), name = NULL) |
| 151 | +p |
| 152 | +``` |
| 153 | + |
| 154 | +For the users convenience, there are also different themes |
| 155 | +available to style the plot. |
| 156 | + |
| 157 | +The default style is called `theme = "maraca"`. |
| 158 | +```{r fig.width=7, fig.height=6} |
| 159 | +component_plot(maraca_dat, theme = "maraca") |
| 160 | +``` |
| 161 | + |
| 162 | +There are 2 different themes with different color |
| 163 | +schemes, `theme = "color1"` and `theme = "color2"`. |
| 164 | +```{r fig.width=7, fig.height=6} |
| 165 | +cumulative_plot(maraca_dat, theme = "color1") |
| 166 | +``` |
| 167 | + |
| 168 | +```{r fig.width=7, fig.height=6} |
| 169 | +component_plot(maraca_dat, theme = "color2") |
| 170 | +``` |
| 171 | + |
| 172 | +There is also a theme without any styling `theme = "none"` that |
| 173 | +can be used as a base when the user wants to style the plot themselves. |
| 174 | +```{r fig.width=8, fig.height=6} |
| 175 | +cumulative_plot(maraca_dat, theme = "none") |
| 176 | +``` |
0 commit comments