-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathREADME.Rmd
More file actions
156 lines (132 loc) · 4.09 KB
/
README.Rmd
File metadata and controls
156 lines (132 loc) · 4.09 KB
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
---
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)
```
This book provides examples of exposure-response analysis with Bayesian methods.
## Install necessary packages <a href="https://genentech.github.io/BayesERtools/"><img src="resources/BayesERtool-logo.png" align="right" height="138" alt="BayesERtools website" /></a>
The examples utilizes [`BayesERtools`](https://genentech.github.io/BayesERtools/) package.
- Tutorial (`BayesERbook`): https://genentech.github.io/BayesERbook/
- Package documentation: https://genentech.github.io/BayesERtools/
- GitHub repo of the package: https://github.com/genentech/BayesERtools/
You can install the package as follows:
``` r
install.packages('BayesERtools')
# devtools::install_github("genentech/BayesERtools") # development version
```
## Quick Example
```{r quick-ex, fig.width = 6, fig.height = 4.5, dpi = 150}
library(BayesERtools)
library(dplyr)
ggplot2::theme_set(ggplot2::theme_bw(base_size = 12))
# Data
data(d_sim_binom_cov)
df_er_ae_hgly2 <-
d_sim_binom_cov |>
mutate(AUCss_1000 = AUCss / 1000) |>
filter(AETYPE == "hgly2")
# Fit a model
ermod <- dev_ermod_bin(
data = df_er_ae_hgly2,
var_resp = "AEFLAG",
var_exposure = "AUCss_1000"
)
# Goodness-of-fit plot
plot_er_gof(ermod, var_group = "Dose_mg", show_coef_exp = TRUE) *
xgxr::xgx_scale_x_log10(guide = ggplot2::guide_axis(minor.ticks = TRUE))
```
## Model types supported by `BayesERtools`
```{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())
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()
```
## Note for developer
Run `usethis::use_tidy_style(strict = FALSE)` before committing to ensure that the code is formatted
appropriately.