Calculate MCMC diagnostics for individual parameters.

diagnostics(x)

Arguments

x

MCMC output from a dreamer model.

Value

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.

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-04-01 17:24:34.471
#> 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-04-01 17:24:34.543
#> total : 0.07 secs
#> mod_quad
#> start : 2024-04-01 17:24:34.544
#> 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-04-01 17:24:34.617
#> total : 0.07 secs

# for all models
diagnostics(output)
#> # A tibble: 7 × 5
#>   model      param gelman_point gelman_upper effective_size
#>   <chr>      <chr>        <dbl>        <dbl>          <dbl>
#> 1 mod_linear b1            1.00         1.00         20695.
#> 2 mod_linear b2            1.00         1.00         20000.
#> 3 mod_linear sigma         1.00         1.00         19553.
#> 4 mod_quad   b1            1.00         1.00         20211.
#> 5 mod_quad   b2            1.00         1.00         17217.
#> 6 mod_quad   b3            1.00         1.00         17119.
#> 7 mod_quad   sigma         1.00         1.00         16379.

# for a single model
diagnostics(output$mod_quad)
#> # A tibble: 4 × 4
#>   param gelman_point gelman_upper effective_size
#>   <chr>        <dbl>        <dbl>          <dbl>
#> 1 b1            1.00         1.00         20211.
#> 2 b2            1.00         1.00         17217.
#> 3 b3            1.00         1.00         17119.
#> 4 sigma         1.00         1.00         16379.