tests/testthat/test.get_variables.R

# Tests for get_variables
#
# Author: mjskay
###############################################################################

library(dplyr)




test_that("mcmc variable extraction works", {
  data(RankCorr, package = "ggdist")

  ref = dimnames(RankCorr[[1]])[[2]]

  tidy_draws_ref = RankCorr %>%
    tidy_draws() %>%
    names() %>%
    setdiff(c(".chain", ".iteration", ".draw"))

  expect_equal(get_variables(RankCorr), ref)
  expect_equal(get_variables(RankCorr[[1]]), ref)
  expect_equal(get_variables(RankCorr), tidy_draws_ref)
})

test_that("rstanarm variable extraction works", {
  skip_if_not_installed("rstanarm")

  m_hp_wt = readRDS("../models/models.rstanarm.m_hp_wt.rds")

  expect_equal(get_variables(m_hp_wt),
    c("(Intercept)", "hp", "wt", "hp:wt", "sigma", "accept_stat__",
      "stepsize__", "treedepth__", "n_leapfrog__", "divergent__", "energy__")
  )
})

Try the tidybayes package in your browser

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

tidybayes documentation built on Sept. 15, 2024, 9:08 a.m.