Title: | Dose Response Models for Bayesian Model Averaging |
---|---|
Description: | Fits (longitudinal) dose-response models utilizing a Bayesian model averaging approach as outlined in Gould (2019) <doi:10.1002/bimj.201700211> for both continuous and binary responses. Functions for plotting and calculating various posterior quantities (e.g. posterior mean, quantiles, probability of minimum efficacious dose, etc.) are also implemented. Copyright Eli Lilly and Company (2019). |
Authors: | Richard Daniel Payne [aut, cre], William Michael Landau [rev], Mitch Thomann [rev], Eli Lilly and Company [cph] |
Maintainer: | Richard Daniel Payne <[email protected]> |
License: | MIT + file LICENSE |
Version: | 3.1.0 |
Built: | 2024-11-21 06:51:54 UTC |
Source: | CRAN |
Calculate MCMC diagnostics for individual parameters.
diagnostics(x)
diagnostics(x)
x |
MCMC output from a dreamer model. |
A tibble listing the Gelman point estimates and upper bounds (obtained from coda::gelman.diag) and effective sample size (obtained from coda::effectiveSize) for each parameter within each model.
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 ) ) # for all models diagnostics(output) # for a single model diagnostics(output$mod_quad)
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 ) ) # for all models diagnostics(output) # for a single model diagnostics(output$mod_quad)
See the model definitions below for specifics for each model.
dreamer_data_linear( n_cohorts, doses, b1, b2, sigma, times, t_max, longitudinal = NULL, ... ) dreamer_data_linear_binary( n_cohorts, doses, b1, b2, link, times, t_max, longitudinal = NULL, ... ) dreamer_data_quad( n_cohorts, doses, b1, b2, b3, sigma, times, t_max, longitudinal = NULL, ... ) dreamer_data_quad_binary( n_cohorts, doses, b1, b2, b3, link, times, t_max, longitudinal = NULL, ... ) dreamer_data_loglinear( n_cohorts, doses, b1, b2, sigma, times, t_max, longitudinal = NULL, ... ) dreamer_data_loglinear_binary( n_cohorts, doses, b1, b2, link, times, t_max, longitudinal = NULL, ... ) dreamer_data_logquad( n_cohorts, doses, b1, b2, b3, sigma, times, t_max, longitudinal = NULL, ... ) dreamer_data_logquad_binary( n_cohorts, doses, b1, b2, b3, link, times, t_max, longitudinal = NULL, ... ) dreamer_data_emax( n_cohorts, doses, b1, b2, b3, b4, sigma, times, t_max, longitudinal = NULL, ... ) dreamer_data_emax_binary( n_cohorts, doses, b1, b2, b3, b4, link, times, t_max, longitudinal = NULL, ... ) dreamer_data_exp( n_cohorts, doses, b1, b2, b3, sigma, times, t_max, longitudinal = NULL, ... ) dreamer_data_exp_binary( n_cohorts, doses, b1, b2, b3, link, times, t_max, longitudinal = NULL, ... ) dreamer_data_beta( n_cohorts, doses, b1, b2, b3, b4, scale, sigma, times, t_max, longitudinal = NULL, ... ) dreamer_data_beta_binary( n_cohorts, doses, b1, b2, b3, b4, scale, link, times, t_max, longitudinal = NULL, ... ) dreamer_data_independent( n_cohorts, doses, b1, sigma, times, t_max, longitudinal = NULL, ... ) dreamer_data_independent_binary( n_cohorts, doses, b1, link, times, t_max, longitudinal = NULL, ... )
dreamer_data_linear( n_cohorts, doses, b1, b2, sigma, times, t_max, longitudinal = NULL, ... ) dreamer_data_linear_binary( n_cohorts, doses, b1, b2, link, times, t_max, longitudinal = NULL, ... ) dreamer_data_quad( n_cohorts, doses, b1, b2, b3, sigma, times, t_max, longitudinal = NULL, ... ) dreamer_data_quad_binary( n_cohorts, doses, b1, b2, b3, link, times, t_max, longitudinal = NULL, ... ) dreamer_data_loglinear( n_cohorts, doses, b1, b2, sigma, times, t_max, longitudinal = NULL, ... ) dreamer_data_loglinear_binary( n_cohorts, doses, b1, b2, link, times, t_max, longitudinal = NULL, ... ) dreamer_data_logquad( n_cohorts, doses, b1, b2, b3, sigma, times, t_max, longitudinal = NULL, ... ) dreamer_data_logquad_binary( n_cohorts, doses, b1, b2, b3, link, times, t_max, longitudinal = NULL, ... ) dreamer_data_emax( n_cohorts, doses, b1, b2, b3, b4, sigma, times, t_max, longitudinal = NULL, ... ) dreamer_data_emax_binary( n_cohorts, doses, b1, b2, b3, b4, link, times, t_max, longitudinal = NULL, ... ) dreamer_data_exp( n_cohorts, doses, b1, b2, b3, sigma, times, t_max, longitudinal = NULL, ... ) dreamer_data_exp_binary( n_cohorts, doses, b1, b2, b3, link, times, t_max, longitudinal = NULL, ... ) dreamer_data_beta( n_cohorts, doses, b1, b2, b3, b4, scale, sigma, times, t_max, longitudinal = NULL, ... ) dreamer_data_beta_binary( n_cohorts, doses, b1, b2, b3, b4, scale, link, times, t_max, longitudinal = NULL, ... ) dreamer_data_independent( n_cohorts, doses, b1, sigma, times, t_max, longitudinal = NULL, ... ) dreamer_data_independent_binary( n_cohorts, doses, b1, link, times, t_max, longitudinal = NULL, ... )
n_cohorts |
a vector listing the size of each cohort. |
doses |
a vector listing the dose for each cohort. |
b1 , b2 , b3 , b4
|
parameters in the models. See sections below for each parameter's interpretation in a given model. |
sigma |
standard deviation. |
times |
the times at which data should be simulated if a longitudinal model is specified. |
t_max |
the t_max parameter used in the longitudinal model. |
longitudinal |
a string indicating the longitudinal model to be used. Can be "linear", "itp", or "idp". |
... |
additional longitudinal parameters. |
link |
character vector indicating the link function for binary models. |
scale |
a scaling parameter (fixed, specified by the user) for the beta models. |
A dataframe of random subjects from the specified model and parameters.
dreamer_data_linear()
: generate data from linear dose response.
dreamer_data_linear_binary()
: generate data from linear binary dose response.
dreamer_data_quad()
: generate data from quadratic dose response.
dreamer_data_quad_binary()
: generate data from quadratic binary dose response.
dreamer_data_loglinear()
: generate data from log-linear dose response.
dreamer_data_loglinear_binary()
: generate data from binary log-linear dose response.
dreamer_data_logquad()
: generate data from log-quadratic dose response.
dreamer_data_logquad_binary()
: generate data from log-quadratic binary dose
response.
dreamer_data_emax()
: generate data from EMAX dose response.
dreamer_data_emax_binary()
: generate data from EMAX binary dose response.
dreamer_data_exp()
: generate data from exponential dose response.
dreamer_data_exp_binary()
: generate data from exponential binary dose response.
dreamer_data_beta()
: generate data from Beta dose response.
dreamer_data_beta_binary()
: generate data from binary Beta dose response.
dreamer_data_independent()
: generate data from an independent dose response.
dreamer_data_independent_binary()
: generate data from an independent dose response.
Here, is the placebo effect (dose = 0),
is the
maximum treatment effect,
is the
, and
is the hill or rate parameter.
Here, on the scale,
is the placebo effect (dose = 0),
is the
maximum treatment effect,
is the
, and
is the hill or rate parameter.
Let be a dose response model. The expected value of the
response, y, is:
Let be a dose response model. The expected value of the
response, y, is:
Increasing-Decreasing-Plateau (IDP).
Let be a dose response model. The expected value of the
response, y, is:
set.seed(888) data <- dreamer_data_linear( n_cohorts = c(20, 20, 20), dose = c(0, 3, 10), b1 = 1, b2 = 3, sigma = 5 ) head(data) plot(data$dose, data$response) abline(a = 1, b = 3) # longitudinal data set.seed(889) data_long <- dreamer_data_linear( n_cohorts = c(10, 10, 10, 10), # number of subjects in each cohort doses = c(.25, .5, .75, 1.5), # dose administered to each cohort b1 = 0, # intercept b2 = 2, # slope sigma = .5, # standard deviation, longitudinal = "itp", times = c(0, 12, 24, 52), t_max = 52, # maximum time a = .5, c1 = .1 ) ## Not run: ggplot(data_long, aes(time, response, group = dose, color = factor(dose))) + geom_point() ## End(Not run)
set.seed(888) data <- dreamer_data_linear( n_cohorts = c(20, 20, 20), dose = c(0, 3, 10), b1 = 1, b2 = 3, sigma = 5 ) head(data) plot(data$dose, data$response) abline(a = 1, b = 3) # longitudinal data set.seed(889) data_long <- dreamer_data_linear( n_cohorts = c(10, 10, 10, 10), # number of subjects in each cohort doses = c(.25, .5, .75, 1.5), # dose administered to each cohort b1 = 0, # intercept b2 = 2, # slope sigma = .5, # standard deviation, longitudinal = "itp", times = c(0, 12, 24, 52), t_max = 52, # maximum time a = .5, c1 = .1 ) ## Not run: ggplot(data_long, aes(time, response, group = dose, color = factor(dose))) + geom_point() ## End(Not run)
This function performs Bayesian model averaging with a selection of dose response models. See model for all possible models.
dreamer_mcmc( data, ..., n_adapt = 1000, n_burn = 1000, n_iter = 10000, n_chains = 4, silent = FALSE, convergence_warn = TRUE )
dreamer_mcmc( data, ..., n_adapt = 1000, n_burn = 1000, n_iter = 10000, n_chains = 4, silent = FALSE, convergence_warn = TRUE )
data |
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). |
... |
model definitions created using the model creation functions in model. If arguments are named, the names are retained in the return values. |
n_adapt |
the number of MCMC iterations to tune the MCMC algorithm. |
n_burn |
the number of burn-in MCMC samples. |
n_iter |
the number of MCMC samples to collect after tuning and burn-in. |
n_chains |
the number of separate, independent, MCMC chains to run. |
silent |
logical indicating if MCMC progress bars should be suppressed. |
convergence_warn |
logical (default |
The Bayesian model averaging approach uses data, multiple models, priors on each model's parameters, and a prior weight for each model. Using these inputs, each model is fit independently, and the output from the models is used to calculate posterior weights for each model. See Gould (2018) for details.
A named list with S3 class "dreamer_bma" and "dreamer". The list contains the following fields:
doses: a vector of the unique ordered doses in the data.
times: a vector of the unique ordered times in the data.
w_prior: a named vector with the prior probabilities of each model.
w_post: a named vector with the posterior probabilities of each model.
The individual MCMC fits for each model.
Gould, A. L. (2019). BMA-Mod: A Bayesian model averaging strategy for determining dose-response relationships in the presence of model uncertainty. Biometrical Journal, 61(5), 1141-1159.
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 = 1e2, n_iter = 1e3, n_chains = 2, silent = TRUE, 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 ) ) # posterior weights output$w_post # plot posterior dose response plot(output) # LONGITUDINAL library(ggplot2) set.seed(889) data_long <- dreamer_data_linear( n_cohorts = c(10, 10, 10, 10), # number of subjects in each cohort doses = c(.25, .5, .75, 1.5), # dose administered to each cohort b1 = 0, # intercept b2 = 2, # slope sigma = .5, # standard deviation, longitudinal = "itp", times = c(0, 12, 24, 52), t_max = 52, # maximum time a = .5, c1 = .1 ) ## Not run: ggplot(data_long, aes(time, response, group = dose, color = factor(dose))) + geom_point() ## End(Not run) output_long <- dreamer_mcmc( data = data_long, n_adapt = 1e3, n_burn = 1e2, n_iter = 1e3, n_chains = 2, silent = TRUE, # make rjags be quiet, mod_linear = model_linear( mu_b1 = 0, sigma_b1 = 1, mu_b2 = 0, sigma_b2 = 1, shape = 1, rate = .001, w_prior = 1 / 2, # prior probability of the model longitudinal = model_longitudinal_itp( mu_a = 0, sigma_a = 1, a_c1 = 0, b_c1 = 1, t_max = 52 ) ), 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, longitudinal = model_longitudinal_linear( mu_a = 0, sigma_a = 1, t_max = 52 ) ) ) ## Not run: # plot longitudinal dose-response profile plot(output_long, data = data_long) plot(output_long$mod_quad, data = data_long) # single model # plot dose response at final timepoint plot(output_long, data = data_long, times = 52) plot(output_long$mod_quad, data = data_long, times = 52) # single model ## End(Not run)
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 = 1e2, n_iter = 1e3, n_chains = 2, silent = TRUE, 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 ) ) # posterior weights output$w_post # plot posterior dose response plot(output) # LONGITUDINAL library(ggplot2) set.seed(889) data_long <- dreamer_data_linear( n_cohorts = c(10, 10, 10, 10), # number of subjects in each cohort doses = c(.25, .5, .75, 1.5), # dose administered to each cohort b1 = 0, # intercept b2 = 2, # slope sigma = .5, # standard deviation, longitudinal = "itp", times = c(0, 12, 24, 52), t_max = 52, # maximum time a = .5, c1 = .1 ) ## Not run: ggplot(data_long, aes(time, response, group = dose, color = factor(dose))) + geom_point() ## End(Not run) output_long <- dreamer_mcmc( data = data_long, n_adapt = 1e3, n_burn = 1e2, n_iter = 1e3, n_chains = 2, silent = TRUE, # make rjags be quiet, mod_linear = model_linear( mu_b1 = 0, sigma_b1 = 1, mu_b2 = 0, sigma_b2 = 1, shape = 1, rate = .001, w_prior = 1 / 2, # prior probability of the model longitudinal = model_longitudinal_itp( mu_a = 0, sigma_a = 1, a_c1 = 0, b_c1 = 1, t_max = 52 ) ), 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, longitudinal = model_longitudinal_linear( mu_a = 0, sigma_a = 1, t_max = 52 ) ) ) ## Not run: # plot longitudinal dose-response profile plot(output_long, data = data_long) plot(output_long$mod_quad, data = data_long) # single model # plot dose response at final timepoint plot(output_long, data = data_long, times = 52) plot(output_long$mod_quad, data = data_long, times = 52) # single model ## End(Not run)
Plot the prior over the dose range. This is intended to help the user choose appropriate priors.
dreamer_plot_prior( n_samples = 10000, probs = c(0.025, 0.975), doses, n_chains = 1, ..., times = NULL, plot_draws = FALSE, alpha = 0.2 )
dreamer_plot_prior( n_samples = 10000, probs = c(0.025, 0.975), doses, n_chains = 1, ..., times = NULL, plot_draws = FALSE, alpha = 0.2 )
n_samples |
the number of MCMC samples per MCMC chain used to generate the plot. |
probs |
A vector of length 2 indicating the lower and upper percentiles
to plot. Not applicable when |
doses |
a vector of doses at which to evaluate and interpolate between. |
n_chains |
the number of MCMC chains. |
... |
model objects. See |
times |
a vector of times at which to plot the prior. |
plot_draws |
if |
alpha |
the transparency setting for the prior draws in (0, 1].
Only applies if |
The ggplot object.
# Plot prior for one model set.seed(8111) dreamer_plot_prior( doses = c(0, 2.5, 5), mod_quad_binary = model_quad_binary( mu_b1 = -.5, sigma_b1 = .2, mu_b2 = -.5, sigma_b2 = .2, mu_b3 = .5, sigma_b3 = .1, link = "logit", w_prior = 1 ) ) # plot individual draws dreamer_plot_prior( doses = seq(from = 0, to = 5, length.out = 50), n_samples = 100, plot_draws = TRUE, mod_quad_binary = model_quad_binary( mu_b1 = -.5, sigma_b1 = .2, mu_b2 = -.5, sigma_b2 = .2, mu_b3 = .5, sigma_b3 = .1, link = "logit", w_prior = 1 ) ) # plot prior from mixture of models dreamer_plot_prior( doses = c(0, 2.5, 5), mod_linear_binary = model_linear_binary( mu_b1 = -1, sigma_b1 = .1, mu_b2 = 1, sigma_b2 = .1, link = "logit", w_prior = .75 ), mod_quad_binary = model_quad_binary( mu_b1 = -.5, sigma_b1 = .2, mu_b2 = -.5, sigma_b2 = .2, mu_b3 = .5, sigma_b3 = .1, link = "logit", w_prior = .25 ) )
# Plot prior for one model set.seed(8111) dreamer_plot_prior( doses = c(0, 2.5, 5), mod_quad_binary = model_quad_binary( mu_b1 = -.5, sigma_b1 = .2, mu_b2 = -.5, sigma_b2 = .2, mu_b3 = .5, sigma_b3 = .1, link = "logit", w_prior = 1 ) ) # plot individual draws dreamer_plot_prior( doses = seq(from = 0, to = 5, length.out = 50), n_samples = 100, plot_draws = TRUE, mod_quad_binary = model_quad_binary( mu_b1 = -.5, sigma_b1 = .2, mu_b2 = -.5, sigma_b2 = .2, mu_b3 = .5, sigma_b3 = .1, link = "logit", w_prior = 1 ) ) # plot prior from mixture of models dreamer_plot_prior( doses = c(0, 2.5, 5), mod_linear_binary = model_linear_binary( mu_b1 = -1, sigma_b1 = .1, mu_b2 = 1, sigma_b2 = .1, link = "logit", w_prior = .75 ), mod_quad_binary = model_quad_binary( mu_b1 = -.5, sigma_b1 = .2, mu_b2 = -.5, sigma_b2 = .2, mu_b3 = .5, sigma_b3 = .1, link = "logit", w_prior = .25 ) )
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.
## S3 method for class 'dreamer_mcmc' plot( x, doses = attr(x, "doses"), times = attr(x, "times"), probs = c(0.025, 0.975), data = NULL, n_smooth = 50, predictive = 0, width = bar_width(doses), reference_dose = NULL, ... )
## S3 method for class 'dreamer_mcmc' plot( x, doses = attr(x, "doses"), times = attr(x, "times"), probs = c(0.025, 0.975), data = NULL, n_smooth = 50, predictive = 0, width = bar_width(doses), reference_dose = NULL, ... )
x |
output from a call to |
doses |
a vector of doses at which to plot the dose response curve. |
times |
a vector of the times at which to plot the posterior (for longitudinal models only). |
probs |
quantiles of the posterior to be calculated. |
data |
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). |
n_smooth |
the number of points to calculate the smooth dose response interpolation. Must be sufficiently high to accurately depict the dose response curve. |
predictive |
the size of sample for which to plot posterior predictive intervals for the mean. |
width |
the width of the error bars. |
reference_dose |
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 ) ) plot(output) ## Not run: # with data plot(output, data = data) # predictive distribution plot(output, data = data, predictive = 1) # single model plot(output$mod_linear) ## End(Not run)
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 ) ) plot(output) ## Not run: # with data plot(output, data = data) # predictive distribution plot(output, data = data, predictive = 1) # single model plot(output$mod_linear) ## End(Not run)
Functions which set the hyperparameters, seeds, and prior
weight for each model to be used in Bayesian model averaging
via dreamer_mcmc()
.
See each function's section below for the model's details. In the
following, denotes the response variable and
represents
the dose.
For the longitudinal specifications, see documentation on
model_longitudinal
.
model_linear( mu_b1, sigma_b1, mu_b2, sigma_b2, shape, rate, w_prior = 1, longitudinal = NULL ) model_quad( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, shape, rate, w_prior = 1, longitudinal = NULL ) model_loglinear( mu_b1, sigma_b1, mu_b2, sigma_b2, shape, rate, w_prior = 1, longitudinal = NULL ) model_logquad( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, shape, rate, w_prior = 1, longitudinal = NULL ) model_emax( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, mu_b4, sigma_b4, shape, rate, w_prior = 1, longitudinal = NULL ) model_exp( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, shape, rate, w_prior = 1, longitudinal = NULL ) model_beta( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, mu_b4, sigma_b4, shape, rate, scale = NULL, w_prior = 1, longitudinal = NULL ) model_independent( mu_b1, sigma_b1, shape, rate, doses = NULL, w_prior = 1, longitudinal = NULL ) model_linear_binary( mu_b1, sigma_b1, mu_b2, sigma_b2, link, w_prior = 1, longitudinal = NULL ) model_quad_binary( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, link, w_prior = 1, longitudinal = NULL ) model_loglinear_binary( mu_b1, sigma_b1, mu_b2, sigma_b2, link, w_prior = 1, longitudinal = NULL ) model_logquad_binary( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, link, w_prior = 1, longitudinal = NULL ) model_emax_binary( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, mu_b4, sigma_b4, link, w_prior = 1, longitudinal = NULL ) model_exp_binary( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, link, w_prior = 1, longitudinal = NULL ) model_beta_binary( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, mu_b4, sigma_b4, scale = NULL, link, w_prior = 1, longitudinal = NULL ) model_independent_binary( mu_b1, sigma_b1, doses = NULL, link, w_prior = 1, longitudinal = NULL )
model_linear( mu_b1, sigma_b1, mu_b2, sigma_b2, shape, rate, w_prior = 1, longitudinal = NULL ) model_quad( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, shape, rate, w_prior = 1, longitudinal = NULL ) model_loglinear( mu_b1, sigma_b1, mu_b2, sigma_b2, shape, rate, w_prior = 1, longitudinal = NULL ) model_logquad( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, shape, rate, w_prior = 1, longitudinal = NULL ) model_emax( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, mu_b4, sigma_b4, shape, rate, w_prior = 1, longitudinal = NULL ) model_exp( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, shape, rate, w_prior = 1, longitudinal = NULL ) model_beta( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, mu_b4, sigma_b4, shape, rate, scale = NULL, w_prior = 1, longitudinal = NULL ) model_independent( mu_b1, sigma_b1, shape, rate, doses = NULL, w_prior = 1, longitudinal = NULL ) model_linear_binary( mu_b1, sigma_b1, mu_b2, sigma_b2, link, w_prior = 1, longitudinal = NULL ) model_quad_binary( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, link, w_prior = 1, longitudinal = NULL ) model_loglinear_binary( mu_b1, sigma_b1, mu_b2, sigma_b2, link, w_prior = 1, longitudinal = NULL ) model_logquad_binary( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, link, w_prior = 1, longitudinal = NULL ) model_emax_binary( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, mu_b4, sigma_b4, link, w_prior = 1, longitudinal = NULL ) model_exp_binary( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, link, w_prior = 1, longitudinal = NULL ) model_beta_binary( mu_b1, sigma_b1, mu_b2, sigma_b2, mu_b3, sigma_b3, mu_b4, sigma_b4, scale = NULL, link, w_prior = 1, longitudinal = NULL ) model_independent_binary( mu_b1, sigma_b1, doses = NULL, link, w_prior = 1, longitudinal = NULL )
mu_b1 , sigma_b1 , mu_b2 , sigma_b2 , mu_b3 , sigma_b3 , mu_b4 , sigma_b4 , shape , rate
|
models parameters. See sections below for interpretation in specific models. |
w_prior |
a scalar between 0 and 1 indicating the prior weight of the model. |
longitudinal |
output from a call to one of the model_longitudinal_*() functions. This is used to specify a longitudinal dose-response model. |
scale |
a scale parameter in the Beta model. Default is 1.2 * max(dose). |
doses |
the doses in the dataset to be modeled. The order of the
doses corresponds to the order in which the priors are specified in
|
link |
a character string of either "logit" or "probit" indicating the link function for binary model. |
A named list of the arguments in the function call. The list has
S3 classes assigned which are used internally within dreamer_mcmc()
.
Here, is the placebo effect (dose = 0),
is the
maximum treatment effect,
is the
, and
is the hill or rate parameter.
Note that is a hyperparameter specified by the
user.
The independent model models the effect of each dose independently.
Vectors can be supplied to mu_b1
and sigma_b1
to set a different
prior for each dose in the order the doses are supplied to doses
.
If scalars are supplied to mu_b1
and sigma_b1
, then the same prior
is used for each dose, and the doses
argument is not needed.
Here, on the scale,
is the placebo effect (dose = 0),
is the
maximum treatment effect,
is the
, and
is the hill or rate parameter.
Note that is a hyperparameter specified by the
user.
The independent model models the effect of each dose independently.
Vectors can be supplied to mu_b1
and sigma_b1
to set a different
prior for each dose in the order the doses are supplied to doses
.
If scalars are supplied to mu_b1
and sigma_b1
, then the same prior
is used for each dose, and the doses
argument is not needed.
Let be a dose response model. The expected value of the
response, y, is:
Let be a dose response model. The expected value of the
response, y, is:
Increasing-Decreasing-Plateau (IDP).
Let be a dose response model. The expected value of the
response, y, is:
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 = 1e2, n_iter = 1e3, n_chains = 2, silent = TRUE, 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 ) ) # posterior weights output$w_post # plot posterior dose response plot(output) # LONGITUDINAL library(ggplot2) set.seed(889) data_long <- dreamer_data_linear( n_cohorts = c(10, 10, 10, 10), # number of subjects in each cohort doses = c(.25, .5, .75, 1.5), # dose administered to each cohort b1 = 0, # intercept b2 = 2, # slope sigma = .5, # standard deviation, longitudinal = "itp", times = c(0, 12, 24, 52), t_max = 52, # maximum time a = .5, c1 = .1 ) ## Not run: ggplot(data_long, aes(time, response, group = dose, color = factor(dose))) + geom_point() ## End(Not run) output_long <- dreamer_mcmc( data = data_long, n_adapt = 1e3, n_burn = 1e2, n_iter = 1e3, n_chains = 2, silent = TRUE, # make rjags be quiet, mod_linear = model_linear( mu_b1 = 0, sigma_b1 = 1, mu_b2 = 0, sigma_b2 = 1, shape = 1, rate = .001, w_prior = 1 / 2, # prior probability of the model longitudinal = model_longitudinal_itp( mu_a = 0, sigma_a = 1, a_c1 = 0, b_c1 = 1, t_max = 52 ) ), 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, longitudinal = model_longitudinal_linear( mu_a = 0, sigma_a = 1, t_max = 52 ) ) ) ## Not run: # plot longitudinal dose-response profile plot(output_long, data = data_long) plot(output_long$mod_quad, data = data_long) # single model # plot dose response at final timepoint plot(output_long, data = data_long, times = 52) plot(output_long$mod_quad, data = data_long, times = 52) # single model ## End(Not run)
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 = 1e2, n_iter = 1e3, n_chains = 2, silent = TRUE, 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 ) ) # posterior weights output$w_post # plot posterior dose response plot(output) # LONGITUDINAL library(ggplot2) set.seed(889) data_long <- dreamer_data_linear( n_cohorts = c(10, 10, 10, 10), # number of subjects in each cohort doses = c(.25, .5, .75, 1.5), # dose administered to each cohort b1 = 0, # intercept b2 = 2, # slope sigma = .5, # standard deviation, longitudinal = "itp", times = c(0, 12, 24, 52), t_max = 52, # maximum time a = .5, c1 = .1 ) ## Not run: ggplot(data_long, aes(time, response, group = dose, color = factor(dose))) + geom_point() ## End(Not run) output_long <- dreamer_mcmc( data = data_long, n_adapt = 1e3, n_burn = 1e2, n_iter = 1e3, n_chains = 2, silent = TRUE, # make rjags be quiet, mod_linear = model_linear( mu_b1 = 0, sigma_b1 = 1, mu_b2 = 0, sigma_b2 = 1, shape = 1, rate = .001, w_prior = 1 / 2, # prior probability of the model longitudinal = model_longitudinal_itp( mu_a = 0, sigma_a = 1, a_c1 = 0, b_c1 = 1, t_max = 52 ) ), 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, longitudinal = model_longitudinal_linear( mu_a = 0, sigma_a = 1, t_max = 52 ) ) ) ## Not run: # plot longitudinal dose-response profile plot(output_long, data = data_long) plot(output_long$mod_quad, data = data_long) # single model # plot dose response at final timepoint plot(output_long, data = data_long, times = 52) plot(output_long$mod_quad, data = data_long, times = 52) # single model ## End(Not run)
Assign hyperparameters and other values for longitudinal
modeling. The output of this function is intended to be used as
the input to the longitudinal
argument of the dose response model
functions, e.g., model_linear
.
model_longitudinal_linear(mu_a, sigma_a, t_max) model_longitudinal_itp(mu_a, sigma_a, a_c1 = 0, b_c1 = 1, t_max) model_longitudinal_idp( mu_a, sigma_a, a_c1 = 0, b_c1 = 1, a_c2 = -1, b_c2 = 0, t_max )
model_longitudinal_linear(mu_a, sigma_a, t_max) model_longitudinal_itp(mu_a, sigma_a, a_c1 = 0, b_c1 = 1, t_max) model_longitudinal_idp( mu_a, sigma_a, a_c1 = 0, b_c1 = 1, a_c2 = -1, b_c2 = 0, t_max )
mu_a , sigma_a , a_c1 , b_c1 , a_c2 , b_c2
|
hyperparameters of the specified longitudinal model. See below for parameterization. |
t_max |
a scalar, typically indicating the latest observed time for subjects. This will influence the interpretation of the parameters of each model. |
A named list of the arguments in the function call. The list has
S3 classes assigned which are used internally within dreamer_mcmc()
.
Let be a dose response model. The expected value of the
response, y, is:
Let be a dose response model. The expected value of the
response, y, is:
Increasing-Decreasing-Plateau (IDP).
Let be a dose response model. The expected value of the
response, y, is:
Compare Posterior Fits
plot_comparison(..., doses, times, probs, data, n_smooth, width) ## Default S3 method: plot_comparison( ..., doses = attr(list(...)[[1]], "doses"), times = NULL, probs = c(0.025, 0.975), data = NULL, n_smooth = 50, width = bar_width(doses) ) ## S3 method for class 'dreamer_bma' plot_comparison( ..., doses = x$doses, times = NULL, probs = c(0.025, 0.975), data = NULL, n_smooth = 50, width = bar_width(doses) )
plot_comparison(..., doses, times, probs, data, n_smooth, width) ## Default S3 method: plot_comparison( ..., doses = attr(list(...)[[1]], "doses"), times = NULL, probs = c(0.025, 0.975), data = NULL, n_smooth = 50, width = bar_width(doses) ) ## S3 method for class 'dreamer_bma' plot_comparison( ..., doses = x$doses, times = NULL, probs = c(0.025, 0.975), data = NULL, n_smooth = 50, width = bar_width(doses) )
... |
|
doses |
a vector of doses at which to plot the dose response curve. |
times |
the times at which to do the comparison. |
probs |
quantiles of the posterior to be calculated. |
data |
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). |
n_smooth |
the number of points to calculate the smooth dose response interpolation. Must be sufficiently high to accurately depict the dose response curve. |
width |
the width of the error bars. |
If a Bayesian model averaging object is supplied first, all individual fits and the Bayesian model averaging fit will be plotted, with the model averaging fit in black (other model colors specified in the legend). Otherwise, named arguments must be supplied for each model, and only the models provided will be plotted.
a 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 = 1e3, 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 ) ) plot_comparison(output) # compare individual models plot_comparison(linear = output$mod_linear, quad = output$mod_quad)
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 = 1e3, 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 ) ) plot_comparison(output) # compare individual models plot_comparison(linear = output$mod_linear, quad = output$mod_quad)
Produces traceplots for each parameter for each model.
plot_trace(x)
plot_trace(x)
x |
output from a call to |
No return value, called to create plots.
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 ) ) # all parameters from all models plot_trace(output) # from a single model plot_trace(output$mod_linear)
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 ) ) # all parameters from all models plot_trace(output) # from a single model plot_trace(output$mod_linear)
Posterior Distribution of Minimum X% Effective Dose
post_medx( x, ed, probs, time, lower, upper, greater, small_bound, return_samples, ... ) ## S3 method for class 'dreamer_bma' post_medx( x, ed, probs = c(0.025, 0.975), time = NULL, lower = min(x$doses), upper = max(x$doses), greater = TRUE, small_bound = 0, return_samples = FALSE, ... ) ## S3 method for class 'dreamer_mcmc' post_medx( x, ed, probs = c(0.025, 0.975), time = NULL, lower = min(attr(x, "doses")), upper = max(attr(x, "doses")), greater = TRUE, small_bound = 0, return_samples = FALSE, index = 1:(nrow(x[[1]]) * length(x)), ... )
post_medx( x, ed, probs, time, lower, upper, greater, small_bound, return_samples, ... ) ## S3 method for class 'dreamer_bma' post_medx( x, ed, probs = c(0.025, 0.975), time = NULL, lower = min(x$doses), upper = max(x$doses), greater = TRUE, small_bound = 0, return_samples = FALSE, ... ) ## S3 method for class 'dreamer_mcmc' post_medx( x, ed, probs = c(0.025, 0.975), time = NULL, lower = min(attr(x, "doses")), upper = max(attr(x, "doses")), greater = TRUE, small_bound = 0, return_samples = FALSE, index = 1:(nrow(x[[1]]) * length(x)), ... )
x |
output from |
ed |
a number between 0 and 100 indicating the ed% dose that is being sought. |
probs |
a vector of quantiles to calculate on the posterior. |
time |
the slice of time for which to calculate the posterior EDX dose. Applies to longitudinal models only. |
lower |
the lower bound of the doses for calculating EDX. |
upper |
the upper bound of the doses for calculating EDX. |
greater |
if |
small_bound |
the minimum ( |
return_samples |
logical indicating if the posterior samples should be returned. |
... |
additional arguments for specific methods. |
index |
a vector indicating which MCMC samples to use in the
calculation. If |
The minimum X% effective dose is the dose that has X% of the
largest effect for doses between lower
and upper
. When greater
is TRUE
, larger positive responses are considered more effective and
vice versa. The X% response is calculated as small_bound
+
ed
/ 100 * (max_effect - small_bound
) where "max_effect" is the
maximum response for doses between lower
and upper
. The X% effective
dose is the smallest dose which has X% response within the dose range.
It is possible that for some MCMC samples, an X% effective dose may
not exist, so probabilities are not guaranteed to sum to one.
Posterior quantities and samples (if applicable),
generally in the form of a list. The pr_edx_exists
column gives the
posterior probability that an EDX% effect exists.
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 = 1e3, 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 ) ) post_medx(output, ed = c(50, 90)) # from a single model post_medx(output$mod_linear, ed = c(50, 90))
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 = 1e3, 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 ) ) post_medx(output, ed = c(50, 90)) # from a single model post_medx(output$mod_linear, ed = c(50, 90))
Given a dose, the "percentage effect" is defined as (effect of the given dose - small_bound) / (maximum effect in dose range - small_bound). This function returns the posterior statistics and/or samples of this effect.
post_perc_effect( x, dose, probs, time, lower, upper, greater, small_bound, index, return_samples ) ## S3 method for class 'dreamer_bma' post_perc_effect( x, dose, probs = c(0.025, 0.975), time = NULL, lower = min(x$doses), upper = max(x$doses), greater = TRUE, small_bound = 0, index = NA, return_samples = FALSE ) ## S3 method for class 'dreamer_mcmc' post_perc_effect( x, dose, probs = c(0.025, 0.975), time = NULL, lower = min(attr(x, "doses")), upper = max(attr(x, "doses")), greater = TRUE, small_bound = 0, index = 1:(nrow(x[[1]]) * length(x)), return_samples = FALSE )
post_perc_effect( x, dose, probs, time, lower, upper, greater, small_bound, index, return_samples ) ## S3 method for class 'dreamer_bma' post_perc_effect( x, dose, probs = c(0.025, 0.975), time = NULL, lower = min(x$doses), upper = max(x$doses), greater = TRUE, small_bound = 0, index = NA, return_samples = FALSE ) ## S3 method for class 'dreamer_mcmc' post_perc_effect( x, dose, probs = c(0.025, 0.975), time = NULL, lower = min(attr(x, "doses")), upper = max(attr(x, "doses")), greater = TRUE, small_bound = 0, index = 1:(nrow(x[[1]]) * length(x)), return_samples = FALSE )
x |
output from a call to |
dose |
the dose at which to calculate the posterior percentage effect. |
probs |
a vector of quantiles to calculate on the posterior. |
time |
the slice of time for which to calculate the posterior percentage effect. Applies to longitudinal models only. |
lower |
the lower bound of the dose range under consideration. |
upper |
the upper bound of the dose range under consideration. |
greater |
logical indicating if the response is desired to
be increasing ( |
small_bound |
the lower (if |
index |
an index on which MCMC samples should be used. Generally
the user should not specify anything for this argument as |
return_samples |
logical indicating if the posterior samples should be returned. |
A named list with the following components:
stats: a tibble listing the dose, time (where relevant), probability a percentage effect exists, the average percentage effect, and the specified quantiles of the percentage effect.
samps: a tibble with the posterior samples for each dose/time combination.
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 = 1e3, 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 ) ) post_perc_effect(output, dose = c(3, 5)) # from a single model post_perc_effect(output$mod_linear, dose = c(3, 5))
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 = 1e3, 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 ) ) post_perc_effect(output, dose = c(3, 5)) # from a single model post_perc_effect(output$mod_linear, dose = c(3, 5))
Calculate posterior mean (and quantiles for specific doses for each MCMC iteration of the model.
posterior( x, doses, times, probs, reference_dose, predictive, return_samples, iter, return_stats ) ## S3 method for class 'dreamer_mcmc' posterior( x, doses = attr(x, "doses"), times = attr(x, "times"), probs = c(0.025, 0.975), reference_dose = NULL, predictive = 0, return_samples = FALSE, iter = NULL, return_stats = TRUE ) ## S3 method for class 'dreamer_mcmc_independent' posterior( x, doses = attr(x, "doses"), times = attr(x, "times"), probs = c(0.025, 0.975), reference_dose = NULL, predictive = 0, return_samples = FALSE, iter = NULL, return_stats = TRUE ) ## S3 method for class 'dreamer_bma' posterior( x, doses = x$doses, times = x$times, probs = c(0.025, 0.975), reference_dose = NULL, predictive = 0, return_samples = FALSE, iter = NULL, return_stats = TRUE )
posterior( x, doses, times, probs, reference_dose, predictive, return_samples, iter, return_stats ) ## S3 method for class 'dreamer_mcmc' posterior( x, doses = attr(x, "doses"), times = attr(x, "times"), probs = c(0.025, 0.975), reference_dose = NULL, predictive = 0, return_samples = FALSE, iter = NULL, return_stats = TRUE ) ## S3 method for class 'dreamer_mcmc_independent' posterior( x, doses = attr(x, "doses"), times = attr(x, "times"), probs = c(0.025, 0.975), reference_dose = NULL, predictive = 0, return_samples = FALSE, iter = NULL, return_stats = TRUE ) ## S3 method for class 'dreamer_bma' posterior( x, doses = x$doses, times = x$times, probs = c(0.025, 0.975), reference_dose = NULL, predictive = 0, return_samples = FALSE, iter = NULL, return_stats = TRUE )
x |
output from a call to |
doses |
doses at which to estimate posterior quantities. |
times |
a vector of times at which to calculate the posterior response (for longitudinal models only). |
probs |
quantiles of the posterior to be calculated. |
reference_dose |
the dose at which to adjust the posterior plot. Specifying a dose returns the plot of pr(trt_dose - trt_reference_dose | data). |
predictive |
An integer. If greater than 0, the return values will
be from the predictive distribution of the mean of |
return_samples |
logical indicating if the weighted raw MCMC samples from the Bayesian model averaging used to calculate the mean and quantiles should be returned. |
iter |
an index on which iterations of the MCMC should be used in the calculations. By default, all MCMC iterations are used. |
return_stats |
logical indicating whether or not the posterior statistics should be calculated. |
A named list with the following elements:
stats: a tibble the dose, posterior mean, and posterior quantiles.
samps: the weighted posterior samples. Only returned if
return_samples = TRUE
.
posterior(dreamer_mcmc)
: posterior summary for linear model.
posterior(dreamer_mcmc_independent)
: posterior summary for independent model.
posterior(dreamer_bma)
: posterior summary for Bayesian model averaging fit.
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 ) ) posterior(output) # return posterior samples of the mean post <- posterior(output, return_samples = TRUE) head(post$samps) # from a single model posterior(output$mod_quad) # posterior of difference of doses posterior(output, reference_dose = 0)
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 ) ) posterior(output) # return posterior samples of the mean post <- posterior(output, return_samples = TRUE) head(post$samps) # from a single model posterior(output$mod_quad) # posterior of difference of doses posterior(output, reference_dose = 0)
Calculate Pr(effect_dose - effect_reference_dose > EOI | data) or Pr(effect_dose > EOI | data).
pr_eoi(x, eoi, dose, reference_dose = NULL, time = NULL)
pr_eoi(x, eoi, dose, reference_dose = NULL, time = NULL)
x |
output from a call to |
eoi |
a vector of the effects of interest (EOI) in the probability function. |
dose |
a vector of the doses for which to calculate the posterior probabilities. |
reference_dose |
a vector of doses for relative effects of interest. |
time |
the time at which to calculate the posterior quantity. Defaults to the latest timepoint. Applies to longitudinal models only. |
A tibble listing the doses, times, and
Pr(effect_dose - effect_reference_dose > eoi) if reference_dose
is specified; otherwise, Pr(effect_dose > eoi).
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 ) ) pr_eoi(output, dose = 3, eoi = 10) # difference of two doses pr_eoi(output, dose = 3, eoi = 10, reference_dose = 0) # single model pr_eoi(output$mod_linear, dose = 3, eoi = 10)
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 ) ) pr_eoi(output, dose = 3, eoi = 10) # difference of two doses pr_eoi(output, dose = 3, eoi = 10, reference_dose = 0) # single model pr_eoi(output$mod_linear, dose = 3, eoi = 10)
Calculates the posterior probability that each specified doses are the minimum effective dose in the set; i.e. the smallest dose that has a clinically significant difference (CSD).
pr_med( x, doses = attr(x, "doses"), csd = NULL, reference_dose = NULL, greater = TRUE, time = NULL )
pr_med( x, doses = attr(x, "doses"), csd = NULL, reference_dose = NULL, greater = TRUE, time = NULL )
x |
output from a call to |
doses |
the doses for which pr(MED) is to be calculated. |
csd |
the treatment effect that is clinically relevant. |
reference_dose |
a single dose that is used as the reference when
defining the MED relative to a dose (rather than in absolute terms). When
|
greater |
if |
time |
the time (scalar) at which the Pr(MED) should be calculated. Applies only to longitudinal models. |
A tibble listing each dose and the posterior probability that each dose is the minimum efficacious dose.
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 = 1e3, 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 ) ) pr_med(output, csd = 10) # difference of two doses pr_med(output, csd = 3, reference_dose = 0) # single model pr_med(output$mod_quad, csd = 10)
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 = 1e3, 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 ) ) pr_med(output, csd = 10) # difference of two doses pr_med(output, csd = 3, reference_dose = 0) # single model pr_med(output$mod_quad, csd = 10)
Calculate the probability a dose being the smallest dose that has at least X% of the maximum efficacy.
pr_medx( x, doses = attr(x, "doses"), ed, greater = TRUE, small_bound = 0, time = NULL )
pr_medx( x, doses = attr(x, "doses"), ed, greater = TRUE, small_bound = 0, time = NULL )
x |
output from a call to |
doses |
the doses for which pr(minimum effective X% dose) is to be calculated. |
ed |
a number between 0 and 100 indicating the ed% dose that is being sought. |
greater |
if |
small_bound |
the lower (upper) bound of the response variable
when |
time |
the time (scalar) at which the Pr(MEDX) should be calculated. |
Obtaining the probability of a particular does being the
minimum efficacious dose achieving ed
% efficacy is dependent on
the doses specified.
For a given MCMC sample of parameters, the 100% efficacy value is defined
as the highest efficacy of the doses specified. For each posterior draw
of MCMC parameters, the minimum ed
% efficacious dose is defined as the
lowest dose what has at least ed
% efficacy relative to the 100%
efficacy value.
The ed
% effect is calculated as
ed / 100 * (effect_100 - small_bound) + small_bound
where effect_100
is the largest mean response among doses
for a given MCMC iteration.
A data frame with the following columns:
dose
: numeric dose levels.
prob
: Prob(EDX | data) for each dose. Note: these probabilities do
not necessarily sum to 1 because the EDX may not exist. In fact,
Pr(EDX does not exist | data) = 1 - sum(prob)
.
set.seed(888) data <- dreamer_data_linear( n_cohorts = c(20, 20, 20), dose = c(0, 3, 10), b1 = 1, b2 = .1, sigma = 5 ) # Bayesian model averaging output <- dreamer_mcmc( data = data, n_adapt = 1e3, n_burn = 1e3, n_iter = 1e3, 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 ) ) pr_medx(output, ed = 80) # single model pr_medx(output$mod_linear, ed = 80)
set.seed(888) data <- dreamer_data_linear( n_cohorts = c(20, 20, 20), dose = c(0, 3, 10), b1 = 1, b2 = .1, sigma = 5 ) # Bayesian model averaging output <- dreamer_mcmc( data = data, n_adapt = 1e3, n_burn = 1e3, n_iter = 1e3, 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 ) ) pr_medx(output, ed = 80) # single model pr_medx(output$mod_linear, ed = 80)
Summarize parameter inference and convergence diagnostics.
## S3 method for class 'dreamer_bma' summary(object, ...)
## S3 method for class 'dreamer_bma' summary(object, ...)
object |
a dreamer MCMC object. |
... |
additional arguments (which are ignored). |
Returns a named list with elements model_weights
and summary
containing the prior and posterior weights for each model and inference
on parameters for each model as well as MCMC diagnostics.
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 ) ) # all models (also show model weights) summary(output) # single model summary(output$mod_linear)
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 ) ) # all models (also show model weights) summary(output) # single model summary(output$mod_linear)
Produces summaries for inference and diagnosing MCMC chains.
## S3 method for class 'dreamer_mcmc' summary(object, ...)
## S3 method for class 'dreamer_mcmc' summary(object, ...)
object |
MCMC output from a dreamer model. |
... |
additional arguments which are ignored. |
A tibble with inference and diagnostics information for each parameter.
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 ) ) # all models (also show model weights) summary(output) # single model summary(output$mod_linear)
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 ) ) # all models (also show model weights) summary(output) # single model summary(output$mod_linear)