diff --git a/DESCRIPTION b/DESCRIPTION index b86e083..3e0952c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: bayesAB Type: Package Title: Fast Bayesian Methods for AB Testing -Version: 1.1.0 +Version: 1.1.1 Date: 2017-09-25 Authors@R: person("Frank", "Portman", email = "frank1214@gmail.com", role = c("aut", "cre")) Description: A suite of functions that allow the user to analyze A/B test @@ -10,7 +10,7 @@ Description: A suite of functions that allow the user to analyze A/B test License: MIT + file LICENSE Imports: Rcpp (>= 0.12.4), - ggplot2, + ggplot2 (>= 3.0.0), methods LinkingTo: Rcpp RoxygenNote: 6.0.1 diff --git a/NAMESPACE b/NAMESPACE index f4af739..05b0142 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,6 +6,7 @@ S3method("-",bayesTest) S3method("/",bayesTest) S3method(c,bayesTest) S3method(plot,bayesTest) +S3method(plot,bayesTestClosed) S3method(print,bayesBandit) S3method(print,bayesTest) S3method(print,bayesTestClosed) diff --git a/R/combine.R b/R/combine.R index d0edd1f..85f38c9 100644 --- a/R/combine.R +++ b/R/combine.R @@ -124,6 +124,7 @@ combine <- function(bT1, bT2, f = `+`, params, newName) { grab <- function(bT, posterior) { if(! posterior %in% names(bT$posteriors)) stop("That posterior doesn't exist in the input bayesTest.") result <- list( + prior = bT$prior, inputs = bT$inputs, posteriors = bT$posteriors[posterior] ) diff --git a/R/generics.R b/R/generics.R index a7b1f94..5939100 100644 --- a/R/generics.R +++ b/R/generics.R @@ -40,7 +40,6 @@ plot.bayesTest <- function(x, if(length(x$posteriors) != length(percentLift)) stop("Must supply a 'percentLift' for every parameter with a posterior distribution.") if(!any(priors, posteriors, samples)) stop("Must specifiy at least one plot to make.") - if(isClosed(x$inputs$distribution)) stop("Can't plot 'closed form' bayesTest.") pri <- post <- samp <- list() # Initialize empty list @@ -60,6 +59,11 @@ plot.bayesTest <- function(x, } +#' @export +plot.bayesTestClosed <- function(x, ...) { + stop("Can't plot 'closed form' bayesTest.") +} + #' @export print.plotBayesTest <- function(x, ...) { @@ -137,7 +141,7 @@ summary.bayesTest <- function(object, if(length(object$posteriors) != length(percentLift)) stop("Must supply a 'percentLift' for every parameter with a posterior distribution.") if(length(object$posteriors) != length(credInt)) stop("Must supply a 'credInt' for every parameter with a posterior distribution.") - if(any(credInt <= 0) | any(credInt >= 1)) stop("Credible interval width ust be in (0, 1).") + if(any(credInt <= 0) | any(credInt >= 1)) stop("Credible interval width must be in (0, 1).") lifts <- lapply(object$posteriors, function(x) do.call(getLift, unname(x))) posteriorExpectedLoss <- lapply(object$posteriors, function(x) do.call(getPostError, unname(x))) diff --git a/R/makePlots.R b/R/makePlots.R index a551488..d2b477f 100644 --- a/R/makePlots.R +++ b/R/makePlots.R @@ -37,7 +37,7 @@ samplePlot <- function(A, B, name, percentLift, f = function(a, b) (a-b)/b) { ggplot2::geom_vline(xintercept = cutoff) + ggplot2::xlim(inner[1], inner[2]) - m <- max(ggplot2::ggplot_build(p)$layout$panel_ranges[[1]]$y.range) + m <- max(ggplot2::ggplot_build(p)$layout$panel_params[[1]]$y.range) xpos <- mean(diff$diff[diff$under == F & diff$inside == T]) if(is.nan(xpos)) xpos <- mean(diff$diff[diff$under == T & diff$inside == T]) diff --git a/tests/testthat/test-combine.R b/tests/testthat/test-combine.R index aa2adc2..2e5c17a 100644 --- a/tests/testthat/test-combine.R +++ b/tests/testthat/test-combine.R @@ -35,6 +35,10 @@ test_that("Failures based on input types", { expect_warning(combine(AB1, AB4, f = `*`, params = c('Probability', 'Mu'), newName = 'Expectation'), "n_samples not equal. Make sure `f` handles recycling appropriately.", fixed = TRUE) + expect_error(grab(AB2, 'MU'), "That posterior doesn't exist in the input bayesTest.", fixed = TRUE) + + expect_error(rename(AB2, 'lol'), 'Can only rename bayesTests with one posterior.', fixed = TRUE) + }) test_that("Success", { @@ -58,5 +62,7 @@ test_that("Success", { expect_identical(successfulTestDiv, AB1 / grab(AB2, 'Mu')) expect_identical(successfulTestMulRename, successfulTestMulRename2) + + expect_equal(3, length(grab(AB2, 'Mu'))) }) diff --git a/tests/testthat/test-generics.R b/tests/testthat/test-generics.R index e573635..7e5b931 100644 --- a/tests/testthat/test-generics.R +++ b/tests/testthat/test-generics.R @@ -30,6 +30,10 @@ test_that("Failures based on inputs", { expect_error(c(x, AB4), "Unable to concatenate. Mismatches in (A_data, B_data, priors, distribution). All inputs must be the same (except n_samples).", fixed = TRUE) + expect_error(plot(AB3), "Can't plot 'closed form' bayesTest.", fixed = TRUE) + + expect_error(summary(x, credInt = c(5, 5, 5, 5)), "Credible interval width must be in (0, 1).", fixed = TRUE) + }) test_that("Success", {