Learn R Programming

votesys (version 0.1.1)

star_rating: User Preference Aggregation

Description

The function uses a simple method to calculate the aggregation scores of user ratings, which is described in Langville, A. and Meyer, C. (2012: 128). Input data can be stored in a sparse matrix. Suppose there are 100 films and users are required to assign scores. However, each user only watched several of them. Thus, when comparing two films A and B, the method only takes account ratings from those who watched both A and B.

Usage

star_rating(x, show_name = FALSE, check_na = TRUE)

Arguments

x

a numeric matrix, or, dgCMatrix and dgeMatrix matrix created with the Matrix package. 0 in the data means no score is given; and valid score values should all be larger than 0. The function will do NOTHING to check the validity. Besides, NA also means no score is given. If your data has NA, set check_na to TRUE so as to convert NA to 0.

show_name

the default is FALSE, that is to say, the function does not store and show candidate names in the result and you cannot see them. However, you can set it to TRUE.

check_na

if it is TRUE, the function will check NAs and convert them to 0s. If NAs do exist and check_na is FALSE, error will be raised.

Value

a list object.

  • (1) call the function call.

  • (2) method the counting method.

  • (3) candidate candidate names. If show_name is FALSE, this will be NULL.

  • (4) candidate_num number of candidate.

  • (5) ballot_num number of ballots in x.

  • (6) valid_ballot_num number of ballots that are used to compute the result.

  • (7) winner the winner. If show_name is FALSE, this only shows the number in 1: ncol(x).

  • (8) winner_score the winner's score, which is the highest score.

  • (9) other_info scores of all the candidates.

References

  • Langville, A. and Meyer, C. 2012. Who's #1? The Science of Rating and Ranking. Princeton University Press, p. 128.

Examples

Run this code
# NOT RUN {
# Example from Langville and Meyer, 2012: 128. 
# 4 films are rated by 10 users; 0 means no score.
raw <- c(4, 3, 1, 2, 0, 2, 0, 3, 0, 2, 2, 1, 0, 4, 3, 3, 4, 
    1, 3, 0, 2, 0, 2, 2, 2, 0, 1, 1, 2, 2, 0, 2, 0, 0, 5, 0, 3, 
    0, 5, 4
)
m <- matrix(raw, ncol = 4)
colnames(m) <- paste("film", 1: 4, sep = "")
y <- star_rating(m, show_name = TRUE) # winner is film4
# }

Run the code above in your browser using DataLab