tests/testthat/test_BFmeta.R

# test for BF on rma.uni object
library(metafor)

# ### Generate data
tau2 <- 0.05 # True between-study variance

set.seed(123)
vi <- runif(50, min = 0.01, max = 0.2) # Observed sampling variances
yi <- rnorm(50, mean = 0, sd = sqrt(vi+tau2)) # Observed effect sizes

test_that("exploratory metafor test for I^2", {
  skip_on_cran()
  ### Fit a random-effects model to the data
  res <- rma(yi = yi, vi = vi)
  BFmeta1 <- BF(res)
  expect_equivalent(
    round(BFmeta1$PHP_exploratory[1,],3),c(0.086,0.013,0.902), tolerance = .05
  )
  expect_equivalent(
    round(BFmeta1$PHP_exploratory[2,],3),c(.800,0.086,0.114), tolerance = .05
  )
})

# test fixed effects meta model
test_that("exploratory metafor test for I^2", {
  res <- metafor::rma(yi = yi, vi = vi, method = "EE")
  BFmeta2 <- BF(res)
  expect_equivalent(
    round(BFmeta2$PHP_exploratory,3),c(0.844,0.082,0.074), tolerance = .05
  )
})

Try the BFpack package in your browser

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

BFpack documentation built on Oct. 20, 2023, 5:09 p.m.