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

if (check_cmdstan()) {
  analysis_object <- create_analysis_obj(
    data_matrix = example_matrix,
    covariates = add_covariates(
      covariates = c("cov1", "cov2"),
      priors = prior_normal(0, 1000)
    ),
    outcome = outcome_surv_exponential(
      "time",
      "cnsr",
      baseline_prior = prior_normal(0, 1000)
    ),
    borrowing = borrowing_hierarchical_commensurate(
      "ext",
      prior_exponential(.001)
    ),
    treatment = treatment_details(
      "trt",
      prior_normal(0, 1000)
    )
  )
  samples <- mcmc_sample(analysis_object, 200, 400, 1)
  draws <- samples$draws()
  renamed_draws <- rename_draws_covariates(draws, analysis_object)
  summary(renamed_draws)
}
#> Inputs look good.
#> Stan program compiled successfully!
#> Ready to go! Now call `mcmc_sample()`.
#> Running MCMC with 1 chain...
#> 
#> Chain 1 finished in 0.4 seconds.
#> # A tibble: 8 × 10
#>   variable        mean   median      sd     mad       q5      q95  rhat ess_bulk
#>   <chr>          <dbl>    <dbl>   <dbl>   <dbl>    <dbl>    <dbl> <dbl>    <dbl>
#> 1 lp__        -1.57e+3 -1.57e+3 1.78e+0  1.64   -1.57e+3 -1.56e+3  1.02     81.6
#> 2 treatment … -5.76e-1 -5.75e-1 2.24e-1  0.218  -9.34e-1 -2.04e-1  1.02     68.2
#> 3 baseline l… -3.71e+0 -3.72e+0 2.02e-1  0.175  -4.02e+0 -3.31e+0  1.04     41.2
#> 4 baseline l… -3.22e+0 -3.22e+0 1.16e-1  0.0991 -3.42e+0 -3.03e+0  1.01    138. 
#> 5 commensura…  1.31e+2  9.75e+0 4.04e+2 10.6     1.31e+0  1.52e+3  1.06     33.2
#> 6 cov1         8.20e-1  8.30e-1 1.07e-1  0.113   6.40e-1  9.99e-1  1.00    241. 
#> 7 cov2         5.74e-1  5.68e-1 9.72e-2  0.0893  4.19e-1  7.30e-1  1.00    209. 
#> 8 treatment …  5.77e-1  5.63e-1 1.36e-1  0.121   3.93e-1  8.15e-1  1.02     68.2
#> # ℹ 1 more variable: ess_tail <dbl>