Skip to content

Commit

Permalink
uncomment tests for describe_posterior()
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil committed Jul 19, 2023
1 parent 03b607b commit 14737ce
Showing 1 changed file with 70 additions and 58 deletions.
128 changes: 70 additions & 58 deletions tests/testthat/test-describe_posterior.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ test_that("describe_posterior", {
test = "all",
ci = c(0.8, 0.9)
), regex = "ROPE range"), regex = "Prior not specified"), regex = "not be precise")
# rez <- suppressWarnings(describe_posterior(
# x,
# centrality = "all",
# dispersion = TRUE,
# test = "all",
# ci = c(0.8, 0.9)
# ))
# expect_equal(dim(rez), c(2, 19))
rez <- suppressWarnings(describe_posterior(
x,
centrality = "all",
dispersion = TRUE,
test = "all",
ci = c(0.8, 0.9)
))
expect_equal(dim(rez), c(2, 19))

rez <- describe_posterior(
x,
Expand All @@ -72,8 +72,9 @@ test_that("describe_posterior", {
test = "all"
)
))
# rez <- suppressWarnings(describe_posterior(x, centrality = "all", dispersion = TRUE, test = "all"))
# expect_equal(dim(rez), c(4, 19))

rez <- suppressWarnings(describe_posterior(x, centrality = "all", dispersion = TRUE, test = "all"))
expect_equal(dim(rez), c(4L, 19L))
expect_warning(expect_warning(
describe_posterior(
x,
Expand All @@ -83,8 +84,16 @@ test_that("describe_posterior", {
ci = c(0.8, 0.9)
)
))
# rez <- suppressWarnings(describe_posterior(x, centrality = "all", dispersion = TRUE, test = "all", ci = c(0.8, 0.9)))
# expect_equal(dim(rez), c(8, 19))

rez <- suppressWarnings(describe_posterior(
x,
centrality = "all",
dispersion = TRUE,
test = "all",
ci = c(0.8, 0.9)
))
expect_equal(dim(rez), c(8L, 19L))

rez <- describe_posterior(
x,
centrality = NULL,
Expand Down Expand Up @@ -148,36 +157,36 @@ test_that("describe_posterior", {

# brms -------------------------------------------------

# x <- brms::brm(mpg ~ wt + (1 | cyl) + (1 + wt | gear), data = mtcars, refresh = 0)
# rez <- describe_posterior(x, centrality = "all", dispersion = TRUE, ci = c(0.8, 0.9))
#
# expect_equal(dim(rez), c(4, 16))
# expect_equal(colnames(rez), c(
# "Parameter", "Median", "MAD", "Mean", "SD", "MAP", "CI", "CI_low",
# "CI_high", "pd", "ROPE_CI", "ROPE_low", "ROPE_high", "ROPE_Percentage",
# "Rhat", "ESS"
# ))
#
# rez <- describe_posterior(
# x,
# centrality = NULL,
# dispersion = TRUE,
# test = NULL,
# ci_method = "quantile",
# diagnostic = NULL
# )
#
# expect_equal(dim(rez), c(2, 4))
#
# model <- brms::brm(
# mpg ~ drat,
# data = mtcars,
# chains = 2,
# algorithm = "meanfield",
# refresh = 0
# )
#
# expect_equal(nrow(describe_posterior(model)), 2)
x <- brms::brm(mpg ~ wt + (1 | cyl) + (1 + wt | gear), data = mtcars, refresh = 0)
rez <- describe_posterior(x, centrality = "all", dispersion = TRUE, ci = c(0.8, 0.9))

expect_equal(dim(rez), c(4, 16))
expect_equal(colnames(rez), c(
"Parameter", "Median", "MAD", "Mean", "SD", "MAP", "CI", "CI_low",
"CI_high", "pd", "ROPE_CI", "ROPE_low", "ROPE_high", "ROPE_Percentage",
"Rhat", "ESS"
))

rez <- describe_posterior(
x,
centrality = NULL,
dispersion = TRUE,
test = NULL,
ci_method = "quantile",
diagnostic = NULL
)

expect_equal(dim(rez), c(2, 4))

model <- brms::brm(
mpg ~ drat,
data = mtcars,
chains = 2,
algorithm = "meanfield",
refresh = 0
)

expect_equal(nrow(describe_posterior(model)), 2)

# rstanarm -------------------------------------------------

Expand All @@ -204,18 +213,18 @@ test_that("describe_posterior", {
)

expect_identical(nrow(describe_posterior(model)), 2L)
# model <- brms::brm(mpg ~ drat, data = mtcars, chains=2, algorithm="fullrank", refresh=0)
# expect_equal(nrow(describe_posterior(model)), 2)

model <- brms::brm(mpg ~ drat, data = mtcars, chains = 2, algorithm = "fullrank", refresh = 0)
expect_equal(nrow(describe_posterior(model)), 2L)

# BayesFactor
# library(BayesFactor)
# x <- BayesFactor::ttestBF(x = rnorm(100, 1, 1))
# rez <- describe_posterior(x, centrality = "all", dispersion = TRUE, test = "all")
# expect_equal(dim(rez), c(4, 16))
# rez <- describe_posterior(x, centrality = "all", dispersion = TRUE, test = "all", ci = c(0.8, 0.9))
# expect_equal(dim(rez), c(8, 16))
# rez <- describe_posterior(x, centrality = NULL, dispersion = TRUE, test = NULL, ci_method="quantile")
# expect_equal(dim(rez), c(4, 4))
x <- BayesFactor::ttestBF(x = rnorm(100, 1, 1))
rez <- describe_posterior(x, centrality = "all", dispersion = TRUE, test = "all")
expect_equal(dim(rez), c(4, 16))
rez <- describe_posterior(x, centrality = "all", dispersion = TRUE, test = "all", ci = c(0.8, 0.9))
expect_equal(dim(rez), c(8, 16))
rez <- describe_posterior(x, centrality = NULL, dispersion = TRUE, test = NULL, ci_method = "quantile")
expect_equal(dim(rez), c(4, 4))
})


Expand Down Expand Up @@ -462,12 +471,15 @@ test_that("describe_posterior: BayesFactor", {

set.seed(123)
expect_warning(expect_equal(
describe_posterior(contingencyTableBF(
x = table(mtcars$am, mtcars$cyl),
sampleType = "indepMulti",
fixedMargin = "cols",
priorConcentration = 1.6
), ci = 0.95),
describe_posterior(
contingencyTableBF(
x = table(mtcars$am, mtcars$cyl),
sampleType = "indepMulti",
fixedMargin = "cols",
priorConcentration = 1.6
),
ci = 0.95
),
structure(
list(
Parameter = c(
Expand Down

0 comments on commit 14737ce

Please sign in to comment.