Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Sep 3, 2024
1 parent ecf09eb commit 2cc5dd3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
7 changes: 6 additions & 1 deletion R/p_significance.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ p_significance.lm <- function(x, threshold = "default", ci = 0.95, verbose = TRU
verbose = verbose
))

attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(x))
# for plot, we need to have it numeric
if (!is.numeric(threshold)) {
threshold <- 0.1
}

attr(out, "data") <- posterior
attr(out, "threshold") <- threshold
class(out) <- c("p_significance_lm", "p_significance", "see_p_significance", "data.frame")
out
Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/_snaps/p_significance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# p_significance

Code
print(x)
Output
Practical Significance (threshold: default)
Parameter | 95% CI | ps
-----------------------------------------
(Intercept) | [24.44, 48.94] | ps > .999
gear | [-1.69, 2.41] | ps = 0.663
wt | [-4.77, -1.28] | ps > .999
cyl | [-2.17, 0.55] | ps = 0.958
hp | [-0.05, 0.01] | ps < .001

19 changes: 19 additions & 0 deletions tests/testthat/test-p_significance.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
skip_if_not_installed("bayestestR")

test_that("p_significance", {
data(mtcars)
m <- lm(mpg ~ gear + wt + cyl + hp, data = mtcars)
set.seed(123)
x <- p_significance(m)
expect_identical(c(nrow(x), ncol(x)), c(5L, 5L))
expect_named(x, c("Parameter", "CI", "CI_low", "CI_high", "ps"))
expect_snapshot(print(x))

set.seed(123)
x <- p_significance(m, ci = 0.8)
expect_equal(x$ps, c(1, 0.7446, 1, 0.9964, 0), tolerance = 1e-4)

set.seed(123)
x <- p_significance(m, threshold = 0.5)
expect_equal(x$ps, c(1, 0.4128, 1, 0.7751, 0), tolerance = 1e-4)
})

0 comments on commit 2cc5dd3

Please sign in to comment.