Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Aug 31, 2024
1 parent 8152a14 commit c6be337
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion R/p_direction.R
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ p_direction.stanreg <- function(x,
attr(out, "clean_parameters") <- cleaned_parameters
class(out) <- unique(c("p_direction", "see_p_direction", class(out)))
attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(x))
attr(out, "as_p") <- as_p
out
}

Expand Down Expand Up @@ -519,6 +520,7 @@ p_direction.brmsfit <- function(x,
attr(out, "clean_parameters") <- cleaned_parameters
class(out) <- unique(c("p_direction", "see_p_direction", class(out)))
attr(out, "object_name") <- insight::safe_deparse_symbol(substitute(x))
attr(out, "as_p") <- as_p
out
}

Expand Down Expand Up @@ -668,7 +670,7 @@ p_direction.parameters_model <- function(x, ...) {
as.numeric.p_direction <- function(x, ...) {
if (inherits(x, "data.frame")) {
# check if we have frequentist p-values
if (attributes(x)$as_p && "p" %in% colnames(x)) {
if (isTRUE(attributes(x)$as_p) && "p" %in% colnames(x)) {
as.numeric(as.vector(x$p))
} else {
as.numeric(as.vector(x$pd))
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-p_direction.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,20 @@ test_that("p_direction", {
p_direction(p)$pd,
tolerance = 1e-3
)
# converstion into frequentist p-value works
expect_equal(
p_direction(m, effects = "all", as_p = TRUE)$p,
pd_to_p(p_direction(m, effects = "all")$pd),
tolerance = 1e-3
)
expect_equal(
p_direction(m, effects = "all", as_p = TRUE)$p,
as.numeric(p_direction(m, effects = "all", as_p = TRUE)),
tolerance = 1e-3
)
})


test_that("p_direction", {
skip_if_offline()
skip_if_not_or_load_if_installed("rstanarm")
Expand Down

0 comments on commit c6be337

Please sign in to comment.