Skip to content

Commit

Permalink
more target_value interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMount committed Jan 26, 2019
1 parent b2c7e2c commit e945957
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 18 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# WVPlots 1.0.8 2019-01-26

* Add baseline in lift curve plot.
* Truth targets.

# WVPlots 1.0.7 2018-12-17

Expand Down
20 changes: 15 additions & 5 deletions R/DoubleDensity.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#' @param truthVar name of the dependent (output or result to be modeled) column in frame
#' @param title title to place on plot
#' @param ... no unnamed argument, added to force named binding of later arguments.
#' @param truth_target if not NULL compare to this scalar value.
#' @examples
#'
#' mpg = ggplot2::mpg
Expand All @@ -37,16 +38,25 @@
#' WVPlots::DoubleDensityPlot(frm, "score", "rare", title="Example double density plot")
#'
#' @export
DoubleDensityPlot <- function(frame, xvar, truthVar, title,...) {
frame <- as.data.frame(frame)
DoubleDensityPlot <- function(frame, xvar, truthVar, title,
...,
truth_target = NULL) {
check_frame_args_list(...,
frame = frame,
name_var_list = list(xvar = xvar, truthVar = truthVar),
title = title,
funname = "WVPlots::DoubleDensityPlot")
df <- data.frame(x=as.numeric(frame[[xvar]]),
y=as.character(frame[[truthVar]]),
stringsAsFactors=FALSE)
if(is.null(truth_target)) {
df <- data.frame(x=as.numeric(frame[[xvar]]),
y=as.character(frame[[truthVar]]),
stringsAsFactors=FALSE)
} else {
df <- data.frame(x=as.numeric(frame[[xvar]]),
y=ifelse(frame[[truthVar]]==truth_target,
truth_target,
paste0("!", truth_target)),
stringsAsFactors=FALSE)
}
pf <- wv_gapply(df,'y',
partitionMethod='split',
function(sf) {
Expand Down
12 changes: 9 additions & 3 deletions R/GainCurve.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ thin_frame_by_orders <- function(d, cols, groupcol, large_count) {
#' @param title title to place on plot
#' @param ... no unnamed argument, added to force named binding of later arguments.
#' @param estimate_sig logical, if TRUE compute significance.
#' @param large_count numeric, upper bound target for number of plotting points
#' @param large_count numeric, upper bound target for number of plotting points.
#' @param truth_target if not NULL compare to this scalar value.
#' @examples
#'
#' set.seed(34903490)
Expand All @@ -118,7 +119,8 @@ thin_frame_by_orders <- function(d, cols, groupcol, large_count) {
GainCurvePlot = function(frame, xvar, truthVar, title,
...,
estimate_sig = FALSE,
large_count = 1000) {
large_count = 1000,
truth_target = NULL) {
frame <- check_frame_args_list(...,
frame = frame,
name_var_list = list(xvar = xvar, truthVar = truthVar),
Expand All @@ -129,7 +131,11 @@ GainCurvePlot = function(frame, xvar, truthVar, title,
NULL # used as a symbol, declare not an unbound variable
sort_criterion <-
NULL # used as a symbol, declare not an unbound variable
truthcol <- as.numeric(frame[[truthVar]])
if(!is.null(truth_target)) {
truthcol <- as.numeric(frame[[truthVar]]==truth_target)
} else {
truthcol <- as.numeric(frame[[truthVar]])
}
predcol <- as.numeric(frame[[xvar]])
# data frame of pred and truth, sorted in order of the predictions
d = data.frame(predcol = predcol, truthcol = truthcol)
Expand Down
10 changes: 8 additions & 2 deletions R/LiftCurve.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#' @param ... no unnamed argument, added to force named binding of later arguments.
#' @param large_count numeric, upper bound target for number of plotting points
#' @param include_wizard logical, if TRUE plot the ideal or wizard plot.
#' @param truth_target if not NULL compare to this scalar value.
#' @examples
#'
#' set.seed(34903490)
Expand All @@ -38,14 +39,19 @@
LiftCurvePlot = function(frame, xvar, truthVar, title,
...,
large_count = 1000,
include_wizard = TRUE) {
include_wizard = TRUE,
truth_target = NULL) {
frame <- check_frame_args_list(...,
frame = frame,
name_var_list = list(xvar = xvar, truthVar = truthVar),
title = title,
funname = "WVPlots::LiftCurvePlot")
pct_outcome <- pctpop <- sort_criterion <- NULL # mark as not unbound variables
truthcol <- as.numeric(frame[[truthVar]])
if(!is.null(truth_target)) {
truthcol <- as.numeric(frame[[truthVar]]==truth_target)
} else {
truthcol <- as.numeric(frame[[truthVar]])
}
predcol <- as.numeric(frame[[xvar]])
# data frame of pred and truth, sorted in order of the predictions
d = data.frame(predcol = predcol, truthcol = truthcol)
Expand Down
1 change: 1 addition & 0 deletions docs/news/index.html

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

6 changes: 5 additions & 1 deletion docs/reference/DoubleDensityPlot.html

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

8 changes: 6 additions & 2 deletions docs/reference/GainCurvePlot.html

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

6 changes: 5 additions & 1 deletion docs/reference/LiftCurvePlot.html

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

4 changes: 3 additions & 1 deletion man/DoubleDensityPlot.Rd

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

6 changes: 4 additions & 2 deletions man/GainCurvePlot.Rd

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

4 changes: 3 additions & 1 deletion man/LiftCurvePlot.Rd

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

0 comments on commit e945957

Please sign in to comment.