tests/testthat/test_point_mass.R

context("point mass")

x <- 1:10
s <- 1

test_that("Basic functionality works", {
  pm.res <- ebnm(x, s, prior_family = "point_mass")
  pm.res2 <- ebnm_point_mass(x, s)
  pm.res$call <- pm.res2$call <- NULL
  expect_identical(pm.res, pm.res2)
  expect_identical(pm.res$posterior$mean, rep(0, length(x)))
  expect_identical(pm.res$posterior$sd, rep(0, length(x)))
})

test_that("Parameters that do nothing are ignored", {
  expect_warning(pm.res <- ebnm(x, s, prior_family = "point_mass", scale = 1))
})

test_that("Fixing g works", {
  g <- ashr::normalmix(1, 0, 0)
  pm.res <- ebnm_point_mass(x, s, g_init = g, fix_g = TRUE)
  expect_true(all(pm.res$posterior$mean == 0))
})

test_that("Setting the mode works", {
  pm.res <- ebnm_point_mass(x, s, mode = 5)
  expect_equal(pm.res$fitted_g$mean, 5)
})

test_that("Mode estimation works", {
  pm.res <- ebnm_point_mass(x, s, mode = "estimate")
  expect_equal(pm.res$fitted_g$mean, mean(x))
})

Try the ebnm package in your browser

Any scripts or data that you put into this service are public.

ebnm documentation built on Oct. 13, 2023, 1:16 a.m.