https://github.com/cran/bayestestR
Revision 40f7c88ddf855896018cf20ec8a7ac5fbd0ea2fb authored by Dominique Makowski on 27 January 2020, 05:30:28 UTC, committed by cran-robot on 27 January 2020, 05:30:28 UTC
1 parent d8462ad
Raw File
Tip revision: 40f7c88ddf855896018cf20ec8a7ac5fbd0ea2fb authored by Dominique Makowski on 27 January 2020, 05:30:28 UTC
version 0.5.1
Tip revision: 40f7c88
test-p_direction.R
if (requireNamespace("rstanarm", quietly = TRUE)) {
  context("p_direction")

  test_that("p_direction", {
    set.seed(333)
    x <- bayestestR::distribution_normal(10000, 1, 1)
    pd <- bayestestR::p_direction(x)
    testthat::expect_equal(as.numeric(pd), 0.842, tolerance = 0.1)
    testthat::expect_equal(as.numeric(p_direction(x, method = "kernel")), 0.842, tolerance = 0.1)
    testthat::expect_equal(nrow(p_direction(data.frame(replicate(4, rnorm(100))))), 4)
    testthat::expect_is(pd, "p_direction")
    testthat::expect_equal(tail(capture.output(print(pd)), 1), "pd = 84.14%")
  })


  if (require("insight")) {
    m <- insight::download_model("stanreg_merMod_5")
    p <- insight::get_parameters(m, effects = "all")

    testthat::test_that("p_direction", {
      testthat::expect_equal(
        p_direction(m, effects = "all")$pd,
        p_direction(p)$pd,
        tolerance = 1e-3
      )
    })

    m <- insight::download_model("brms_zi_3")
    p <- insight::get_parameters(m, effects = "all", component = "all")

    testthat::test_that("p_direction", {
      testthat::expect_equal(
        p_direction(m, effects = "all", component = "all")$pd,
        p_direction(p)$pd,
        tolerance = 1e-3
      )
    })
  }
}
back to top