Package {ConsRank}


Type: Package
Title: Compute the Median Ranking(s) According to the Kemeny's Axiomatic Approach
Version: 3.1.2
Date: 2026-11-24
Maintainer: Antonio D'Ambrosio <antdambr@unina.it>
Depends: R (≥ 4.1.0)
LinkingTo: Rcpp
Imports: rlist (≥ 0.4.2), methods, proxy, gtools, Rcpp
Suggests: rgl, plotly
Description: Compute the median ranking according to the Kemeny's axiomatic approach. Rankings can or cannot contain ties, rankings can be both complete or incomplete. The package contains both branch-and-bound algorithms and heuristic solutions. The search space of the solution can be the universe of all rankings with ties, the permutations, or the bucket orders with a given number of buckets or with a given pattern of bucket sizes, top-k lists included. The package also provides some useful utilities to deal with preference rankings, including the element-weight Kemeny distance and correlation coefficient. Essential references: Emond, E.J., and Mason, D.W. (2002) <doi:10.1002/mcda.313>; D'Ambrosio, A., Amodio, S., and Iorio, C. (2015) <doi:10.1285/i20705948v8n2p198>; Amodio, S., D'Ambrosio, A., and Siciliano R. (2016) <doi:10.1016/j.ejor.2015.08.048>; D'Ambrosio, A., Mazzeo, G., Iorio, C., and Siciliano, R. (2017) <doi:10.1016/j.cor.2017.01.017>; Albano, A., and Plaia, A. (2021) <doi:10.1285/i20705948v14n1p117>; D'Ambrosio, A., Iorio, C., Staiano, M. and Siciliano, R (2019) <doi:10.1007/s00180-018-0858-z>; Romano, M., Coraggio, L., Conversano, C., and D'Ambrosio, A. (2026) <doi:10.48550/arXiv.2611.28925>.
License: GPL-3
Encoding: UTF-8
Config/roxygen2/version: 8.1.0
NeedsCompilation: yes
Packaged: 2026-11-24 12:06:24 UTC; Antonio
Author: Antonio D'Ambrosio [aut, cre], Sonia Amodio [ctb], Giulio Mazzeo [ctb], Alessandro Albano [ctb], Antonella Plaia [ctb], Maurizio Romano [ctb], Luca Coraggio [ctb]
Repository: CRAN
Date/Publication: 2026-11-24 13:30:25 UTC

Median Ranking Approach According to the Kemeny's Axiomatic Approach

Description

Compute the median ranking according to the Kemeny's axiomatic approach. Rankings can or cannot contain ties, rankings can be both complete or incomplete. The package contains both branch-and-bound and heuristic solutions, including the deterministic BOLT algorithm (bolt), as well as routines for computing the median constrained bucket order, with a given number of buckets or a given pattern of bucket sizes (mcbo), and the median top-k list (consranktopk). The package also contains routines for visualizing rankings, for detecting the universe of rankings including ties, and for reading the data files of PrefLib (readpreflib).

Author(s)

Antonio D'Ambrosio [cre,aut] <antdambr@unina.it>, Sonia Amodio <sonia.amodio@unina.it> [ctb], Giulio Mazzeo [ctb] <giuliomazzeo@gmail.com>, Alessandro Albano [ctb], Antonella Plaia [ctb], Maurizio Romano [ctb]

Maintainer: Antonio D'Ambrosio <antdambr@unina.it>

References

Kemeny, J. G., & Snell, J. L. (1962). Mathematical models in the social sciences (Vol. 9). New York: Ginn.

Marden, J. I. (1996). Analyzing and modeling rank data. CRC Press.

Emond, E. J., & Mason, D. W. (2002). A new rank correlation coefficient with application to the consensus ranking problem. Journal of Multi-Criteria Decision Analysis, 11(1), 17-28.

D'Ambrosio, A. (2008). Tree based methods for data editing and preference rankings. Ph.D. thesis. https://www.fedoa.unina.it/2746/

Heiser, W. J., & D'Ambrosio, A. (2013). Clustering and prediction of rankings within a Kemeny distance framework. In Algorithms from and for Nature and Life (pp. 19-31). Springer International Publishing.

Amodio, S., D'Ambrosio, A. & Siciliano, R (2016). Accurate algorithms for identifying the median ranking when dealing with weak and partial rankings under the Kemeny axiomatic approach. European Journal of Operational Research, vol. 249(2).

D'Ambrosio, A., Amodio, S. & Iorio, C. (2015). Two algorithms for finding optimal solutions of the Kemeny rank aggregation problem for full rankings. Electronic Journal of Applied Statistical Analysis, vol. 8(2).

D'Ambrosio, A., Mazzeo, G., Iorio, C., & Siciliano, R. (2017). A differential evolution algorithm for finding the median ranking under the Kemeny axiomatic approach. Computers & Operations Research, vol. 82.

D'Ambrosio, A., & Heiser, W.J. (2019). A Distribution-free Soft Clustering Method for Preference Rankings. Behaviormetrika , vol. 46(2), pp. 333–351.

D'Ambrosio, A., Iorio, C., Staiano, M., & Siciliano, R. (2019). Median constrained bucket order rank aggregation. Computational Statitstics, vol. 34(2), pp. 787–802,

Examples

## load APA data set, full version
data(APAFULL)
## Emond and Mason Branch-and-Bound algorithm.
#CR=consrank(APAFULL)
#use frequency tables
#TR=tabulaterows(APAFULL)
#quick algorithm
#CR2=consrank(TR$X,wk=TR$Wk,algorithm="quick")
#FAST algorithm
#CR3=consrank(TR$X,wk=TR$Wk,algorithm="fast",itermax=10)
#Decor algorithm
#CR4=consrank(TR$X,wk=TR$Wk,algorithm="decor",itermax=10)

#####################################
### load sports data set
#data(sports)
### FAST algorithm
#CR=consrank(sports,algorithm="fast",itermax=10)
#####################################

#######################################
### load Emond and Mason data set
#data(EMD)
### matrix X contains rankings
#X=EMD[,1:15]
### vector Wk contains frequencies
#Wk=EMD[,16]
### QUICK algorithm
#CR=consrank(X,wk=Wk,algorithm="quick")
#######################################


American Psychological Association dataset, full version

Description

The American Psychological Association dataset includes 15449 ballots of the election of the president in 1980, 5738 of which are complete rankings, in which the candidates are ranked from most to least favorite.

Usage

data(APAFULL)

Source

Diaconis, P. (1988). Group representations in probability and statistics. Lecture Notes-Monograph Series, i-192., pag. 96.


American Psychological Association dataset, reduced version with only full rankings

Description

The American Psychological Association reduced dataset includes 5738 ballots of the election of the president in 1980, in which the candidates are ranked from most to least favorite.

Usage

data(APAred)

Source

Diaconis, P. (1988). Group representations in probability and statistics. Lecture Notes-Monograph Series, i-192., pag. 96.


Brook and Upton data

Description

The data consist of ballots of three candidates, where the 948 voters rank the candidates from 1 to 3. Data are in form of frequency table.

Usage

data(BU)

Source

Brook, D., & Upton, G. J. G. (1974). Biases in local government elections due to position on the ballot paper. Applied Statistics, 414-419.

References

Marden, J. I. (1996). Analyzing and modeling rank data. CRC Press, pag. 153.

Examples

data(BU)
polyplot(BU[,1:3],Wk=BU[,4])


Defunct functions in ConsRank

Description

These functions have been removed from ConsRank. Use the alternatives listed below.

Usage

EMCons(...)

QuickCons(...)

BBFULL(...)

FASTcons(...)

DECOR(...)

FASTDECOR(...)

Details


Emond and Mason data

Description

Data simuated by Emond and Mason to check their branch-and-bound algorithm. There are 112 voters ranking 15 objects. There are 21 uncomplete rankings. Data are in form of frequency table.

Usage

data(EMD)

Source

Emond, E. J., & Mason, D. W. (2000). A new technique for high level decision support. Department of National Defence, Operational Research Division, pag. 28.

References

