Skip to contents

Rename Covariates in draws Object

Usage

rename_draws_covariates(draws, analysis)

Arguments

draws

draws created from sampled analysis object. See example.

analysis

Analysis as created by create_analysis_obj().

Value

A draws[posterior::draws] object with covariate names.

Examples

analysis_object <- create_analysis_obj(
  data_matrix = example_matrix,
  covariates = add_covariates(
    covariates = c("cov1", "cov2"),
    priors = normal_prior(0, 1000)
  ),
  outcome = exp_surv_dist(
    "time",
    "cnsr",
    baseline_prior = normal_prior(0, 1000)
  ),
  borrowing = borrowing_details(
    "BDB",
    "ext",
    exponential_prior(.001)
  ),
  treatment = treatment_details(
    "trt",
    normal_prior(0, 1000)
  )
)
#> Inputs look good.
#> Stan program compiled successfully!
#> Ready to go! Now call `mcmc_sample()`.
samples <- mcmc_sample(analysis_object)
#> Running MCMC with 4 sequential chains...
#> 
#> Chain 1 finished in 7.2 seconds.
#> Chain 2 finished in 6.8 seconds.
#> Chain 3 finished in 7.1 seconds.
#> Chain 4 finished in 8.3 seconds.
#> 
#> All 4 chains finished successfully.
#> Mean chain execution time: 7.4 seconds.
#> Total execution time: 29.9 seconds.
#> 
draws <- samples$draws()
renamed_draws <- rename_draws_covariates(draws, analysis_object)
summary(renamed_draws)
#> # A tibble: 8 × 10
#>   variable          mean   median      sd   mad       q5      q95  rhat ess_bulk
#>   <chr>            <num>    <num>   <num> <num>    <num>    <num> <num>    <num>
#> 1 lp__          -1.57e+3 -1.57e+3 1.76e+0 1.60  -1.57e+3 -1.56e+3  1.00   15493.
#> 2 treatment lo… -5.63e-1 -5.56e-1 2.33e-1 0.232 -9.61e-1 -1.91e-1  1.00    9533.
#> 3 commensurabi…  6.15e+1  9.04e+0 2.54e+2 9.43   1.05e+0  2.17e+2  1.00    6105.
#> 4 baseline log… -3.72e+0 -3.73e+0 2.01e-1 0.199 -4.05e+0 -3.38e+0  1.00    8413.
#> 5 baseline log… -3.21e+0 -3.21e+0 1.14e-1 0.114 -3.40e+0 -3.03e+0  1.00   16054.
#> 6 cov1           8.15e-1  8.14e-1 1.11e-1 0.111  6.34e-1  9.99e-1  1.00   20112.
#> 7 cov2           5.74e-1  5.75e-1 9.94e-2 0.100  4.10e-1  7.37e-1  1.00   18899.
#> 8 treatment HR   5.85e-1  5.74e-1 1.37e-1 0.133  3.83e-1  8.26e-1  1.00    9533.
#> # ℹ 1 more variable: ess_tail <num>