Skip to content

Commit

Permalink
Ggplot fix (#29)
Browse files Browse the repository at this point in the history
* Bump to new ggplot version to break tests

* Make sure grab returns the correct data structure

* Fix for ggplot 3.0

* typo

* Bump up version

* Other changes
  • Loading branch information
FrankPortman committed Jul 10, 2018
1 parent 36c68c7 commit 3aa088d
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions 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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions R/combine.R
Expand Up @@ -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]
)
Expand Down
8 changes: 6 additions & 2 deletions R/generics.R
Expand Up @@ -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

Expand All @@ -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, ...) {

Expand Down Expand Up @@ -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)))
Expand Down
2 changes: 1 addition & 1 deletion R/makePlots.R
Expand Up @@ -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])
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-combine.R
Expand Up @@ -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", {
Expand All @@ -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')))

})
4 changes: 4 additions & 0 deletions tests/testthat/test-generics.R
Expand Up @@ -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", {
Expand Down

0 comments on commit 3aa088d

Please sign in to comment.