Emond, E. J., & Mason, D. W. (2000). A new technique for high level decision support. Department of National Defence, Operational Research Division, pag. 28.

Examples

data(EMD)
CR=consrank(EMD[,1:15],EMD[,16],algorithm="quick")


German political goals

Description

Ranking data of 2262 German respondents about the desirability of the four political goals: a = the maintenance of order in the nation; b = giving people more say in the decisions of government; c = growthing rising prices; d = protecting freedom of speech

Usage

data(German)

Source

Croon, M. A. (1989). Latent class models for the analysis of rankings. Advances in psychology, 60, 99-121.

Examples

data(German)
TR=tabulaterows(German)
if (requireNamespace("rgl", quietly = TRUE)) {
  polyplot(TR$X, Wk = TR$Wk, engine = "rgl")
}

Idea data set

Description

98 college students where asked to rank five words, (thought, play, theory, dream, attention) regarding its association with the word idea, from 5=most associated to 1=least associated.

Usage

data(Idea)

Source

Fligner, M. A., & Verducci, J. S. (1986). Distance based ranking models. Journal of the Royal Statistical Society. Series B (Methodological), 359-369.

Examples

data(Idea)
revIdea=6-Idea
TR=tabulaterows(revIdea)
CR=consrank(TR$X,wk=TR$Wk,algorithm="quick")
colnames(CR$Consensus)=colnames(Idea)


USA rank data

Description

Random subset of the rankings collected by O'Leary Morgan and Morgon (2010) on the 50 American States. The 368 number of items (the number of American States) is equal to 50, and the number of rankings is equal to 104. These data concern rankings of the 50 American States on three particular aspects: socio-demographic characteristics, health care expenditures and crime statistics.

Usage

data(USAranks)

Source

Amodio, S., D'Ambrosio, A. & Siciliano, R (2015). Accurate algorithms for identifying the median ranking when dealing with weak and partial rankings under the Kemeny axiomatic approach. European Journal of Operational Research. DOI: 10.1016/j.ejor.2015.08.048

References

O'Leary Morgan, K., Morgon, S., (2010). State Rankings 2010: A Statistical view of America; Crime State Ranking 2010: Crime Across America; Health Care State Rankings 2010: Health Care Across America. CQ Press.

Examples

data(USAranks)

BOLT algorithm for the median ranking

Description

Find the median ranking according to the Kemeny's axiomatic approach with BOLT (Bucket-Order Local search with optimal Tie partitioning), a deterministic and scalable heuristic that works entirely on the combined input matrix.

Usage

bolt(
  X = NULL,
  wk = NULL,
  full = FALSE,
  otp = TRUE,
  maxjudges = Inf,
  ps = FALSE,
  cij = NULL,
  nj = NULL
)

Arguments

X

A N by M data matrix, in which there are N judges and M objects to be judged. Each row is a ranking of the objects which are represented by the columns. If X contains the rankings observed only once, the argument wk can be used. Either X or cij must be given

wk

Optional: the frequency of each ranking in the data

full

Logical. If TRUE, the median ranking is searched in the space of full rankings (permutations), i.e. without ties. Default FALSE

otp

Logical. If TRUE (default), the local search is alternated with the exact optimal tie partitioning (the "full" configuration of the paper); if FALSE, only the tie-aware local search is used (the "fast" configuration). Ignored when full = TRUE

maxjudges

Maximum number of distinct rankings of the judges used as starting solutions, the most frequent first. Default Inf (all of them); 0 uses only the starting solutions computed from the combined input matrix

ps

Logical. If TRUE, displays information on screen. Default FALSE

cij

The combined input matrix (M by M, see combinpmatr), to be given instead of X. With cij, the argument wk is ignored and the rankings of the judges are not used as starting solutions

nj

The number of judges (the sum of the weights, if any) that produced cij. Required when cij is given: it is used to compute the averaged TauX

Details

The median ranking maximizes the averaged TauX rank correlation coefficient with the rankings of the judges, which depends on the data only through the combined input matrix C (Emond and Mason, 2002). BOLT works entirely on C and combines three ingredients:

  1. starting solutions computed from C (net flow, Copeland, a Markov chain score, a bucket pivot order and the starting solution of the branch-and-bound algorithm) and the rankings of the judges;

  2. a tie-aware insertion local search: an object is moved to another position or tied with a group of objects, and each move is evaluated in O(M) time;

  3. the optimal tie partitioning: for a fixed order of the objects, the tie structure maximizing TauX is computed exactly by dynamic programming in O(M^2) time.

The local search and the optimal tie partitioning are alternated until no improvement, from each starting solution; the best solution(s) are returned. When ties are allowed (full = FALSE), a first phase runs the local search without ties from each starting solution (ties broken) and adds the resulting full rankings to the starting solutions: the result is never worse than the one with full = TRUE. The procedure is deterministic: no random starting solutions are used.

Instead of the data X, the combined input matrix cij can be given, together with the number of judges nj.

Value

A list containing the following components:

Consensus the consensus ranking(s)
Tau averaged TauX rank correlation coefficient
Eltime elapsed time in seconds

Author(s)

Maurizio Romano

References

Romano, M., D'Ambrosio, A., and Conversano, C. A deterministic and scalable heuristic for median ranking detection: tie-aware local search with optimal tie partitioning on the combined input matrix. Manuscript under review.

Emond, E. J., and Mason, D. W. (2002). A new rank correlation coefficient with application to the consensus ranking problem. Journal of Multi-Criteria Decision Analysis, 11(1), 17-28.

See Also

consrank, mcbo, combinpmatr

Examples

data(EMD)
CR <- bolt(EMD[, 1:15], wk = EMD[, 16])
CR$Consensus
CR$Tau
# the same result from the combined input matrix
CR2 <- bolt(cij = combinpmatr(EMD[, 1:15], EMD[, 16]), nj = sum(EMD[, 16]),
            maxjudges = 0)


Combined input matrix with C++ optimization

Description

Compute the Combined input matrix of a data set as defined by Emond and Mason (2002). This version uses C++ for improved performance.

Usage

combinpmatr(X, Wk = NULL, use_cpp = TRUE)

Arguments

X

A data matrix N by M, in which there are N judges and M objects to be judged. Each row is a ranking of the objects which are represented by the columns. Alternatively X can contain the rankings observed only once. In this case the argument Wk must be used

Wk

Optional: the frequency of each ranking in the data

use_cpp

Logical. If TRUE (default), use the optimized C++ implementation. If FALSE, use the original R implementation.

Details

This function now uses an optimized C++ implementation (combinpmatr_impl) for improved performance. The original R implementation is preserved for reference and can be accessed by setting use_cpp = FALSE.

The C++ implementation provides significant speedup (typically 10-100x) compared to the R implementation, especially for large datasets with many judges and objects.

Value

The M by M combined input matrix

Author(s)

Antonio D'Ambrosio antdambr@unina.it

References

Emond, E. J., and Mason, D. W. (2002). A new rank correlation coefficient with application to the consensus ranking problem. Journal of Multi-Criteria Decision Analysis, 11(1), 17-28.

See Also

tabulaterows frequency distribution of a ranking data.

Examples

# Simple example
X <- matrix(c(1,2,3,4, 2,1,4,3, 1,3,2,4), nrow=3, byrow=TRUE)
CI <- combinpmatr(X)

# With weights
CI_weighted <- combinpmatr(X, Wk=c(2, 1, 3))

# Compare implementations
## Not run: 
data(APAred) 
system.time(CI1 <- combinpmatr(APAred, use_cpp=TRUE))
system.time(CI2 <- combinpmatr(APAred, use_cpp=FALSE))
all.equal(CI1, CI2)  # Should be TRUE

## End(Not run)


Branch-and-bound and heuristic algorithms to find consensus (median) ranking according to the Kemeny's axiomatic approach

Description

Branch-and-bound, Quick , FAST and DECOR algorithms to find consensus (median) ranking according to the Kemeny's axiomatic approach. The median ranking(s) can be restricted to be necessarily a full ranking, namely without ties

Usage

