generate_constraints: Generate Constraint Set from Pairwise Comparisons

View source: R/generate_constraints.R

generate_constraintsR Documentation

Generate Constraint Set from Pairwise Comparisons

Description

This function is relevant when compute_mallows is called repeatedly with the same data, e.g., when determining the number of clusters. It precomputes a list of constraints used internally by the MCMC algorithm, which otherwise would be recomputed each time compute_mallows is called.

Usage

generate_constraints(preferences, n_items, cl = NULL)

Arguments

preferences

Data frame of preferences. For the case of consistent rankings, preferences should be returned from generate_transitive_closure. For the case of inconsistent preferences, when using an error model as described in \insertCitecrispino2019;textualBayesMallows, a dataframe of preferences can be directly provided.

n_items

Integer specifying the number of items.

cl

Optional computing cluster used for parallelization, returned from parallel::makeCluster. Defaults to NULL.

Value

A list which is used internally by the MCMC algorithm.

References

\insertAllCited

See Also

Other preprocessing: estimate_partition_function(), generate_initial_ranking(), generate_transitive_closure(), obs_freq, prepare_partition_function()

Examples

# Here is an example with the beach preference data.
# First, generate the transitive closure.
beach_tc <- generate_transitive_closure(beach_preferences)

# Next, generate an initial ranking.
beach_init_rank <- generate_initial_ranking(beach_tc)

# Then generate the constrain set used intervally by compute_mallows
constr <- generate_constraints(beach_tc, n_items = 15)

# Provide all these elements to compute_mallows
model_fit <- compute_mallows(rankings = beach_init_rank,
preferences = beach_tc, constraints = constr)

## Not run: 
  # The constraints can also be generated in parallel
  library(parallel)
  cl <- makeCluster(detectCores() - 1)
  constr <- generate_constraints(beach_tc, n_items = 15, cl = cl)
  stopCluster(cl)

## End(Not run)

BayesMallows documentation built on Nov. 25, 2023, 5:09 p.m.