Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Oct 25, 2023
1 parent 94f0267 commit 9835b52
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/testthat/_snaps/complete_separation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# print warning about complete separation

Code
print(out)
Output
Parameter | Log-Odds | SE | 95% CI | z | p
------------------------------------------------------------------------------
(Intercept) | -66.10 | 1.83e+05 | [-10644.72, 10512.52] | -3.60e-04 | > .999
x1 | 15.29 | 27362.84 | [ -3122.69, ] | 5.59e-04 | > .999
x2 | 6.24 | 81543.72 | [-12797.28, ] | 7.65e-05 | > .999
Message
Uncertainty intervals (profile-likelihood) and p-values (two-tailed)
computed using a Wald z-distribution approximation.
The model has a log- or logit-link. Consider using `exponentiate =
TRUE` to interpret coefficients as ratios.
Note that some coefficients are very large, which may indicate issues
with complete separation.

---

Code
print(out)
Output
Parameter | Log-Odds | SE | 95% CI | z | p
-------------------------------------------------------------------------
(Intercept) | -83.33 | 15505.03 | [ , 816.56] | -5.37e-03 | 0.996
gear | 21.01 | 3876.26 | [-248.93, ] | 5.42e-03 | 0.996
Message
Uncertainty intervals (profile-likelihood) and p-values (two-tailed)
computed using a Wald z-distribution approximation.
The model has a log- or logit-link. Consider using `exponentiate =
TRUE` to interpret coefficients as ratios.
Note that some coefficients are very large, which may indicate issues
with complete separation.

# print warning about quasi complete separation

Code
print(out)
Output
Parameter | Log-Odds | SE | 95% CI | z | p
------------------------------------------------------------------
(Intercept) | -56.36 | 21.45 | [-114.76, -25.33] | -2.63 | 0.009
qsec | 3.12 | 1.19 | [ 1.40, 6.37] | 2.62 | 0.009
Message
Uncertainty intervals (profile-likelihood) and p-values (two-tailed)
computed using a Wald z-distribution approximation.
The model has a log- or logit-link. Consider using `exponentiate =
TRUE` to interpret coefficients as ratios.
Note that some coefficients are very large, which may indicate issues
with (quasi) complete separation. Consider using bias-corrected or
penalized regression models.

42 changes: 42 additions & 0 deletions tests/testthat/test-complete_separation.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
skip_if(getRversion() < "4.0.0")
skip_if_not_installed("withr")

withr::with_options(
list("parameters_warning_exponentiate" = TRUE),

Check warning on line 5 in tests/testthat/test-complete_separation.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-complete_separation.R,line=5,col=8,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
{
test_that("print warning about complete separation", {
d_sep <- data.frame(
y = c(0, 0, 0, 0, 1, 1, 1, 1),
x1 = c(1, 2, 3, 3, 5, 6, 10, 11),
x2 = c(3, 2, -1, -1, 2, 4, 1, 0)
)
m_sep <- suppressWarnings(glm(y ~ x1 + x2, data = d_sep, family = binomial))
out <- model_parameters(m_sep)
expect_snapshot(print(out))
})
}
)

withr::with_options(
list("parameters_warning_exponentiate" = TRUE),

Check warning on line 21 in tests/testthat/test-complete_separation.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-complete_separation.R,line=21,col=8,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
{
test_that("print warning about complete separation", {
data(mtcars)
m_sep2 <- suppressWarnings(glm(am ~ gear, data = mtcars, family = binomial))
out <- model_parameters(m_sep2)
expect_snapshot(print(out))
})
}
)

withr::with_options(
list("parameters_warning_exponentiate" = TRUE),

Check warning on line 33 in tests/testthat/test-complete_separation.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-complete_separation.R,line=33,col=8,[keyword_quote_linter] Only quote named arguments to functions if necessary, i.e., if the name is not a valid R symbol (see ?make.names).
{
test_that("print warning about quasi complete separation", {
data(mtcars)
m_sep3 <- suppressWarnings(glm(vs ~ qsec, data = mtcars, family = binomial))
out <- model_parameters(m_sep3)
expect_snapshot(print(out))
})
}
)

0 comments on commit 9835b52

Please sign in to comment.