Learn R Programming

BayesMallowsSMC2 (version 0.2.1)

compute_sequentially: Compute the Bayesian Mallows model sequentially

Description

Fits the Bayesian Mallows model to sequentially arriving ranking or preference data using the SMC2 (Sequential Monte Carlo Squared) algorithm. This function can handle complete rankings, partial rankings, and pairwise preference data, and supports mixture models with multiple clusters.

Usage

compute_sequentially(
  data,
  hyperparameters = set_hyperparameters(),
  smc_options = set_smc_options(),
  topological_sorts = NULL
)

Value

An object of class BayesMallowsSMC2, which is a list containing:

alpha

A matrix of dispersion parameter values with dimensions [n_clusters, n_particles]. Each column represents one particle, and each row represents one cluster.

rho

A 3-dimensional array of latent ranking values with dimensions [n_items, n_clusters, n_particles]. Entry [i, k, j] gives the rank of item i in cluster k for particle j.

tau

A matrix of precision parameter values (for mixture models) with dimensions [n_clusters, n_particles]. Each column represents one particle.

cluster_probabilities

A 3-dimensional array of cluster assignment probabilities (for mixture models) with dimensions [n_particles, n_users, n_clusters]. Only present when n_clusters > 1.

importance_weights

A numeric vector of length n_particles containing the normalized importance weights for each particle.

ESS

A numeric vector of length n_timepoints containing the effective sample size at each timepoint.

resampling

An integer vector of length n_timepoints indicating whether resampling occurred at each timepoint (1 = yes, 0 = no).

n_particle_filters

An integer vector of length n_timepoints showing the number of particle filters used at each timepoint.

log_marginal_likelihood

A numeric value giving the estimated log marginal likelihood of the data.

alpha_traces

A list of parameter traces (only if trace = TRUE in set_smc_options()). Each element contains alpha values at one timepoint.

tau_traces

A list of parameter traces (only if trace = TRUE in set_smc_options()). Each element contains tau values at one timepoint.

rho_traces

A list of parameter traces (only if trace = TRUE in set_smc_options()). Each element contains rho values at one timepoint.

log_importance_weights_traces

A list of importance weight traces (only if trace = TRUE in set_smc_options()).

latent_rankings_traces

A list of latent ranking traces (only if trace_latent = TRUE in set_smc_options()).

Arguments

data

A dataframe containing partial rankings or pairwise preferences. If data contains complete or partial rankings, it must have the following columns:

  • timepoint: a numeric vector denoting the timepoint, starting at 1.

  • user: a vector identifying the user.

  • item1: ranking of item 1.

  • item2: ranking of item 2.

  • etc.

If data contains pairwise preferences, it must have the following structure:

  • timepoint: a numeric vector denoting the timepoint, starting at 1.

  • user: a vector identifying the user.

  • top_item: identifier for the preferred item.

  • bottom_item: identifier for the dispreferred item.

hyperparameters

A list returned from set_hyperparameters().

smc_options

A list returned from set_smc_options()

topological_sorts

A list returned from precompute_topological_sorts(). Only used with preference data, and defaults to NULL.

Details

The function implements the SMC2 algorithm for sequential Bayesian inference in the Mallows model. At each timepoint, it updates the particle approximation to the posterior distribution as new ranking or preference data arrives. The algorithm automatically performs resampling and rejuvenation steps when the effective sample size drops below the specified threshold.

The returned object has S3 methods for printing (print.BayesMallowsSMC2), summarizing (summary.BayesMallowsSMC2), and plotting (plot.BayesMallowsSMC2). For visualization of parameter evolution over time, see trace_plot().

References

10.1214/25-BA1564BayesMallowsSMC2

Examples

Run this code
# Compute the model sequentially 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)
)

# Print the model summary
mod

# Plot posterior distribution of alpha
plot(mod, parameter = "alpha")

Run the code above in your browser using DataLab