tests/testthat/testBFE.R

library(testthat)
library(BayesFactor)
library(BFEffects)

data("ToothGrowth")
df <- ToothGrowth
df$dose <- factor(df$dose)
BF <- anovaBF(len ~ supp * dose, df)

# Test restricted ---------------------------------------------------------

test_that("restricted", {
  expect_is(restrict(BF[1], OJ < 0), "resBF")
  expect_is(restrict(BF[1], OJ < 0), "list")

  expect_equal(length(restrict(BF[1], OJ < 0)),2)

  expect_is(restrict(BF, OJ < 0)$probability,'data.frame')
  expect_equal(ncol(restrict(BF, OJ < 0)$probability),2)
  expect_equal(nrow(restrict(BF, OJ < 0)$probability),1)

  expect_is(restrict(BF, OJ < 0)$`log(BFs)`,'data.frame')
  expect_equal(ncol(restrict(BF, OJ < 0)$`log(BFs)`),3)
  expect_equal(nrow(restrict(BF, OJ < 0)$`log(BFs)`),1)

  expect_is(restrict(BF), "character")
})


# Test BFGrid -------------------------------------------------------------

mo0 <- lm(Sepal.Length ~ 1, data = iris)
mo1 <- lm(Sepal.Length ~ Species, data = iris)
moBad <- lm(Sepal.Length ~ Species + Petal.Length, data = iris[-1,])

test_that("BIC_BFs", {
  expect_is(BIC_BFs(mo0,mo1), "BFEffect")
  expect_is(BIC_BFs(mo0,mo1), "BFGrid")
  expect_error(BIC_BFs(mo0,moBad))
})

test_that("BayesFactor_BFs", {
  expect_is(BayesFactor_BFs(BF), "BFGrid")
})

# test_that("stan_BFs", {
#   # add
# })
mattansb/BFEffect documentation built on June 7, 2019, 8:49 p.m.