View source: R/generate_constraints.R
generate_constraints | R Documentation |
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.
generate_constraints(preferences, n_items, cl = NULL)
preferences |
Data frame of preferences. For the case of consistent
rankings, |
n_items |
Integer specifying the number of items. |
cl |
Optional computing cluster used for parallelization, returned
from |
A list which is used internally by the MCMC algorithm.
Other preprocessing:
estimate_partition_function()
,
generate_initial_ranking()
,
generate_transitive_closure()
,
obs_freq
,
prepare_partition_function()
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.