Skip to contents

This function performs Markov Chain Monte Carlo (MCMC) sampling on the input data and returns tidy data and a plot representing the results.

Usage

tidy_mcmc_sampling(.x, .fns = "mean", .cum_fns = "cmean", .num_sims = 2000)

Arguments

.x

The data vector for MCMC sampling.

.fns

The function(s) to apply to each MCMC sample. Default is "mean".

.cum_fns

The function(s) to apply to the cumulative MCMC samples. Default is "cmean".

.num_sims

The number of simulations. Default is 2000.

Value

A list containing tidy data and a plot.

Details

Perform MCMC sampling and return tidy data and a plot.

The function takes a data vector as input and performs MCMC sampling with the specified number of simulations. It applies user-defined functions to each MCMC sample and to the cumulative MCMC samples. The resulting data is formatted in a tidy format, suitable for further analysis. Additionally, a plot is generated to visualize the MCMC samples and cumulative statistics.

Author

Steven P. Sanderson II, MPH

Examples

# Generate MCMC samples
set.seed(123)
data <- rnorm(100)
result <- tidy_mcmc_sampling(data, "median", "cmedian", 500)
#> Warning: Setting '.num_sims' to less than 2000 means that results can be potentially
#> unstable. Consider setting to 2000 or more.
result
#> $mcmc_data
#> # A tibble: 1,000 × 3
#>    sim_number name                 value
#>    <fct>      <fct>                <dbl>
#>  1 1          .sample_median    -0.0285 
#>  2 1          .cum_stat_cmedian -0.0285 
#>  3 2          .sample_median     0.239  
#>  4 2          .cum_stat_cmedian  0.105  
#>  5 3          .sample_median     0.00576
#>  6 3          .cum_stat_cmedian  0.00576
#>  7 4          .sample_median    -0.0357 
#>  8 4          .cum_stat_cmedian -0.0114 
#>  9 5          .sample_median    -0.111  
#> 10 5          .cum_stat_cmedian -0.0285 
#> # ℹ 990 more rows
#> 
#> $plt

#>