consrank(
  X = NULL,
  wk = NULL,
  ps = TRUE,
  algorithm = "BB",
  full = FALSE,
  itermax = 10,
  np = 15,
  gl = 100,
  ff = 0.4,
  cr = 0.9,
  proc = FALSE,
  use_cpp = TRUE,
  otp = TRUE,
  maxjudges = Inf,
  cij = NULL,
  nj = NULL
)

Arguments

X

A n by m data matrix, in which there are n judges and m objects to be judged. Each row is a ranking of the objects which are represented by the columns. If X contains the rankings observed only once, the argument wk can be used. Either X or cij must be given

wk

Optional: the frequency of each ranking in the data

ps

If PS=TRUE, on the screen some information about how many branches are processed are displayed.

algorithm

Specifies the used algorithm. One among "BB", "quick", "fast", "decor" and "BOLT". algorithm="BB" is the default option. The name of the algorithm is matched ignoring the case.

full

Specifies if the median ranking must be searched in the universe of rankings including all the possible ties (full=FALSE) or in the restricted space of full rankings (permutations). full=FALSE is the default option.

itermax

maximum number of iterations for FAST and DECOR algorithms. itermax=10 is the default option.

np

For DECOR algorithm only: the number of population individuals. np=15 is the default option.

gl

For DECOR algorithm only: generations limit, maximum number of consecutive generations without improvement. gl=100 is the default option.

ff

For DECOR algorithm only: the scaling rate for mutation. Must be in [0,1]. ff=0.4 is the default option.

cr

For DECOR algorithm only: the crossover range. Must be in [0,1]. cr=0.9 is the default option.

proc

For BB algorithm only: proc=TRUE allows the branch and bound algorithm to work in difficult cases, i.e. when the number of objects is larger than 15 or 25. proc=FALSE is the default option

use_cpp

Logical. If TRUE (default), uses C++ implementation for faster computation. If FALSE, uses the R implementation. Ignored with algorithm = "BOLT", which is implemented in C++ only.

otp

For BOLT algorithm only: if TRUE (default), the optimal tie partitioning step is used (see bolt).

maxjudges

For BOLT algorithm only: maximum number of distinct rankings of the judges used as starting solutions (see bolt). Default Inf (all of them).

cij

The combined input matrix (m by m, see combinpmatr), to be given instead of X. All the algorithms depend on the data only through this matrix (Emond and Mason, 2002). With cij, the argument wk is ignored and the rankings of the judges are not used as starting solutions by BOLT

nj

The number of judges (the sum of the weights, if any) that produced cij. Required when cij is given: it is used to compute the averaged TauX

Details

The BB algorithm can take long time to find the solutions if the number objects to be ranked is large with some missing (>15-20 if full=FALSE, <25-30 if full=TRUE). quick algorithm works with a large number of items to be ranked. The solution is quite accurate. fast algorithm works with a large number of items to be ranked by repeating several times the quick algorithm with different random starting points. decor algorithm works with a very large number of items to be ranked. BOLT algorithm is a deterministic heuristic that works with a very large number of items (even more than one thousand), see bolt. For decor algorithm, empirical evidence shows that the number of population individuals (the 'np' parameter) can be set equal to 10, 20 or 30 for problems till 20, 50 and 100 items. Both scaling rate and crossover ratio (parameters 'ff' and 'cr') must be set by the user. The default options (ff=0.4, cr=0.9) work well for a large variety of data sets All algorithms allow the user to set the option 'full=TRUE' if the median ranking(s) must be searched in the restricted space of permutations instead of in the unconstrained universe of rankings of n items including all possible ties

Instead of the data X, the combined input matrix cij can be given, together with the number of judges nj. This is useful when only the pairwise preferences are available, or when the median ranking of many subsets of the data is needed (the combined input matrix of a group is the sum of those of its parts).

Value

a "list" containing the following components:

Consensus the Consensus Ranking
Tau averaged TauX rank correlation coefficient
Eltime Elapsed time in seconds

#'

Author(s)

Antonio D'Ambrosio antdambr@unina.it

References

Emond, E. J., and Mason, D. W. (2002). A new rank correlation coefficient with application to the consensus ranking problem. Journal of Multi-Criteria Decision Analysis, 11(1), 17-28. D'Ambrosio, A., Amodio, S., and Iorio, C. (2015). Two algorithms for finding optimal solutions of the Kemeny rank aggregation problem for full rankings. Electronic Journal of Applied Statistical Analysis, 8(2), 198-213. Amodio, S., D'Ambrosio, A. and Siciliano, R. (2016). Accurate algorithms for identifying the median ranking when dealing with weak and partial rankings under the Kemeny axiomatic approach. European Journal of Operational Research, 249(2), 667-676. D'Ambrosio, A., Mazzeo, G., Iorio, C., and Siciliano, R. (2017). A differential evolution algorithm for finding the median ranking under the Kemeny axiomatic approach. Computers and Operations Research, vol. 82, pp. 126-138.

See Also

iwquickcons, bolt, mcbo

Examples

data(Idea)
RevIdea<-6-Idea 
# as 5 means "most associated", it is necessary compute the reverse ranking of 
# each rankings to have rank 1 = "most associated" and rank 5 = "least associated"
CR<-consrank(RevIdea)
CR<-consrank(RevIdea,algorithm="quick")
# the same median ranking from the combined input matrix
CR2<-consrank(cij=combinpmatr(RevIdea),nj=nrow(RevIdea))
#CR<-consrank(RevIdea,algorithm="fast",itermax=10)
#not run
#data(EMD)
#CRemd<-consrank(EMD[,1:15],wk=EMD[,16],algorithm="decor",itermax=1)
#data(APAFULL)
#CRapa<-consrank(APAFULL,full=TRUE)



Median top-k list

Description

Find the median top-k list according to the Kemeny's axiomatic approach: the consensus ranking in which k objects are ranked in strict order in the first k positions and all the other objects are tied in the last position. It is the median constrained bucket order with bucket sizes 1, ..., 1 (k times) and a last bucket with the remaining objects (see mcbo with bucketsizes = rep(1, k)). By default the solution is exact whenever possible (see Details).

Usage

consranktopk(
  X = NULL,
  k,
  wk = NULL,
  ps = TRUE,
  maxjudges = Inf,
  cij = NULL,
  nj = NULL,
  algorithm = c("exact", "BOLT"),
  maxcand = 22
)

Arguments

X

A N by M data matrix, in which there are N judges and M objects to be judged. Each row is a ranking of the objects which are represented by the columns. If X contains the rankings observed only once, the argument wk can be used. Either X or cij must be given

k

The number of objects of the top-k list: a whole number between 1 and M-1 (with k = M-1 the top-k list is a full ranking)

wk

Optional: the frequency of each ranking in the data

ps

Logical. If TRUE, displays information on screen. Default TRUE

maxjudges

Maximum number of distinct rankings of the judges used as starting solutions by BOLT, the most frequent first. Default Inf (all of them); 0 uses only the starting solutions computed from the combined input matrix

cij

The combined input matrix (M by M, see combinpmatr), to be given instead of X. With cij, the argument wk is ignored and the rankings of the judges are not used as starting solutions

nj

The number of judges (the sum of the weights, if any) that produced cij. Required when cij is given: it is used to compute the averaged TauX

algorithm

"exact" (default): the exact solution, found by dynamic programming on the objects that can belong to an optimal list, when they are at most maxcand; otherwise the BOLT solution. "BOLT": always the BOLT solution, as mcbo(X, bucketsizes = rep(1, k), algorithm = "BOLT")

maxcand

The largest number of candidate objects for the exact solution (default 22). The memory used grows as 2^maxcand (8 bytes times 2^maxcand: 32 MB with 22); at most 30

Details

The objects of the top-k list are those for which the judges agree most on placing them in front of the others, and their order is the one that best agrees with the judges; the objects outside the list are tied, so that their mutual order does not matter. Like the other functions of the package, the solution maximizes the averaged TauX rank correlation coefficient with the rankings of the judges. The procedure is deterministic.

With the combined input matrix C (elements c_ij), the agreement of a top-k list with the judges is a constant plus

