Convert a set of preferences to an adjacency matrix summarising wins and losses between pairs of items.
Arguments
- x
A
preferences
object or atibble
with apreferences
-typed column.- preferences_col
<
tidy-select
> Whenx
is atibble
, the column containing the preferences.- frequency_col
<
tidy-select
> Whenx
is atibble
, the column containing the frequency of the preferences. If not provided, each row is considered to be observed a single time.- ...
Currently unused.
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 <- tibble::tribble(
~voter_id, ~species, ~food, ~ranking,
1, "Rabbit", "Apple", 1,
1, "Rabbit", "Banana", 2,
1, "Rabbit", "Carrot", 3,
2, "Monkey", "Banana", 1,
2, "Monkey", "Apple", 2,
2, "Monkey", "Carrot", 3
) |>
long_preferences(
food_preference,
id_cols = voter_id,
item_col = food,
rank_col = ranking
) |>
dplyr::pull(food_preference) |>
adjacency()