Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Nov 21, 2023
1 parent 450261e commit dc1c906
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ Suggests:
lme4,
lmerTest,
lmtest,
logistf,
logspline,
lqmm,
M3C,
Expand Down
2 changes: 1 addition & 1 deletion R/methods_logistf.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ p_value.logistf <- function(model, ...) {
utils::capture.output(s <- summary(model)) # nolint

.data_frame(
Parameter = .remove_backticks_from_string(names(s$prob)),
Parameter = .remove_backticks_from_string(names(s$coefficients)),
p = as.vector(s$prob)
)
}
Expand Down
63 changes: 63 additions & 0 deletions tests/testthat/_snaps/windows/model_parameters.logistf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# model_parameters.logistf

Code
params
Output
# Fixed Effects
Parameter | Log-Odds | SE | 95% CI | Chi2(1) | p
-----------------------------------------------------------------
(Intercept) | 0.12 | 0.48 | [-0.82, 1.07] | 0.06 | 0.802
age | -1.11 | 0.41 | [-1.97, -0.31] | 7.51 | 0.006
oc | -0.07 | 0.43 | [-0.94, 0.79] | 0.02 | 0.875
vic | 2.27 | 0.54 | [ 1.27, 3.44] | 22.93 | < .001
vicl | -2.11 | 0.53 | [-3.26, -1.12] | 19.10 | < .001
vis | -0.79 | 0.41 | [-1.61, 0.02] | 3.70 | 0.054
dia | 3.10 | 1.51 | [ 0.77, 8.03] | 7.90 | 0.005
Message
Uncertainty intervals (profile-likelihood) and p-values (two-tailed)
computed using a Wald z-distribution approximation.

# model_parameters.flic

Code
params
Output
# Fixed Effects
Parameter | Log-Odds | SE | 95% CI | Chi2(1) | p
-----------------------------------------------------------------
(Intercept) | 0.13 | 0.28 | [-0.82, 1.08] | 0.85 | 0.358
age | -1.11 | 0.29 | [-1.97, -0.31] | 7.51 | 0.006
oc | -0.07 | 0.24 | [-0.94, 0.79] | 0.02 | 0.875
vic | 2.27 | 0.24 | [ 1.27, 3.44] | 22.93 | < .001
vicl | -2.11 | 0.25 | [-3.26, -1.12] | 19.10 | < .001
vis | -0.79 | 0.26 | [-1.61, 0.02] | 3.70 | 0.054
dia | 3.10 | 0.41 | [ 0.77, 8.03] | 7.90 | 0.005
Message
Uncertainty intervals (profile-likelihood) and p-values (two-tailed)
computed using a Wald z-distribution approximation.

# model_parameters.flac

Code
params
Output
# Fixed Effects
Parameter | Log-Odds | SE | 95% CI | Chi2(1) | p
-----------------------------------------------------------------
(Intercept) | 0.12 | 0.48 | [-0.81, 1.07] | 0.07 | 0.797
age | -1.10 | 0.42 | [-1.95, -0.31] | 7.55 | 0.006
oc | -0.07 | 0.43 | [-0.93, 0.79] | 0.02 | 0.879
vic | 2.28 | 0.54 | [ 1.29, 3.43] | 23.37 | < .001
vicl | -2.11 | 0.53 | [-3.24, -1.13] | 19.45 | < .001
vis | -0.79 | 0.41 | [-1.60, 0.01] | 3.74 | 0.053
dia | 3.18 | 1.53 | [ 0.87, 7.99] | 8.54 | 0.003
Message
Uncertainty intervals (profile-likelihood) and p-values (two-tailed)
computed using a Wald z-distribution approximation.

27 changes: 27 additions & 0 deletions tests/testthat/test-model_parameters.logistf.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
skip_if_not_installed("logistf")
skip_if_not_installed("withr")

# skip_on_cran()

withr::with_options(
list(parameters_exponentiate = FALSE),
{
data(sex2, package = "logistf")
m1 <- logistf::logistf(case ~ age + oc + vic + vicl + vis + dia, data = sex2)
m2 <- logistf::flic(m1)
m3 <- logistf::flac(m1, data = sex2)

test_that("model_parameters.logistf", {
params <- model_parameters(m1)
expect_snapshot(params, variant = "windows")
})
test_that("model_parameters.flic", {
params <- model_parameters(m2)
expect_snapshot(params, variant = "windows")
})
test_that("model_parameters.flac", {
params <- model_parameters(m3)
expect_snapshot(params, variant = "windows")
})
}
)

0 comments on commit dc1c906

Please sign in to comment.