\sum_{t=1}^{k} g_{a_t} + 2 \sum_{s<t} c_{a_s a_t},

where a_1, \ldots, a_k are the objects of the list in order and g_a = -2 \sum_{j \neq a} c_{ja} depends only on the column total of the object a. With algorithm = "exact", the objects that cannot belong to an optimal list are first removed, by two rules applied repeatedly: an object of an optimal list cannot be improved by replacing it with an object outside the list, and the value of a list containing the object, bounded from above, must reach the value of a known list. The best list of the remaining candidates is then found exactly by dynamic programming over their subsets with at most k objects, and all the optimal lists are returned (at most 1000). The first rule needs no known list; if the candidates are more than maxcand, the BOLT solution is computed and used in the second rule; if they are still more than maxcand, the BOLT solution is returned and Exact is FALSE.

Value

A list containing the following components:

TopK the k objects of the median top-k list, in order (a matrix with one row per solution if there are several)
Consensus the consensus ranking(s) of all the objects, with the objects outside the top-k list tied in position k+1
Tau averaged TauX rank correlation coefficient
Exact TRUE if the solution is certified optimal, FALSE if it is the BOLT solution
Candidates the number of objects that can belong to an optimal list (NA with algorithm = "BOLT")
Eltime elapsed time in seconds

Author(s)

Antonio D'Ambrosio antdambr@unina.it

References

Emond, E. J., and Mason, D. W. (2002). A new rank correlation coefficient with application to the consensus ranking problem. Journal of Multi-Criteria Decision Analysis, 11(1), 17-28.

D'Ambrosio, A., Iorio, C., Staiano, M., and Siciliano, R. (2019). Median constrained bucket order rank aggregation. Computational Statistics, 34(2), 787-802. doi:10.1007/s00180-018-0858-z

Romano, M., D'Ambrosio, A., and Conversano, C. A deterministic and scalable heuristic for median ranking detection: tie-aware local search with optimal tie partitioning on the combined input matrix. Manuscript under review.

See Also

mcbo for bucket orders with a given number of buckets or a given pattern of bucket sizes

consrank for the unconstrained median ranking

bolt for the BOLT algorithm

Examples

data(EMD)
CR <- consranktopk(EMD[, 1:15], k = 3, wk = EMD[, 16])
CR$TopK
CR$Tau
CR$Exact


Item-weighted Kemeny distance

Description

Compute the item-weighted Kemeny distance of a data matrix containing preference rankings, or compute the kemeny distance between two (matrices containing) rankings.

Usage

iw_kemenyd(x, y = NULL, w)

Arguments

x

A N by M data matrix, in which there are N judges and M objects to be judged. Each row is a ranking of the objects which are represented by the columns. If there is only x as input, the output is a square distance matrix

y

A row vector, or a N by M data matrix in which there are N judges and the same M objects as x to be judged.

w

A M-dimensional row vector (individually weighted items), or a M by M matrix (item similarities)

Details

The Kemeny distance is defined for complete rankings (with or without ties): if x or y contain missing values (NA) the function stops with an error. Partial rankings must be completed by the user before computing the distance, e.g. by tying the missing objects in the last position.

Value

If there is only x as input, d = square distance matrix. If there is also y as input, d = matrix with N rows and n columns.

Author(s)

Alessandro Albano alessandro.albano@unipa.it
Antonella Plaia antonella.plaia@unipa.it

References

Kemeny, J. G., & Snell, L. J. (1962). Preference ranking: an axiomatic approach. Mathematical models in the social sciences, 9-23.
Albano, A. and Plaia, A. (2021) Element weighted Kemeny distance for ranking data. Electronic Journal of Applied Statistical Analysis, doi: 10.1285/i20705948v14n1p117

See Also

iw_tau_x item-weighted tau_x rank correlation coefficient

kemenyd Kemeny distance

Examples

#Individually weighted items
data("German")
w=c(10,5,5,10)
iw_kemenyd(x= German[c(1,200,300,500),],w= w)
iw_kemenyd(x= German[1,],y=German[400,],w= w)

#Item similarity weights
data(sports)
P=matrix(NA,nrow=7,ncol=7)
P[1,]=c(0,5,5,10,10,10,10)
P[2,]=c(5,0,5,10,10,10,10)
P[3,]=c(5,5,0,10,10,10,10)
P[4,]=c(10,10,10,0,5,5,5)
P[5,]=c(10,10,10,5,0,5,5)
P[6,]=c(10,10,10,5,5,0,5)
P[7,]=c(10,10,10,5,5,5,0)
iw_kemenyd(x=sports[c(1,3,5,7),], w= P)
iw_kemenyd(x=sports[1,],y=sports[100,], w= P)

Item-weighted TauX rank correlation coefficient

Description

Compute the item-weighted TauX rank correlation coefficient of a data matrix containing preference rankings, or compute the item-weighted correlation coefficient between two (matrices containing) rankings.

Usage

iw_tau_x(x, y = NULL, w)

Arguments

x

A N by M data matrix, in which there are N judges and M objects to be judged. Each row is a ranking of the objects which are represented by the columns. If there is only x as input, the output is a square matrix

y

A row vector, or a N by M data matrix in which there are N judges and the same M objects as x to be judged.

w

A M-dimensional row vector (individually weighted items), or a M by M matrix (item similarities)

Value

Item-weighted TauX rank correlation coefficient

Author(s)

Alessandro Albano alessandro.albano@unipa.it
Antonella Plaia antonella.plaia@unipa.it

References

Emond, E. J., and Mason, D. W. (2002). A new rank correlation coefficient with application to the consensus ranking problem. Journal of Multi-Criteria Decision Analysis, 11(1), 17-28.
Albano, A. and Plaia, A. (2021) Element weighted Kemeny distance for ranking data. Electronic Journal of Applied Statistical Analysis, doi: 10.1285/i20705948v14n1p117

See Also

tau_x TauX rank correlation coefficient

iw_kemenyd item-weighted Kemeny distance

Examples

#Individually weighted items
data("German")
w=c(10,5,5,10)
iw_tau_x(x= German[c(1,200,300,500),],w= w)
iw_tau_x(x= German[1,],y=German[400,],w= w)

#Item similarity weights
data(sports)
P=matrix(NA,nrow=7,ncol=7)
P[1,]=c(0,5,5,10,10,10,10)
P[2,]=c(5,0,5,10,10,10,10)
P[3,]=c(5,5,0,10,10,10,10)
P[4,]=c(10,10,10,0,5,5,5)
P[5,]=c(10,10,10,5,0,5,5)
P[6,]=c(10,10,10,5,5,0,5)
P[7,]=c(10,10,10,5,5,5,0)
iw_tau_x(x=sports[c(1,3,5,7),], w= P)
iw_tau_x(x=sports[1,],y=sports[100,], w= P)

Item-weighted Combined input matrix of a data set

Description

Compute the item-weighted Combined input matrix of a data set as defined by Albano and Plaia (2021)

Usage

iwcombinpmatr(X, w, Wk = NULL)

Arguments

X

A data matrix N by M, in which there are N judges and M objects to be judged. Each row is a ranking of the objects which are represented by the columns. Alternatively X can contain the rankings observed only once. In this case the argument Wk must be used

w

A M-dimensional row vector (individually weighted items), or a M by M matrix (item similarities)

Wk

Optional: the frequency of each ranking in the data

Value

The M by M item-weighted combined input matrix

Author(s)

Alessandro Albano alessandro.albano@unipa.it
Antonella Plaia antonella.plaia@unipa.it

References

Emond, E. J., and Mason, D. W. (2002). A new rank correlation coefficient with application to the consensus ranking problem. Journal of Multi-Criteria Decision Analysis, 11(1), 17-28.
Albano, A. and Plaia, A. (2021). Element weighted Kemeny distance for ranking data. Electronic Journal of Applied Statistical Analysis, doi: 10.1285/i20705948v14n1p117

See Also

tabulaterows frequency distribution of a ranking data.

combinpmatr combined input matrix of a ranking data set.

Examples

