swh:1:snp:2c68a6c5a8af2f06ac2c0225927f25b54fd1f9d0
Raw File
Tip revision: 428249f43a9c6fd0c425b28deb5fee51a9525d69 authored by Dominique Makowski on 18 September 2022, 01:46:03 UTC
version 0.13.0
Tip revision: 428249f
test-p_map.R
if (requireNamespace("rstanarm", quietly = TRUE)) {
  test_that("p_map", {
    expect_equal(as.numeric(p_map(distribution_normal(1000))), 1, tolerance = 0.1)
    expect_equal(as.numeric(p_map(distribution_normal(1000, 1, 1))), 0.62, tolerance = 0.1)
    expect_equal(as.numeric(p_map(distribution_normal(1000, 2, 1))), 0.15, tolerance = 0.1)
    expect_equal(as.numeric(p_map(distribution_normal(1000, 3, 0.01))), 0, tolerance = 0.1)
  })


  .runThisTest <- Sys.getenv("RunAllbayestestRTests") == "yes"
  if (.runThisTest) {
    if (require("insight")) {
      m <- insight::download_model("stanreg_merMod_5")
      p <- insight::get_parameters(m, effects = "all")

      test_that("p_map", {
        expect_equal(
          p_map(m, effects = "all")$p_MAP,
          p_map(p)$p_MAP,
          tolerance = 0.1
        )
      })

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

      test_that("p_map", {
        expect_equal(
          p_map(m, effects = "all", component = "all")$p_MAP,
          p_map(p)$p_MAP,
          tolerance = 0.1
        )
      })
    }
  }
}
back to top