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 dreamer_mcmc(), or the MCMC samples from a single model of output from a dreamer_mcmc() call.

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 (TRUE) or decreasing (FALSE).

small_bound

the lower (if greater = TRUE) or upper (if greater = FALSE) bound that the effect is expected to take.

index

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.

return_samples

logical indicating if the posterior samples should be returned.

Value

A named list with the following components:

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))

[Package dreamer version 3.1.0 Index]