Skip to content

Commit

Permalink
add test for tweedie
Browse files Browse the repository at this point in the history
  • Loading branch information
actuaryzhang committed Jan 28, 2017
1 parent 654551b commit 852dd6e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion R/pkg/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Suggests:
rmarkdown,
testthat,
e1071,
survival
survival,
statmod
Collate:
'schema.R'
'generics.R'
Expand Down
4 changes: 2 additions & 2 deletions R/pkg/R/mllib_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ setClass("IsotonicRegressionModel", representation(jobj = "jobj"))
#' summary(savedModel)
#'
#' # fit tweedie model
#' library(statmod)
#' require(statmod)
#' model <- spark.glm(df, Sepal_Length ~ Sepal_Width,
#' family = tweedie(var.power = 1.5, link.power = 0))
#' family = tweedie(var.power = 1.2, link.power = 0))
#' summary(model)
#' }
#' @note spark.glm since 2.0.0
Expand Down
12 changes: 12 additions & 0 deletions R/pkg/inst/tests/testthat/test_mllib_regression.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ test_that("spark.glm and predict", {
out <- capture.output(print(summary(model)))
expect_true(any(grepl("Dispersion parameter for gamma family", out)))

# tweedie family
require(statmod)
model <- spark.glm(training, Sepal_Width ~ Sepal_Length + Species,
family = tweedie(var.power = 1.2, link.power = 1.0))
prediction <- predict(model, training)
expect_equal(typeof(take(select(prediction, "prediction"), 1)$prediction), "double")
vals <- collect(select(prediction, "prediction"))
rVals <- suppressWarnings(predict(
glm(Sepal.Width ~ Sepal.Length + Species, data = iris,
family = tweedie(var.power = 1.2, link.power = 1.0)), iris))
expect_true(all(abs(rVals - vals) < 1e-6), rVals - vals)

# Test stats::predict is working
x <- rnorm(15)
y <- x + rnorm(15)
Expand Down

0 comments on commit 852dd6e

Please sign in to comment.