create_ranking takes a vector or matrix of ordered items orderings and returns a corresponding vector or matrix of ranked items. create_ordering takes a vector or matrix of rankings rankings and returns a corresponding vector or matrix of ordered items.
orderings: A vector or matrix of ordered items. If a matrix, it should be of size N times n, where N is the number of samples and n is the number of items.
rankings: A vector or matrix of ranked items. If a matrix, it should be N times n, where N is the number of samples and n is the number of items.
Returns
A vector or matrix of rankings. Missing orderings coded as NA are propagated into corresponding missing ranks and vice versa.
Examples
# A vector of ordered items.orderings <- c(5,1,2,4,3)# Get ranksrankings <- create_ranking(orderings)# rankings is c(2, 3, 5, 4, 1)# Finally we convert it backed to an ordering.orderings_2 <- create_ordering(rankings)# Confirm that we get back what we hadall.equal(orderings, orderings_2)# Next, we have a matrix with N = 19 samples# and n = 4 itemsset.seed(21)N <-10n <-4orderings <- t(replicate(N, sample.int(n)))# Convert the ordering to rankingrankings <- create_ranking(orderings)# Now we try to convert it back to an ordering.orderings_2 <- create_ordering(rankings)# Confirm that we get back what we hadall.equal(orderings, orderings_2)
See Also
Other rank functions: compute_expected_distance(), compute_observation_frequency(), compute_rank_distance(), get_mallows_loglik(), sample_mallows()