Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Oct 29, 2023
1 parent bfc8f8f commit da58f2f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,4 @@ Config/Needs/website:
r-lib/pkgdown,
easystats/easystatstemplate
Config/rcmdcheck/ignore-inconsequential-notes: true
Remotes: easystats/insight
52 changes: 52 additions & 0 deletions tests/testthat/test-check_predictions.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,55 @@ test_that("check_predictions, glmmTMB", {
)
expect_true(attributes(out)$model_info$is_bernoulli)
})


test_that("check_predictions, glm, binomial", {
skip_if(packageVersion("insight") <= "0.19.6")
data(mtcars)
set.seed(1)
tot <- rep(10, 100)
suc <- rbinom(100, prob = 0.9, size = tot)
dat <- data.frame(tot, suc)
dat$prop <- suc / tot

mod1 <- glm(cbind(suc, tot - suc) ~ 1,
family = binomial,
data = dat
)

mod2 <- glm(prop ~ 1,
family = binomial,
data = dat,
weights = tot
)

mod3 <- glm(cbind(suc, tot) ~ 1,
family = binomial,
data = dat
)

mod4 <- glm(am ~ 1,
family = binomial,
data = mtcars
)

set.seed(1)
out1 <- check_predictions(mod1)
set.seed(1)
out2 <- check_predictions(mod2)
set.seed(1)
out3 <- check_predictions(mod3)
set.seed(1)
out4 <- check_predictions(mod4)


dput(head(out4$sim_1))
expect_equal(head(out1$sim_1), c(1, 0.9, 0.9, 0.8, 1, 0.8), tolerance = 1e-4)
expect_false(attributes(out1)$model_info$is_bernoulli)
expect_equal(head(out2$sim_1), c(1, 0.9, 0.9, 0.8, 1, 0.8), tolerance = 1e-4)
expect_false(attributes(out2)$model_info$is_bernoulli)
expect_equal(head(out3$sim_1), c(0.4, 0.42105, 0.47368, 0.61111, 0.4, 0.61111), tolerance = 1e-3)
expect_false(attributes(out3)$model_info$is_bernoulli)
expect_equal(head(out4$sim_1), c(0, 0, 0, 1, 0, 1), tolerance = 1e-4)
expect_true(attributes(out4)$model_info$is_bernoulli)
})

0 comments on commit da58f2f

Please sign in to comment.