data(sports)
np <- dim(sports)[2]
P <- matrix(NA,nrow=np,ncol=np)
P[1,] <- c(0,5,5,10,10,10,10)
P[2,] <- c(5,0,5,10,10,10,10)
P[3,] <- c(5,5,0,10,10,10,10)
P[4,] <- c(10,10,10,0,5,5,5)
P[5,] <- c(10,10,10,5,0,5,5)
P[6,] <- c(10,10,10,5,5,0,5)
P[7,] <- c(10,10,10,5,5,5,0)
CIW <- iwcombinpmatr(sports,w=P) 


The item-weighted Quick algorithm to find up to 4 solutions to the consensus ranking problem

Description

The item-weighted Quick algorithm finds up to 4 solutions. Solutions reached are most of the time optimal solutions.

Usage

iwquickcons(X, w, Wk = NULL, full = FALSE, PS = FALSE)

Arguments

X

A N by M data matrix in which there are N judges and M objects to be judged. Each row is a ranking of the objects which are represented by the columns. Alternatively X can contain the rankings observed only once in the sample. In this case the argument Wk must be used

w

A M-dimensional row vector (individually weighted items), or a M by M matrix (item similarities)

Wk

Optional: the frequency of each ranking in the data

full

Default full=FALSE. If full=TRUE, the searching is limited to the space of full rankings.

PS

Default PS=FALSE. If PS=TRUE the number of evaluated branches is diplayed

Details

The item-weigthed Quick algorithm finds up the consensus (median) ranking according to the Kemeny's axiomatic approach. The median ranking(s) can be restricted to be necessarily a full ranking, namely without ties.

Value

a "list" containing the following components:

Consensus the Consensus Ranking
Tau averaged item-weighted TauX rank correlation coefficient
Eltime Elapsed time in seconds

Author(s)

Alessandro Albano alessandro.albano@unipa.it
Antonella Plaia antonella.plaia@unipa.it

References

Amodio, S., D'Ambrosio, A. and Siciliano, R. (2016). Accurate algorithms for identifying the median ranking when dealing with weak and partial rankings under the Kemeny axiomatic approach. European Journal of Operational Research, 249(2), 667-676.
Albano, A. and Plaia, A. (2021). Element weighted Kemeny distance for ranking data. Electronic Journal of Applied Statistical Analysis, doi: 10.1285/i20705948v14n1p117

See Also

consrank

Examples

#Individually weighted items
data("German")
w=c(10,5,5,10)
iwquickcons(X= German,w= w)

#Item similirity weights
data(sports)
dim(sports)
P=matrix(NA,nrow=7,ncol=7)
P[1,]=c(0,5,5,10,10,10,10)
P[2,]=c(5,0,5,10,10,10,10)
P[3,]=c(5,5,0,10,10,10,10)
P[4,]=c(10,10,10,0,5,5,5)
P[5,]=c(10,10,10,5,0,5,5)
P[6,]=c(10,10,10,5,5,0,5)
P[7,]=c(10,10,10,5,5,5,0)
iwquickcons(X= sports, w= P)


Kemeny distance

Description

Compute the Kemeny distance of a data matrix containing preference rankings, or compute the kemeny distance between two (matrices containing) rankings.

Usage

kemenyd(X, Y = NULL)

Arguments

X

A N by M data matrix, in which there are N judges and M objects to be judged. Each row is a ranking of the objects which are represented by the columns. If there is only X as input, the output is a square distance matrix

Y

A row vector, or a n by M data matrix in which there are n judges and the same M objects as X to be judged.

Details

The Kemeny distance is defined for complete rankings (with or without ties): if X or Y contain missing values (NA) the function stops with an error. Partial rankings must be completed by the user before computing the distance, e.g. by tying the missing objects in the last position (the ranking (1, 2, NA, NA) becomes (1, 2, 3, 3)).

Value

If there is only X as input, d = square distance matrix. If there is also Y as input, d = matrix with N rows and n columns.

Author(s)

Antonio D'Ambrosio antdambr@unina.it

References

Kemeny, J. G., & Snell, L. J. (1962). Preference ranking: an axiomatic approach. Mathematical models in the social sciences, 9-23.

See Also

tau_x TauX rank correlation coefficient

iw_kemenyd item-weighted Kemeny distance

Examples

data(Idea)
RevIdea<-6-Idea ##as 5 means "most associated", it is necessary compute the reverse 
#ranking of each rankings to have rank 1 = "most associated" and rank 5 = "least associated"
KD<-kemenyd(RevIdea)
KD2<-kemenyd(RevIdea[1:10,],RevIdea[55,])


Auxiliary function

Description

Define a design matrix to compute Kemeny distance

Usage

kemenydesign(X)

Arguments

X

A N by M data matrix, in which there are N judges and M objects to be judged. Each row is a ranking of the objects represented by the columns.

Details

This function now uses an optimized C++ implementation (kemenydesign_cpp) for improved performance. The original R implementation is preserved for reference.

Value

Design matrix

Author(s)

Antonio D'Ambrosio antdambr@unina.it

References

D'Ambrosio, A. (2008). Tree based methods for data editing and preference rankings. Unpublished PhD Thesis. Universita' degli Studi di Napoli Federico II.

See Also

kemenydesign_cpp


Kemeny design matrix (C++ implementation)

Description

Compute the design matrix for Kemeny distance calculation. This function uses an optimized C++ implementation for better performance.

Usage

kemenydesign_cpp(X)

Arguments

X

A N by M numeric matrix or vector, where each row represents a ranking of M objects. If X is a vector, it will be converted to a single-row matrix.

Details

This is a C++ reimplementation of the original kemenydesign function for improved computational efficiency. The function processes all pairwise comparisons between M objects, generating M*(M-1)/2 binary features that encode the ranking structure.

The optimization provides significant speedup (typically 20-50x) compared to the R implementation, especially for large matrices.

Value

A numeric matrix with N rows and M*(M-1)/2 columns. Each column represents a pairwise comparison between objects:

Author(s)

Antonio D'Ambrosio antdambr@unina.it

References

D'Ambrosio, A. (2008). Tree based methods for data editing and preference rankings. Unpublished PhD Thesis. Universita' degli Studi di Napoli Federico II.

See Also

kemenydesign for the wrapper function

kemenyd for computing Kemeny distance using this design matrix

Examples

# Single ranking
x <- c(1, 3, 2, 4)
kemenydesign_cpp(x)

# Multiple rankings
X <- matrix(c(1,2,3,4,
              4,3,2,1,
              1,1,2,2), nrow=3, byrow=TRUE)
kemenydesign_cpp(X)


Score matrix according Kemeny (1962)

Description

Given a ranking, it computes the score matrix as defined by Emond and Mason (2002)

Usage

kemenyscore(X)

Arguments

X

a ranking (must be a row vector or, better, a matrix with one row and M columns)

Value

the M by M score matrix

Author(s)

Antonio D'Ambrosio antdambr@unina.it

References

Kemeny, J and Snell, L. (1962). Mathematical models in the social sciences.

See Also

scorematrix The score matrix as defined by Emond and Mason (2002)

Examples

Y <- matrix(c(1,3,5,4,2),1,5)
SM<-kemenyscore(Y)
#
Z<-c(1,2,3,2)
SM2<-kemenyscore(Z)


Median Constrained Bucket Order (MCBO)

Description

Find the median ranking constrained to exactly b buckets (tied groups) according to Kemeny's axiomatic approach. This implements the algorithms described in D'Ambrosio et al. (2019) for rank aggregation with fixed bucket constraints.

Usage

mcbo(
  X = NULL,
  nbuckets = NULL,
  wk = NULL,
  ps = TRUE,
  algorithm = "BB",
  itermax = 10,
  np = 10,
  gl = 100,
  ff = 0.4,
  cr = 0.8,
  use_cpp = TRUE,
  maxjudges = Inf,
  cij = NULL,
  nj = NULL,
  bucketsizes = NULL
)

Arguments

X

A N by M data matrix, in which there are N judges and M objects to be judged. Either X or cij must be given. Each row is a ranking of the objects which are represented by the columns. If X contains the rankings observed only once, the argument wk can be used

nbuckets

