library(ROCR)
gain.chart <- function(n) {
score <- runif(n)
y <- (runif(n) < score)
plot(performance(prediction(score, y), "tpr", "rpp"),
lwd = 7, main = paste("N =", n))
lines(ecdf((rank(-score)[y == T]) / n),
verticals = T, do.points = F, col = "red", lwd = 3)
}
set.seed(1)
par(mfrow = c(1, 2))
gain.chart(10)
gain.chart(10000)
The code plots the following gain charts:
For small samples the two methods do not produce identical plots as ecdf returns step function and ROCR plot provides linear interpolation at jumps.

No comments:
Post a Comment