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

Arguments

x

output from a call to dreamer_mcmc.

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.

Value

Returns the ggplot object.

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 = 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)
} # }