Learn R Programming

BayesMallowsSMC2 (version 0.2.1)

plot.BayesMallowsSMC2: Plot Posterior Distributions for BayesMallowsSMC2 Objects

Description

Visualize posterior distributions of the parameters of the Bayesian Mallows model after the final timepoint.

Usage

# S3 method for BayesMallowsSMC2
plot(x, parameter = "alpha", items = NULL, ...)

Value

A ggplot object showing:

  • For parameter = "alpha": A histogram of the posterior distribution of the dispersion parameter.

  • For parameter = "tau": A histogram of the posterior distribution of the precision parameter.

  • For parameter = "rho": Bar charts showing the posterior probability of each ranking for each item separately.

Arguments

x

An object of class BayesMallowsSMC2, returned from compute_sequentially().

parameter

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

items

The items to study in the plot for rho. Either a vector of item names or a vector of indices (1 to n_items). If NULL and there are more than 5 items, 5 items are selected randomly. Only used when parameter = "rho".

...

Other arguments (currently unused).

Details

The function uses importance weights from the SMC algorithm to compute weighted posterior distributions. For mixture models (multiple clusters), separate plots are created for each cluster using faceting.

For parameter = "rho", if the number of items is large (> 5) and items is not specified, a random subset of 5 items is selected for visualization. The random selection respects the current random seed, so results are reproducible if you set a seed before calling the function (e.g., with set.seed()).

Examples

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

# Plot alpha (default)
plot(mod)

# Plot tau
plot(mod, parameter = "tau")

# Plot rho for specific items
plot(mod, parameter = "rho", items = c(1, 3, 5))

# Plot rho for all items (if <= 5 items)
plot(mod, parameter = "rho")
# }

Run the code above in your browser using DataLab