Plots the posterior mean and quantiles over the dose range and
plots error bars at the observed doses. If the data
argument is
specified, the observed means at each dose are also plotted.
output from a call to dreamer_mcmc
.
a vector of doses at which to plot the dose response curve.
a vector of the times at which to plot the posterior (for longitudinal models only).
quantiles of the posterior to be calculated.
a dataframe with column names of "dose" and "response" for individual patient data. Optional columns "n" and "sample_var" can be specified if aggregate data is supplied, but it is recommended that patient-level data be supplied where possible for continuous models, as the posterior weights differ if aggregated data is used. For aggregated continuous data, "response" should be the average of "n" subjects with a sample variance of "sample_var". For aggregated binary data, "response" should be the number of successes, "n" should be the total number of subjects (the "sample_var" column is irrelevant in binary cases and is ignored).
the number of points to calculate the smooth dose response interpolation. Must be sufficiently high to accurately depict the dose response curve.
the size of sample for which to plot posterior predictive intervals for the mean.
the width of the error bars.
the dose at which to adjust the posterior plot. Specifying a dose returns the plot of pr(trt_dose - trt_{reference_dose} | data).
model definitions created using the model creation functions in model. If arguments are named, the names are retained in the return values.
Returns the ggplot object.
set.seed(888)
data <- dreamer_data_linear(
n_cohorts = c(20, 20, 20),
dose = c(0, 3, 10),
b1 = 1,
b2 = 3,
sigma = 5
)
# Bayesian model averaging
output <- dreamer_mcmc(
data = data,
n_adapt = 1e3,
n_burn = 1e3,
n_iter = 1e4,
n_chains = 2,
silent = FALSE,
mod_linear = model_linear(
mu_b1 = 0,
sigma_b1 = 1,
mu_b2 = 0,
sigma_b2 = 1,
shape = 1,
rate = .001,
w_prior = 1 / 2
),
mod_quad = model_quad(
mu_b1 = 0,
sigma_b1 = 1,
mu_b2 = 0,
sigma_b2 = 1,
mu_b3 = 0,
sigma_b3 = 1,
shape = 1,
rate = .001,
w_prior = 1 / 2
)
)
#> mod_linear
#> start : 2024-12-19 14:43:24.569
#> Compiling model graph
#> Resolving undeclared variables
#> Allocating nodes
#> Graph information:
#> Observed stochastic nodes: 6
#> Unobserved stochastic nodes: 3
#> Total graph size: 50
#>
#> Initializing model
#>
#> finish: 2024-12-19 14:43:24.634
#> total : 0.07 secs
#> mod_quad
#> start : 2024-12-19 14:43:24.635
#> Compiling model graph
#> Resolving undeclared variables
#> Allocating nodes
#> Graph information:
#> Observed stochastic nodes: 6
#> Unobserved stochastic nodes: 4
#> Total graph size: 59
#>
#> Initializing model
#>
#> finish: 2024-12-19 14:43:24.708
#> total : 0.07 secs
plot(output)
if (FALSE) { # \dontrun{
# with data
plot(output, data = data)
# predictive distribution
plot(output, data = data, predictive = 1)
# single model
plot(output$mod_linear)
} # }