Skip to contents

Convert a set of preferences to an adjacency matrix summarising wins and losses between pairs of items

Usage

adjacency(object, weights = NULL, ...)

Arguments

object

a preferences object, or an object that can be coerced by as.preferences.

weights

an optional vector of weights for the preferences.

...

further arguments passed to/from methods.

Value

An \(N\) by \(N\) matrix, where \(N\) is the number of items.

Details

For a preferences object with \(N\) items, the adjacency matrix is an \(N\) by \(N\) matrix, with element \((i, j)\) being the number of times item \(i\) wins over item \(j\). For example, in the preferences {1} > {3, 4} > {2}, item 1 wins over items 2, 3, and 4, while items 3 and 4 win over item 2.

If weights is specified, the values in the adjacency matrix are the weighted counts.

Examples

X <- matrix(c(
  2, 1, 2, 1, 2,
  3, 2, 0, 0, 1,
  1, 0, 2, 2, 3
), nrow = 3, byrow = TRUE)
X <- as.preferences(X, format = "ranking", item_names = LETTERS[1:5])
adjacency(X)
#>   A B C D E
#> A 0 0 1 1 1
#> B 3 0 2 1 2
#> C 1 1 0 0 2
#> D 2 1 1 0 3
#> E 1 1 0 0 0
#> attr(,"class")
#> [1] "adjacency" "matrix"   

adjacency(X, weights = c(1, 1, 2))
#>   A B C D E
#> A 0 0 2 2 2
#> B 4 0 3 2 3
#> C 1 1 0 0 3
#> D 2 1 1 0 4
#> E 1 1 0 0 0
#> attr(,"class")
#> [1] "adjacency" "matrix"