Integer. The number of buckets (tied groups) the consensus ranking must contain. Must be between 2 and M (where M is the number of objects); with M buckets the solution is a full ranking and the result is the one of consrank(..., full = TRUE) with the same algorithm. Give either nbuckets or bucketsizes, not both

wk

Optional: the frequency of each ranking in the data

ps

Logical. If TRUE, displays progress information on screen. Default TRUE

algorithm

Character string specifying the algorithm to use. One of:

  • "BB" - Branch-and-Bound (exact, default). Best for M <= 15

  • "quick" - Quick algorithm (deterministic heuristic, see Details). Best for 15 < M <= 50

  • "decor" - Differential Evolution (metaheuristic). Best for M > 50

  • "BOLT" - BOLT adapted to the bucket constraint (deterministic heuristic, see Details). Works with a very large number of objects

The name of the algorithm is matched ignoring the case

itermax

Integer. For "quick": maximum number of insertion passes (the algorithm stops earlier when a pass does not improve the solution). For "decor": number of runs of the algorithm. Default 10

np

Integer. Number of population individuals for "decor" algorithm. Default 10

gl

Integer. Generations limit for "decor": maximum number of consecutive generations without improvement. Default 100

ff

Numeric. Scaling rate for mutation in "decor". Must be in [0,1]. Default 0.4

cr

Numeric. Crossover range for "decor". Must be in [0,1]. Default 0.8

use_cpp

Logical. If TRUE (default), use optimized C++ implementations for core functions (combinpmatr, scorematrix, PenaltyBB2, etc.). Ignored with algorithm = "BOLT", which is implemented in C++ only. With algorithm = "quick", the optimal tie partitioning step (taken from BOLT) is always computed in C++.

maxjudges

For "BOLT" only: maximum number of distinct rankings of the judges used as starting solutions, the most frequent first. Default Inf (all of them); 0 uses only the starting solutions computed from the combined input matrix

cij

The combined input matrix (M by M, see combinpmatr), to be given instead of X. With cij, the argument wk is ignored and the rankings of the judges are not used as starting solutions by "BOLT"

nj

The number of judges (the sum of the weights, if any) that produced cij. Required when cij is given: it is used to compute the averaged TauX

bucketsizes

Optional pattern of bucket sizes, one element per bucket: a whole number greater than zero prescribes the size of that bucket, NA leaves it free. If the sizes given do not use all the objects and no NA is present, one free bucket is added at the end, so that with ten objects bucketsizes = c(1, 1, 1) means three buckets of one object and a fourth one with the remaining seven, that is a top-3 list; in the same way, with any number of objects, bucketsizes = rep(1, 10) is the top-10 list, with all the other objects tied in the last position. To fix the number of buckets of a pattern, use NA for the buckets of free size: for instance bucketsizes = c(1, 1, NA, NA, NA) gives five buckets, the first two with one object each. A pattern of ones is a full ranking, a pattern of NAs is the plain constrained bucket order of nbuckets buckets, and a single bucket is the solution with all the objects tied. Available with algorithm = "BOLT" only, which is used by default when bucketsizes is given

Details

The median constrained bucket order problem finds the ranking that minimizes the sum of Kemeny distances to the input rankings, subject to the constraint that the solution must have exactly nbuckets groups of tied items.

This is useful in applications where the output must conform to predetermined categories, such as:

The search space is restricted to Z^{n/b}, which contains

\sum_{b=1}^{n} b! S(n,b)

rankings, where S(n,b) is the Stirling number of the second kind.

Algorithm Selection Guidelines:

The "decor" algorithm is stochastic: it is run several times (controlled by itermax) to avoid local optima. Since version 3.1, a good candidate (the order of the starting point of the branch-and-bound algorithm, cut into exactly nbuckets buckets by the optimal partition described below for "BOLT") is inserted in the initial population, a child with a wrong number of buckets is brought back to nbuckets buckets by the optimal partition of its order (instead of being replaced by a random individual), and the final solution is refined by the optimal partition of its order.

The "quick" algorithm is deterministic (since version 3.1). The starting solution is the order given by the starting point of the branch-and-bound algorithm, cut into exactly nbuckets buckets by the optimal partition described below for "BOLT". Then the insertion passes of the Quick algorithm are repeated until no improvement: a candidate solution with a number of buckets different from nbuckets is brought back to nbuckets buckets by the optimal partition of its order, and each solution is refined in the same way.

The "BOLT" algorithm adapts the procedure of bolt to the bucket constraint. For a fixed order of the objects, the best partition into exactly nbuckets groups of consecutive objects is computed exactly by dynamic programming in O(nbuckets M^2) time. From each starting solution (the same as in bolt), the order is first improved by an insertion local search without ties; then the optimal partition into nbuckets buckets and a local search that keeps the number of buckets (an object alone in its bucket is moved to another position, an object of a larger bucket is moved into another bucket; then two objects of different buckets exchange their buckets) are alternated until no improvement. With bucketsizes, the local search keeps the size of every bucket: an object moves to another bucket and one object crosses each boundary in between, and two objects of different buckets exchange their buckets. The procedure is deterministic: repeated runs return the same solution(s), and the argument itermax is not used.

Value

A list containing the following components:

Consensus The consensus ranking with exactly nbuckets buckets
Tau Averaged TauX rank correlation coefficient
Eltime Elapsed time in seconds

Author(s)

Antonio D'Ambrosio antdambr@unina.it

References

D'Ambrosio, A., Iorio, C., Staiano, M., and Siciliano, R. (2019). Median constrained bucket order rank aggregation. Computational Statistics, 34(2), 787-802. doi:10.1007/s00180-018-0858-z

Romano, M., D'Ambrosio, A., and Conversano, C. A deterministic and scalable heuristic for median ranking detection: tie-aware local search with optimal tie partitioning on the combined input matrix. Manuscript under review.

See Also

consrank for unconstrained consensus ranking

bolt for the BOLT algorithm

combinpmatr for computing the combined input matrix

scorematrix for computing score matrices

tau_x for TauX correlation coefficient

kemenyd for Kemeny distance

stirling2 for Stirling numbers (bucket combinatorics)

Examples

# Deterministic BOLT algorithm
data(EMD)
CR_bolt <- mcbo(EMD[,1:15], nbuckets = 5, wk = EMD[,16], algorithm = "BOLT")
CR_bolt$Tau

## Not run: 
# Simple example with 98 judges ranking 5 items into 3 buckets
data(Idea)
RevIdea <- 6 - Idea  # Reverse ranking
CR <- mcbo(RevIdea, nbuckets = 3, algorithm = "BB")
print(CR$Consensus)
print(CR$Tau)

# Large dataset with Quick algorithm
data(EMD)
CR_quick <- mcbo(EMD[,1:15], nbuckets = 5, wk = EMD[,16], 
                 algorithm = "quick", itermax = 20)

## End(Not run)


Given an ordering, it is transformed to a ranking

Description

From ordering to rank. IMPORTANT: check which symbol denotes tied rankings in the X matrix

Usage

order2rank(X, TO = "{", TC = "}", NAs = "NA")

Arguments

X

A ordering or a matrix containing orderings

TO

symbol indicating the start of a set of items ranked in a tie

TC

symbol indicating the end of a set of items ranked in a tie

NAs

symbol indicating missing ranked object. Can be any symbol in the original ordering matrix

Value

a ranking or a matrix of rankings:

R ranking or matrix of rankings

Author(s)

Antonio D'Ambrosio antdambr@unina.it

Examples

data(APAred)
ord=rank2order(APAred) #transform rankings into orderings
ran=order2rank(ord) #transform the orderings into rankings


Generate partitions of n items constrained into k non empty subsets

Description

Generate all possible partitions of n items constrained into k non empty subsets. It does not generate the universe of rankings constrained into k buckets.

Usage

partitions(n, k = NULL, items = NULL, itemtype = "L")

Arguments

n

a (integer) number denoting the number of items

k

The number of the non-empty subsets. Default value is NULL, in this case all the possible partitions are displayed

items

items: the items to be placed into the ordering matrix. Default are the first c small letters

itemtype

