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
)
output from a call to dreamer_mcmc()
, or
the MCMC samples from a single model of output from
a dreamer_mcmc()
call.
the dose at which to calculate the posterior percentage effect.
a vector of quantiles to calculate on the posterior.
the slice of time for which to calculate the posterior percentage effect. Applies to longitudinal models only.
the lower bound of the dose range under consideration.
the upper bound of the dose range under consideration.
logical indicating if the response is desired to
be increasing (TRUE
) or decreasing (FALSE
).
the lower (if greater = TRUE
) or upper
(if greater = FALSE
) bound that the effect is expected to
take.
an index on which MCMC samples should be used. Generally
the user should not specify anything for this argument as dreamer
will handle this automatically.
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
)
)
#> mod_linear
#> start : 2024-12-19 14:43:30.209
#> 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:30.228
#> total : 0.02 secs
#> mod_quad
#> start : 2024-12-19 14:43:30.229
#> 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:30.248
#> total : 0.02 secs
post_perc_effect(output, dose = c(3, 5))
#> $stats
#> # A tibble: 2 × 5
#> dose pr_perc_exists mean `2.50%` `97.50%`
#> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 3 1 0.311 0.256 0.353
#> 2 5 1 0.506 0.443 0.555
#>
# from a single model
post_perc_effect(output$mod_linear, dose = c(3, 5))
#> $stats
#> # A tibble: 2 × 5
#> dose pr_perc_exists mean `2.50%` `97.50%`
#> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 3 1 0.313 0.283 0.345
#> 2 5 1 0.509 0.488 0.532
#>