Skip to content

Commit

Permalink
rebrand model to player, split to round (#11) and print for epp class (
Browse files Browse the repository at this point in the history
  • Loading branch information
woznicak committed Jul 28, 2021
1 parent c1681ea commit 91e40a2
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 62 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

S3method(print,epp_results)
S3method(print,epp_test)
export(calculate_actual_wins)
export(calculate_epp)
Expand Down
109 changes: 63 additions & 46 deletions R/calculate_elo.R

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions R/plot_wins_ratio.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ plot_wins_ratio <- function(epp, random_sample = NULL, random_state = NULL){
set.seed(random_state)
}

sample_player <- sample(epp_score$model, size = floor(random_sample * length(epp_score$model)))
sample_player <- sample(epp_score$player, size = floor(random_sample * length(epp_score$player)))
actual_score <- actual_score[actual_score$winner %in% sample_player & actual_score$loser %in% sample_player,]
epp_score <- epp_score[epp_score$model %in% sample_player, ]
epp_score <- epp_score[epp_score$player %in% sample_player, ]
}

actual_score[["ratio"]] <- actual_score[["wins"]] / actual_score[["match"]]
actual_score <- merge(actual_score, epp_score, by.x ="winner", by.y = "model")
actual_score <- merge(actual_score, epp_score, by.x ="winner", by.y = "player")
names(actual_score)[names(actual_score)=='epp'] <- "epp_winner"
actual_score <- merge(actual_score, epp_score, by.x ="loser", by.y = "model")
actual_score <- merge(actual_score, epp_score, by.x ="loser", by.y = "player")
names(actual_score)[names(actual_score)=='epp'] <- "epp_loser"

actual_score[['pred_ratio']] <- exp(actual_score[["epp_winner"]] - actual_score[['epp_loser']])/(1+exp(actual_score[["epp_winner"]] - actual_score[['epp_loser']]))
Expand Down
6 changes: 3 additions & 3 deletions R/wald_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
test_players_diff <- function(epp, player1, player2){
if(epp$estimation != "glm") stop("Test requires estimated covariance matrix. Use `estimation='glm'` in function `caluclate_epp()`.")
coefs <- epp$epp_summary$epp
players <- epp$epp_summary$model
players <- epp$epp_summary$player
covar <- epp$covariance_epp
n <- length(coefs)

Expand All @@ -43,14 +43,14 @@ test_players_diff <- function(epp, player1, player2){

#' @title Printing Summary of the EPP Test
#'
#' @param x epp_results. The result of a function \code{\link{calculate_epp}}.
#' @param x epp_test. The result of a function \code{\link{test_players_diff}}.
#' @param ... other parameters
#'
#' @return No return value, prints the structure of the object
#'
#' @export
print.epp_test <- function(x, ...) {
cat("Wald-based test for the difference between ", x$player1, " and ", x$player1, ".\n", sep = "")
cat("Wald-based test for the difference between ", x$player1, " and ", x$player2, ".\n", sep = "")
cat("Test statistic: ", x$statistic, "\n")
cat("p-value: ", x$pval, "\n")
}
6 changes: 3 additions & 3 deletions man/calculate_actual_wins.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/calculate_epp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/print.epp_results.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/print.epp_test.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test_calculations.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ context("Testing functions calculating scores")
data("auc_scores")
auc_scores_short <- auc_scores[1:100,]
test_that("Is epp calculated?", {
expect_is(calculate_epp(auc_scores_short, decreasing_metric = TRUE, compare_in_split = TRUE),
expect_is(calculate_epp(auc_scores_short, decreasing_metric = TRUE, compare_in_round = TRUE),
"epp_results")
expect_is(calculate_epp(auc_scores_short, decreasing_metric = FALSE, compare_in_split = FALSE, keep_data = FALSE),
expect_is(calculate_epp(auc_scores_short, decreasing_metric = FALSE, compare_in_round = FALSE, keep_data = FALSE),
"epp_results")
})

0 comments on commit 91e40a2

Please sign in to comment.