Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jul 23, 2023
1 parent 5df0801 commit 66991bb
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions tests/testthat/test-get_predicted.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ test_that("get_predicted - lm", {
# Confidence
ref <- predict(x, se.fit = TRUE, interval = "confidence")
rez <- as.data.frame(get_predicted(x, predict = "expectation", ci = 0.95))
expect_length(rez, 32)
expect_identical(nrow(rez), 32L)
expect_equal(max(abs(as.data.frame(ref$fit)$fit - rez$Predicted)), 0, tolerance = 1e-10)
expect_equal(max(abs(ref$se.fit - rez$SE)), 0, tolerance = 1e-10)
expect_equal(max(abs(as.data.frame(ref$fit)$lwr - rez$CI_low)), 0, tolerance = 1e-10)

# Prediction
ref <- predict(x, newdata = get_data(x), se.fit = TRUE, interval = "prediction")
rez <- as.data.frame(get_predicted(x, predict = "prediction", ci = 0.95))
expect_length(rez, 32)
expect_identical(nrow(rez), 32L)
expect_equal(max(abs(as.data.frame(ref$fit)$fit - rez$Predicted)), 0, tolerance = 1e-10)
expect_equal(max(abs(as.data.frame(ref$fit)$lwr - rez$CI_low)), 0, tolerance = 1e-10)

Expand Down Expand Up @@ -124,15 +124,15 @@ test_that("get_predicted - glm", {
dat_glm <- glm(Y ~ 1, data = dat, family = gaussian(link = "log"))
## predictions on the response scale - correct
out <- modelbased::estimate_relation(dat_glm, length = 1)
expect_identical(
expect_equal(
out$Predicted,
predict(dat_glm, type = "response")[1],
tolerance = 0.01,
ignore_attr = TRUE
)
## predictions on the link scale - incorrect
out <- modelbased::estimate_link(dat_glm, length = 1)
expect_identical(
expect_equal(
out$Predicted,
predict(dat_glm, type = "link")[1],
tolerance = 0.01,
Expand All @@ -145,11 +145,11 @@ test_that("get_predicted - lm (log)", {
rez <- get_predicted(x)
expect_length(rez, 32)

expect_identical(max(abs(rez - stats::fitted(x))), 0)
expect_identical(max(abs(rez - stats::predict(x))), 0)
expect_equal(max(abs(rez - stats::fitted(x))), 0, tolerance = 1e-4)
expect_equal(max(abs(rez - stats::predict(x))), 0, tolerance = 1e-4)

data <- as.data.frame(rez)
expect_identical(max(abs(rez - data$Predicted)), 0)
expect_equal(max(abs(rez - data$Predicted)), 0, tolerance = 1e-4)
expect_identical(nrow(data), 32L)
})

Expand Down

0 comments on commit 66991bb

Please sign in to comment.