Skip to content

Commit

Permalink
Merge pull request #238 from kkholst/master
Browse files Browse the repository at this point in the history
Moved BradleyTerry2 to Suggested packages.
  • Loading branch information
topepo committed Sep 8, 2015
2 parents f2cfcca + 966cc40 commit b5060d4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pkg/caret/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ URL: https://github.com/topepo/caret/
BugReports: https://github.com/topepo/caret/issues
Imports:
car,
reshape2,
foreach,
methods,
plyr,
nlme,
BradleyTerry2,
reshape2,
stats,
stats4,
utils,
grDevices
Suggests:
BradleyTerry2,
e1071,
earth (>= 2.2-3),
fastICA,
Expand Down
2 changes: 1 addition & 1 deletion pkg/caret/NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
useDynLib(caret)
import(foreach, methods, plyr, reshape2, ggplot2, lattice, nlme, BradleyTerry2)
import(foreach, methods, plyr, reshape2, ggplot2, lattice, nlme)
importFrom(car, powerTransform, yjPower)
importFrom(grDevices, extendrange)
importFrom(stats, .checkMFClasses, .getXlevels, aggregate, anova,
Expand Down
14 changes: 8 additions & 6 deletions pkg/caret/R/adaptive.R
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ get_id <- function(x, param) {
}

bt_eval <- function(rs, metric, maximize, alpha = 0.05) {
if (!requireNamespace("BradleyTerry2")) stop("BradleyTerry2 package missing")
se_thresh <- 100
constant <- qnorm(1 - alpha)
rs <- rs[order(rs$Resample, rs$model_id),]
Expand All @@ -799,12 +800,12 @@ bt_eval <- function(rs, metric, maximize, alpha = 0.05) {
best_mod <- if(maximize)
best_mod$model_id[which.max(best_mod$V1)] else
best_mod$model_id[which.min(best_mod$V1)]
btModel <- BTm(cbind(win1, win2), player1, player2, data = scores, refcat = best_mod)
upperBound <- BTabilities(btModel)[,1] + constant*BTabilities(btModel)[,2]
if(any(BTabilities(btModel)[,2] > se_thresh)) {
btModel <- BradleyTerry2::BTm(cbind(win1, win2), player1, player2, data = scores, refcat = best_mod)
upperBound <- BradleyTerry2::BTabilities(btModel)[,1] + constant*BradleyTerry2::BTabilities(btModel)[,2]
if(any(BradleyTerry2::BTabilities(btModel)[,2] > se_thresh)) {
## These players either are uniformly dominated (='dom') or dominating
dom1 <- BTabilities(btModel)[,2] > se_thresh
dom2 <- if(maximize) BTabilities(btModel)[,1] <= 0 else BTabilities(btModel)[,1] >= 0
dom1 <- BradleyTerry2::BTabilities(btModel)[,2] > se_thresh
dom2 <- if(maximize) BradleyTerry2::BTabilities(btModel)[,1] <= 0 else BradleyTerry2::BTabilities(btModel)[,1] >= 0
dom <- dom1 & dom2
} else dom <- rep(FALSE, length(upperBound))
bound <- upperBound >= 0
Expand All @@ -814,14 +815,15 @@ bt_eval <- function(rs, metric, maximize, alpha = 0.05) {

get_scores <- function(x, maximize = NULL, metric = NULL)
{
if (!requireNamespace("BradleyTerry2")) stop("BradleyTerry2 package missing")
delta <- outer(x[,metric], x[,metric], "-")
tied <- ifelse(delta == 0, 1, 0)*.5
diag(tied) <- 0
binary <- if(maximize) ifelse(delta > 0, 1, 0) else ifelse(delta > 0, 0, 1)
binary <- binary + tied
diag(binary) <- 0
rownames(binary) <- colnames(binary) <- x$model_id
countsToBinomial(as.table(binary))
BradleyTerry2::countsToBinomial(as.table(binary))
}

skunked <- function(scores, verbose = TRUE) {
Expand Down

0 comments on commit b5060d4

Please sign in to comment.