post_perc_effect {dreamer} | R Documentation |
Calculate Posterior of a Dose's Percentage Effect
Description
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.
Usage
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
)
Arguments
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. |
Value
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.
Examples
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))