to be used only if items is not set. The default value is "L", namely letters. Any other symbol produces items as the first c integers

Details

If the objects to be ranked is large (>15-20) with some missing, it can take long time to find the solutions. If the searching space is limited to the space of full rankings (also incomplete rankings, but without ties), use the function BBFULL or the functions FASTcons and QuickCons with the option FULL=TRUE.

Value

the ordering matrix (or vector)

Author(s)

Antonio D'Ambrosio antdambr@unina.it

See Also

stirling2 Stirling number of second kind.

rank2order Convert rankings into orderings.

order2rank Convert orderings into ranks.

univranks Generate the universe of rankings given the input partition

Examples

X<-partitions(4,3)
#shows all the ways to partition 4 items (say "a", "b", "c" and "d" into 3 non-empty subets
 #(i.e., into 3 buckets). The Stirling number of the second kind (4,3) indicates that there
 #are 6 ways.
s2<-stirling2(4,3)$S
X2<-order2rank(X) #it transform the ordering into ranking



Plot rankings on a permutation polytope of 3 or 4 objects containing all possible ties

Description

Plot rankings on the permutation polytope, the geometrical space of preference rankings with all the possible ties. The plot is available for 3 or 4 objects.

Usage

polyplot(X = NULL, L = NULL, Wk = NULL, nobj = 3, engine = "auto", size = 1)

Arguments

X

Sample of rankings (matrix or data frame with 3 or 4 columns), either one row for each judge or the distinct rankings returned by tabulaterows() with their frequencies in Wk. If NULL (default), the whole universe of rankings of nobj objects is plotted

L

Labels of the objects (character vector)

Wk

Frequency weights for each ranking (numeric vector). If NULL, each row of X counts 1

nobj

Number of objects, 3 (default) or 4. Used only when X is NULL: if X is given, the number of objects is the number of columns of X

engine

Rendering engine for 4-object plots: "auto", "rgl", or "plotly" (character)

size

Scale factor of the symbols (default 1): values larger than 1 enlarge them

Details

For 3 objects: uses base R graphics (always available) For 4 objects: - engine="auto": tries rgl first, falls back to plotly if unavailable - engine="rgl": requires 'rgl' package (may need XQuartz on macOS) - engine="plotly": requires 'plotly' package (works on all platforms)

A polytope with more than 4 objects cannot be visualized: in that case the function stops with an error.

Each observed ranking is drawn as a circle (3 objects) or a sphere (4 objects) whose area is proportional to its frequency, i.e. the sum of the weights Wk of the rows of X equal to it (rows with ties are matched whatever the coding of the ties, e.g. (1, 3, 3) and (1, 2, 2)); the most frequent ranking has the largest symbol, whose size is controlled by size. If X is NULL, all the points of the polytope are shown. With the plotly engine the frequency is shown when the mouse is over a point.

Value

For 3 objects: invisible NULL (creates base graphics plot) For 4 objects: invisible NULL for rgl, plotly object for plotly engine

Author(s)

Antonio D'Ambrosio antdambr@unina.it and Sonia Amodio sonia.amodio@unina.it

References

Thompson, G. L. (1993). Generalized permutation polytopes and exploratory graphical methods for ranked data. The Annals of Statistics, 1401-1430.

Heiser, W. J., and D'Ambrosio, A. (2013). Clustering and prediction of rankings within a Kemeny distance framework. In Algorithms from and for Nature and Life (pp. 19-31). Springer International Publishing.

See Also

tabulaterows frequency distribution for ranking data.

Examples

polyplot()
data(BU)
polyplot(BU[, 1:3], Wk = BU[, 4])

data(German)
tab <- tabulaterows(German)
if (requireNamespace("rgl", quietly = TRUE)) {
  polyplot(tab$X, Wk = tab$Wk, engine = "rgl")
}



Given a rank, it is transformed to a ordering

Description

From ranking to ordering. IMPORTANT: check which symbol denotes tied rankings in the X matrix

Usage

rank2order(X, items = NULL, TO = "{", TC = "}", itemtype = "L")

Arguments

X

A ordering or a matrix containing orderings

items

items to be placed into the ordering matrix. Default are the

TO

symbol indicating the start of a set of items ranked in a tie

TC

symbol indicating the end of a set of items ranked in a tie

itemtype

to be used only if items=NULL. The default value is "L", namely

Value

a ordering or a matrix of orderings:

out ranking or matrix of rankings

Author(s)

Antonio D'Ambrosio antdambr@unina.it

Examples

data(APAred)
ord<-rank2order(APAred)


Read a PrefLib data file

Description

Read a file of preferences in the format of PrefLib (www.preflib.org) and return the rankings in the format used by the functions of the package: a matrix with one row per distinct ranking and one column per object, and the frequency of each ranking.

Usage

readpreflib(file, unranked = c("last", "na"), expand = FALSE)

Arguments

file

The name of a PrefLib data file, a URL (for example the raw link of a file of the PrefLib-Data repository on GitHub) or a connection

unranked

What to do with the objects that a judge does not rank, in the files of incomplete orders (soi, toi) and of categorical preferences (cat): "last" (default) ties them in the last position, after the ranked objects, as in the files that PrefLib obtains by adding the unranked alternatives at the bottom; "na" leaves them missing (NA)

expand

Logical. If FALSE (default), the rankings are returned once each with their frequencies in wk; if TRUE, each ranking is repeated as many times as its frequency, one row per judge, and wk is NULL

Details

PrefLib files begin with header lines starting with "#" (file name, title, data type, number of alternatives, names of the alternatives, number of voters, ...), followed by one line for each distinct preference, of the form count: preference. The data types are: strict orders complete (soc), strict orders incomplete (soi), orders with ties complete (toc), orders with ties incomplete (toi) and categorical preferences (cat). In the orders, the alternatives are separated by commas from the first to the last, and tied alternatives are grouped in braces: 13: 1, {4, 3}, 2 means that 13 voters put alternative 1 first, 4 and 3 tied in second position and 2 last. In the categorical preferences each line lists the categories in order, from the most preferred one, and an empty category is {}: the categories become the buckets of a ranking with ties, and the empty categories are skipped. Weighted matching files (wmd) do not contain rankings and are not read.

The function checks that the sum of the frequencies is equal to the number of voters declared in the header. With unranked = "last", two different incomplete orders can give the same ranking (for example the order of all the objects but one, and the full order): such rankings are merged and their frequencies are summed. The rankings are in the order in which they first appear in the file.

With unranked = "na" the result can be used with tau_x and combinpmatr, which treat a pair with a missing object as in Emond and Mason (2002); kemenyd and the median ranking functions need complete rankings, as given by unranked = "last".

Value

A list containing the following components:

X the rankings: a matrix with one row per distinct ranking (one per judge with expand = TRUE) and one column per object, named with the names of the alternatives; the entries are the positions of the objects (1 = first position, objects tied in the same bucket have the same position, the positions of each ranking are 1, 2, 3, ... without gaps)
wk the frequency of each ranking (NULL with expand = TRUE)
datatype the data type of the file: "soc", "soi", "toc", "toi" or "cat"
categories the names of the categories, in order (cat files only, NULL otherwise)
header the metadata of the file: a named list with the values of the header lines

Author(s)

Antonio D'Ambrosio antdambr@unina.it

References

Mattei, N., and Walsh, T. (2013). PrefLib: A library for preferences http://www.preflib.org. In Algorithmic Decision Theory (ADT 2013), Lecture Notes in Computer Science, vol. 8176, 259-270. Springer.

Emond, E. J., and Mason, D. W. (2002). A new rank correlation coefficient with application to the consensus ranking problem. Journal of Multi-Criteria Decision Analysis, 11(1), 17-28.

See Also

consrank, mcbo and consranktopk for the median ranking of the data

tabulaterows for the frequencies of the rankings in a data matrix

Examples

