Learn R Programming

BayesMallowsSMC2 (version 0.2.1)

trace_plot: Create Trace Plots for BayesMallowsSMC2 Objects

Description

Visualize the timeseries dynamics of the alpha and tau parameters across timepoints. This function creates trace plots similar to Figure 4 (left) in 10.1214/25-BA1564BayesMallowsSMC2.

Usage

trace_plot(x, parameter = "alpha", ...)

Value

A ggplot object showing the evolution of the parameter over time. For each timepoint, the plot shows:

  • The weighted mean (solid line)

  • The weighted 0.025 and 0.975 quantiles (shaded area representing the 95% credible interval)

Arguments

x

An object of class BayesMallowsSMC2, returned from compute_sequentially() with trace = TRUE in set_smc_options().

parameter

Character string defining the parameter to plot. Available options are "alpha" (default) and "tau".

...

Other arguments (currently unused).

Details

This function requires that the model was fitted with trace = TRUE in the smc_options. The trace contains the parameter values at each timepoint, which allows visualization of how the posterior distribution evolves as more data arrives sequentially.

For mixture models (multiple clusters), separate trace plots are created for each cluster using faceting.

The shaded area represents the 95% credible interval (from 2.5% to 97.5% quantiles) of the posterior distribution at each timepoint, computed using the importance weights from the SMC algorithm.

References

10.1214/25-BA1564BayesMallowsSMC2

Examples

Run this code
# \donttest{
# Fit a model with trace enabled
mod <- compute_sequentially(
  complete_rankings,
  hyperparameters = set_hyperparameters(n_items = 5),
  smc_options = set_smc_options(
    n_particles = 100,
    n_particle_filters = 1,
    trace = TRUE
  )
)

# Create trace plot for alpha (default)
trace_plot(mod)
# }

Run the code above in your browser using DataLab