From dc1c9067448fb3c170023e8ccfc190daa9b3f4a0 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 21 Nov 2023 11:20:04 +0100 Subject: [PATCH] add tests --- DESCRIPTION | 1 + R/methods_logistf.R | 2 +- .../windows/model_parameters.logistf.md | 63 +++++++++++++++++++ .../testthat/test-model_parameters.logistf.R | 27 ++++++++ 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 tests/testthat/_snaps/windows/model_parameters.logistf.md create mode 100644 tests/testthat/test-model_parameters.logistf.R diff --git a/DESCRIPTION b/DESCRIPTION index 9d2abefc3..b16d757e7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -146,6 +146,7 @@ Suggests: lme4, lmerTest, lmtest, + logistf, logspline, lqmm, M3C, diff --git a/R/methods_logistf.R b/R/methods_logistf.R index 2912c488b..27f47562e 100644 --- a/R/methods_logistf.R +++ b/R/methods_logistf.R @@ -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) ) } diff --git a/tests/testthat/_snaps/windows/model_parameters.logistf.md b/tests/testthat/_snaps/windows/model_parameters.logistf.md new file mode 100644 index 000000000..d15d7ac16 --- /dev/null +++ b/tests/testthat/_snaps/windows/model_parameters.logistf.md @@ -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. + diff --git a/tests/testthat/test-model_parameters.logistf.R b/tests/testthat/test-model_parameters.logistf.R new file mode 100644 index 000000000..824b74226 --- /dev/null +++ b/tests/testthat/test-model_parameters.logistf.R @@ -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") + }) + } +)