Learn R Programming

ConsRank (version 3.0)

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)

Value

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

  • 1: first object ranked lower (better) than second

  • -1: first object ranked higher (worse) than second

  • 0: objects tied

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.

Author

Antonio D'Ambrosio antdambr@unina.it

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.

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

Run this code
# 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)

Run the code above in your browser using DataLab