# a small file in the PrefLib format: 4 objects, orders with ties
tf <- tempfile(fileext = ".toi")
writeLines(c(
  "# FILE NAME: example.toi",
  "# TITLE: A small example",
  "# DATA TYPE: toi",
  "# NUMBER ALTERNATIVES: 4",
  "# ALTERNATIVE NAME 1: a",
  "# ALTERNATIVE NAME 2: b",
  "# ALTERNATIVE NAME 3: c",
  "# ALTERNATIVE NAME 4: d",
  "# NUMBER VOTERS: 10",
  "# NUMBER UNIQUE ORDERS: 3",
  "5: 1, {4, 3}, 2",
  "3: 2, 1",
  "2: 3, 1, 2, 4"), tf)
P <- readpreflib(tf)
P$X
P$wk
CR <- consrank(P$X, wk = P$wk, algorithm = "BB")
CR$Consensus
# the objects not ranked by a judge left missing
readpreflib(tf, unranked = "na")$X
## Not run: 
# a file of the PrefLib-Data repository: the sushi data (top-10 of 100 sushi)
P <- readpreflib(paste0("https://raw.githubusercontent.com/PrefLib/",
  "PrefLib-Data/main/datasets/00014%20-%20sushi/00014-00000002.soi"))
dim(P$X)

## End(Not run)


Given a vector (or a matrix), returns an ordered vector (or a matrix with ordered vectors)

Description

Given a ranking of M objects (or a matrix with M columns), it reduces it in "natural" form (i.e., with integers from 1 to M)

Usage

reordering(X)

Arguments

X

a ranking, or a ranking data matrix

Value

a ranking in natural form

Author(s)

Antonio D'Ambrosio antdambr@unina.it


Score matrix according Emond and Mason (2002)

Description

Given a ranking, it computes the score matrix as defined by Emond and Mason (2002)

Usage

scorematrix(X, use_cpp = TRUE)

Arguments

X

a ranking (must be a row vector or, better, a matrix with one row and M columns)

use_cpp

Logical. If TRUE (default), uses C++ implementation for faster computation. If FALSE, uses the R implementation.

Value

the M by M score matrix

Author(s)

Antonio D'Ambrosio antdambr@unina.it

References

Emond, E. J., and Mason, D. W. (2002). A new rank correlation coefficient with application to the consensus ranking problem. Journal of Multi-Criteria Decision Analysis, 11(1), 17-28.

See Also

combinpmatr The combined inut matrix

Examples

Y <- matrix(c(1,3,5,4,2),1,5)
SM<-scorematrix(Y)
#
Z<-c(1,2,4,3)
SM2<-scorematrix(Z)


sports data

Description

130 students at the University of Illinois ranked seven sports according to their preference (Baseball, Football, Basketball, Tennis, Cycling, Swimming, Jogging).

Usage

data(sports)

Source

Marden, J. I. (1996). Analyzing and modeling rank data. CRC Press.

Examples

data(sports)

Stirling numbers of the second kind

Description

Denote the number of ways to partition a set of n objects into k non-empty subsets

Usage

stirling2(n, k)

Arguments

n

(integer): the number of the objects

k

(integer <=n): the number of the non-empty subsets (buckets)

Value

a "list" containing the following components:

S the stirling number of the second kind
SM a matrix showing, for each k (on the columns) in how many ways the n objects (on the rows) can be partitioned

Author(s)

Antonio D'Ambrosio antdambr@unina.it

References

Comtet, L. (1974). Advanced Combinatorics: The art of finite and infinite expansions. D. Reidel, Dordrecth, The Netherlands.

Examples

parts<-stirling2(4,2)


Frequency distribution of a sample of rankings

Description

Given a sample of preference rankings, it compute the frequency associated to each ranking

Usage

tabulaterows(X, miss = FALSE)

Arguments

X

a N by M data matrix containing N judges judging M objects

miss

TRUE if there are missing data (either partial or incomplete rankings): default: FALSE

Value

a "list" containing the following components:

X the unique rankings
Wk the frequency associated to each ranking
tabfreq frequency table

Author(s)

Antonio D'Ambrosio antdambr@unina.it

Examples

data(Idea)
TR<-tabulaterows(Idea)
FR<-TR$Wk/sum(TR$Wk)
RF<-cbind(TR$X,FR)
colnames(RF)<-c(colnames(Idea),"fi")
#compute modal ranking
maxfreq<-which(RF[,6]==max(RF[,6]))
rank2order(RF[maxfreq,1:5],items=colnames(Idea))
#
data(APAred)
TR<-tabulaterows(APAred)
#
data(APAFULL)
TR<-tabulaterows(APAFULL)
CR1<-consrank(TR$X,wk=TR$Wk)
CR2<-consrank(TR$X,wk=TR$Wk,algorithm="fast",itermax=15)
CR3<-consrank(TR$X,wk=TR$Wk,algorithm="quick")


TauX (tau exstension) rank correlation coefficient

Description

Tau exstension is a new rank correlation coefficient defined by Emond and Mason (2002)

Usage

tau_x(X, Y = NULL)

Tau_X(X, Y = NULL)

Arguments

X

a M by N data matrix, in which there are N judges and M objects to be judged. Each row is a ranking of the objects which are represented by the columns. If there is only X as input, the output is a square matrix containing the Tau_X rcc.

Y

A row vector, or a n by M data matrix in which there are n judges and the same M objects as X to be judged.

Details

With complete rankings TauX is a linear function of the Kemeny distance. The rankings can also be partial (missing objects coded NA): as in Emond and Mason (2002), the score of a pair of objects with a missing object is 0, so that the pair does not contribute to the coefficient.

Value

Tau_x rank correlation coefficient

Author(s)

Antonio D'Ambrosio antdambr@unina.it

References

Emond, E. J., and Mason, D. W. (2002). A new rank correlation coefficient with application to the consensus ranking problem. Journal of Multi-Criteria Decision Analysis, 11(1), 17-28.

See Also

kemenyd Kemeny distance

iw_tau_x item-weighted tau_x rank correlation coefficient

Examples

data(BU)
RD<-BU[,1:3]
Tau<-tau_x(RD)
Tau1_3<-tau_x(RD[1,],RD[3,])


Generate the universe of rankings

Description

Generate the universe of rankings given the input partition

Usage

univranks(X, k = NULL, ordering = TRUE)

Arguments

X

A number (the number of items), or a single ranking (a numeric vector, or a numeric matrix with one row), or an ordering. With a number, the universe of the rankings of X items is generated (constrained into k buckets if k is given); with a ranking or an ordering, the rankings with the same groups of tied items, i.e., all the orders of its buckets

k

Optional: the number of the non-empty subsets. It has to be used only if X is anumber. The default value is NULL, In this case the universe of rankings with n=X items are computed

ordering

The universe of rankings must be returned as orderings (default) or rankings?

Details

The function should be used with small numbers because it can generate a large number of permutations. The use of X greater than 9, of X matrices with more than 9 columns as input is not reccomended.

Value

a "list" containing the following components:

Runiv The universe of rankings
Cuniv A list containing:
R The universe of rankings in terms of rankings;
Parts for each ranking in input the produced rankings
Univinbucket the universe of rankings within each bucket

Author(s)

Antonio D'Ambrosio antdambr@unina.it

See Also

stirling2 Stirling number of second kind.

rank2order Convert rankings into orderings.

order2rank Convert orderings into ranks.

partitions Generate partitions of n items constrained into k non empty subsets.

Examples

S2<-stirling2(4,4)$SM[4,] #indicates in how many ways 4 objects
                         #can be placed, respectively, into 1, 2,
                         #3 or 4 non-empty subsets.
CardConstr<-factorial(c(1,2,3,4))*S2  #the cardinality of rankings 
                                     #constrained into 1, 2, 3 and 4
                                     #buckets
Card<-sum(CardConstr)  #Cardinality of the universe of rankings with 4
                      #objects                                                              
U<-univranks(4)$Runiv #the universe of rankings with four objects
                     # we know that the universe counts 75 
                     #different rankings
Uk<-univranks(4,2)$Runiv    #the universe of rankings of four objects 
                           #constrained into k=2 buckets, we know they are 14
Up<-univranks(c(1,4,3,1))$Runiv  #the universe of rankings with 4 objects
                                #for which the first and the fourth item
                                #are tied