Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

generate_transitive_closure

Generate Transitive Closure


Description

Generate the transitive closure for a set of consistent pairwise comparisons. The result can be given in the preferences argument to compute_mallows.

Usage

generate_transitive_closure(df, cl = NULL)

Arguments

df

A data frame with one row per pairwise comparison, and columns assessor, top_item, and bottom_item. Each column contains the following:

  • assessor is a numeric vector containing the assessor index, or a character vector containing the (unique) name of the assessor.

  • bottom_item is a numeric vector containing the index of the item that was disfavored in each pairwise comparison.

  • top_item is a numeric vector containing the index of the item that was preferred in each pairwise comparison.

So if we have two assessors and five items, and assessor 1 prefers item 1 to item 2 and item 1 to item 5, while assessor 2 prefers item 3 to item 5, we have the following df:

assessor bottom_item top_item
1 2 1
1 5 1
2 5 3
cl

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

Value

A dataframe with the same columns as df, but with its set of rows expanded to include all pairwise preferences implied by the ones stated in df. The returned object has S3 subclass BayesMallowsTC, to indicate that this is the transitive closure.

See Also

Examples

# Let us first consider a simple case with two assessors, where assessor 1
# prefers item 1 to item 2, and item 1 to item 5, while assessor 2 prefers
# item 3 to item 5. We then have the following dataframe of pairwise
# comparisons:
library(dplyr)
pair_comp <- tribble(
  ~assessor, ~bottom_item, ~top_item,
  1, 2, 1,
  1, 5, 1,
  2, 5, 3
)
# We then generate the transitive closure of these preferences:
(pair_comp_tc <- generate_transitive_closure(pair_comp))
# In this case, no additional relations we implied by the ones
# stated in pair_comp, so pair_comp_tc has exactly the same rows
# as pair_comp.

# Now assume that assessor 1 also preferred item 5 to item 3, and
# that assessor 2 preferred item 4 to item 3.
pair_comp <- tribble(
  ~assessor, ~bottom_item, ~top_item,
  1, 2, 1,
  1, 5, 1,
  1, 3, 5,
  2, 5, 3,
  2, 3, 4
)
# We generate the transitive closure again:
(pair_comp_tc <- generate_transitive_closure(pair_comp))
# We now have one implied relation for each assessor.
# For assessor 1, it is implied that 1 is preferred to 3.
# For assessor 2, it is implied that 4 is preferred to 5.

## Not run: 
  # If assessor 1 in addition preferred item 3 to item 1,
  # the preferences would not be consistent. This is not yet supported by compute_mallows,
  # so it causes an error message. It will be supported in a future release of the package.
  # First, we add the inconsistent row to pair_comp
  pair_comp <- bind_rows(pair_comp,
                         tibble(assessor = 1, bottom_item = 1, top_item = 3))

  # This causes an error message and prints out the problematic rankings:
  (pair_comp_tc <- generate_transitive_closure(pair_comp))

## End(Not run)


## Not run: 
  # The computations can also be done in parallel
  library(parallel)
  cl <- makeCluster(detectCores() - 1)
  beach_tc <- generate_transitive_closure(beach_preferences, cl = cl)
  stopCluster(cl)

## End(Not run)

BayesMallows

Bayesian Preference Learning with the Mallows Rank Model

v1.0.1
GPL-3
Authors
Oystein Sorensen [aut, cre] (<https://orcid.org/0000-0003-0724-3542>), Valeria Vitelli [aut] (<https://orcid.org/0000-0002-6746-0453>), Marta Crispino [aut], Qinghua Liu [aut], Cristina Mollica [aut], Luca Tardella [aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.