https://github.com/cran/bayestestR
Raw File
Tip revision: 053d5208164a7eccb0edff2752c83e3a99c8f69d authored by Dominique Makowski on 07 April 2023, 14:20:02 UTC
version 0.13.1
Tip revision: 053d520
test-distributions.R
test_that("distributions", {
  tolerance <- 0.01

  expect_equal(mean(distribution_normal(10)), 0, tolerance = tolerance)
  expect_equal(length(distribution_normal(10, random = TRUE)), 10, tolerance = tolerance)

  expect_equal(mean(distribution_beta(10, 1, 1)), 0.5, tolerance = tolerance)
  expect_equal(length(distribution_normal(10, 1, 1, random = TRUE)), 10, tolerance = tolerance)

  expect_equal(mean(distribution_binomial(10, 0, 0.5)), 0, tolerance = tolerance)
  expect_equal(length(distribution_binomial(10, 0, 0.5, random = TRUE)), 10, tolerance = tolerance)

  expect_equal(mean(distribution_cauchy(10)), 0, tolerance = tolerance)
  expect_equal(length(distribution_cauchy(10, random = TRUE)), 10, tolerance = tolerance)

  expect_equal(mean(distribution_chisquared(10, 1)), 0.893, tolerance = tolerance)
  expect_equal(length(distribution_chisquared(10, 1, random = TRUE)), 10, tolerance = tolerance)

  expect_equal(mean(distribution_gamma(10, 1)), 0.9404, tolerance = tolerance)
  expect_equal(length(distribution_gamma(10, 1, random = TRUE)), 10, tolerance = tolerance)

  expect_equal(mean(distribution_poisson(10)), 1, tolerance = tolerance)
  expect_equal(length(distribution_poisson(10, random = TRUE)), 10, tolerance = tolerance)

  expect_equal(mean(distribution_student(10, 1)), 0, tolerance = tolerance)
  expect_equal(length(distribution_student(10, 1, random = TRUE)), 10, tolerance = tolerance)

  expect_equal(mean(distribution_uniform(10)), 0.5, tolerance = tolerance)
  expect_equal(length(distribution_uniform(10, random = TRUE)), 10, tolerance = tolerance)
})
back to top