-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
200 lines (169 loc) · 5.6 KB
/
README.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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "75%"
)
library(dplyr)
library(tidyr)
library(gt)
```
# BayesERtools <a href="https://genentech.github.io/BayesERtools/"><img src="man/figures/logo.png" align="right" height="138" alt="BayesERtools website" /></a>
<!-- badges: start -->
[](https://github.com/Genentech/BayesERtools/actions/workflows/R-CMD-check.yaml)
[](https://CRAN.R-project.org/package=BayesERtools)
[](https://CRAN.R-project.org/package=BayesERtools)
[](https://app.codecov.io/gh/Genentech/BayesERtools?branch=main)
<!-- badges: end -->
`BayesERtools` provides a suite of tools that facilitate
exposure-response analysis using Bayesian methods.
- Tutorial (`BayesERbook`): https://genentech.github.io/BayesERbook/
- Package documentation: https://genentech.github.io/BayesERtools/
- GitHub repo of the package: https://github.com/genentech/BayesERtools/
## Installation
You can install the `BayesERtools` with:
``` r
install.packages('BayesERtools')
# devtools::install_github("genentech/BayesERtools") # development version
```
## Supported model types
```{r, echo = FALSE}
set.seed(1234) # Needed to stablize div id
# Need to do this to remove CSS from the outputs for it
# to work in GitLab-flavored md
remove_css <- function(x) {
x <- gsub("<style>.*</style>", "", x)
htmltools::HTML(x)
}
# Define the initial transposed tibble
tab_mod_raw <- tibble(
feature = c("lin_logit", "emax_logit", "linear", "emax"),
backend = c("`rstanarm`", "`rstanemax`", "`rstanarm`", "`rstanemax`"),
reference =
c(
"https://mc-stan.org/rstanarm/reference/stan_glm.html",
"https://yoshidk6.github.io/rstanemax/reference/stan_emax.html",
"https://mc-stan.org/rstanarm/reference/stan_glm.html",
"https://yoshidk6.github.io/rstanemax/reference/stan_emax_binary.html"
),
`develop model` = c("✅", "✅", "✅", "✅"),
`simulate & plot ER` = c("✅", "✅", "✅", "✅"),
`exposure metrics selection` = c("✅", "✅", "✅", "✅"),
`covariate selection` = c("✅", "❌", "✅", "❌"),
`covariate forest plot` = c("✅", "❌", "🟡", "❌")
)
# Transpose the table for display
tab_mod <- tab_mod_raw %>%
pivot_longer(
cols = -feature,
names_to = "feature_name", values_to = "value"
) %>%
pivot_wider(names_from = feature, values_from = value) |>
mutate(.row_id = row_number())
readr::write_csv(tab_mod, "vignettes/data/supported_models.csv")
tab_mod |>
select(-.row_id) |>
gt() |>
fmt_markdown() |>
fmt_url(
columns = !1,
rows = 2,
label = "🔗",
show_underline = FALSE
) |>
tab_spanner(
label = "Binary endpoint",
columns = c(lin_logit, emax_logit)
) |>
tab_spanner(
label = "Continuous endpoint",
columns = c(linear, emax)
) |>
cols_label(
feature_name = "",
lin_logit = "Linear (logit)",
emax_logit = md("E<sub/>max</sub> (logit)"),
linear = "Linear",
emax = md("E<sub/>max</sub>"),
) |>
tab_style(
style = cell_text(v_align = "top", align = "center"),
locations = cells_column_labels()
) |>
tab_style(
style = cell_text(v_align = "middle", align = "center"),
locations = cells_body()
) |>
tab_style(
style = cell_text(v_align = "middle", align = "right"),
locations = cells_body(columns = feature_name)
) |>
tab_footnote(
footnote = paste(
"✅ Available",
"🟡 In plan/under development",
"❌ Not in a current plan",
sep = ", "
)
) |>
as_raw_html(inline_css = FALSE) |>
remove_css()
```
## Quick guide
Here is a quick demo on how to use this package for E-R analysis.
See [Basic workflow](https://genentech.github.io/BayesERbook/notebook/binary/basic_workflow.html) for
more thorough walk through.
```{r, warning=FALSE, message=FALSE}
# Load package and data
library(dplyr)
library(BayesERtools)
ggplot2::theme_set(ggplot2::theme_bw(base_size = 12))
data(d_sim_binom_cov)
# Hyperglycemia Grade 2+ (hgly2) data
df_er_ae_hgly2 <-
d_sim_binom_cov |>
filter(AETYPE == "hgly2") |>
# Re-scale AUCss, baseline age
mutate(
AUCss_1000 = AUCss / 1000, BAGE_10 = BAGE / 10,
Dose = paste(Dose_mg, "mg")
)
var_resp <- "AEFLAG"
```
### Simple univariable model for binary endpoint
```{r ermod_bin, fig.width = 6, fig.height = 4.5, dpi = 150}
set.seed(1234)
ermod_bin <- dev_ermod_bin(
data = df_er_ae_hgly2,
var_resp = var_resp,
var_exposure = "AUCss_1000"
)
ermod_bin
# Using `*` instead of `+` so that scale can be
# applied for both panels (main plot and boxplot)
plot_er_gof(ermod_bin, var_group = "Dose", show_coef_exp = TRUE) *
xgxr::xgx_scale_x_log10()
```
### Covariate selection
BGLUC (baseline glucose) is selected while other two covariates are not.
```{r ermod_bin_cov_sel, fig.width = 6, fig.height = 4, dpi = 150}
set.seed(1234)
ermod_bin_cov_sel <-
dev_ermod_bin_cov_sel(
data = df_er_ae_hgly2,
var_resp = var_resp,
var_exposure = "AUCss_1000",
var_cov_candidate = c("BAGE_10", "RACE", "BGLUC")
)
ermod_bin_cov_sel
plot_submod_performance(ermod_bin_cov_sel)
```
```{r plot_coveff, fig.width = 5, fig.height = 3, dpi = 150}
coveffsim <- sim_coveff(ermod_bin_cov_sel)
plot_coveff(coveffsim)
```