Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jan 31, 2024
1 parent d6a04cc commit 9e26aae
Showing 1 changed file with 21 additions and 25 deletions.
46 changes: 21 additions & 25 deletions tests/testthat/test-betareg.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,29 +157,25 @@ skip_if_not_installed("withr")

withr::with_environment(
new.env(),
{
test_that("get_predicted", {
data("GasolineYield", package = "betareg")
data("FoodExpenditure", package = "betareg")
mp1 <- betareg::betareg(yield ~ batch + temp, data = GasolineYield)
mp2 <- betareg::betareg(I(food / income) ~ income + persons, data = FoodExpenditure)
p <- suppressWarnings(get_predicted(mp1))
expect_s3_class(p, "get_predicted")
expect_length(p, 32)
p <- suppressWarnings(get_predicted(mp1, data = head(GasolineYield)))
expect_s3_class(p, "get_predicted")
expect_length(p, 6)

# delta method does not work, so we omit SE and issue warning
expect_warning(get_predicted(mp2, predict = "expectation"))
expect_warning(get_predicted(mp2, predict = "link"), NA)
p1 <- suppressWarnings(get_predicted(mp2, predict = "expectation", ci = 0.95))
p2 <- get_predicted(mp2, predict = "link", ci = 0.95)
p1 <- data.frame(p1)
p2 <- data.frame(p2)
expect_false("SE" %in% colnames(p1))
expect_true("SE" %in% colnames(p2))
})

}
test_that("get_predicted", {
data("GasolineYield", package = "betareg")
data("FoodExpenditure", package = "betareg")
mp1 <- betareg::betareg(yield ~ batch + temp, data = GasolineYield)
mp2 <- betareg::betareg(I(food / income) ~ income + persons, data = FoodExpenditure)
p <- suppressWarnings(get_predicted(mp1))
expect_s3_class(p, "get_predicted")
expect_length(p, 32)
p <- suppressWarnings(get_predicted(mp1, data = head(GasolineYield)))
expect_s3_class(p, "get_predicted")
expect_length(p, 6)
# delta method does not work, so we omit SE and issue warning
expect_warning(get_predicted(mp2, predict = "expectation"))
expect_warning(get_predicted(mp2, predict = "link"), NA)
p1 <- suppressWarnings(get_predicted(mp2, predict = "expectation", ci = 0.95))
p2 <- get_predicted(mp2, predict = "link", ci = 0.95)
p1 <- data.frame(p1)
p2 <- data.frame(p2)
expect_false("SE" %in% colnames(p1))
expect_true("SE" %in% colnames(p2))
})
)

0 comments on commit 9e26aae

Please sign in to comment.