Skip to content

Commit

Permalink
lintr
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Oct 4, 2024
1 parent 394f7c7 commit 3049fc2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
30 changes: 22 additions & 8 deletions tests/testthat/test-bayesfactor_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ test_that("bayesfactor_models BIC", {
BFM3 <- bayesfactor_models(mo2, mo3, mo4, mo1, denominator = mo1)
BFM4 <<- bayesfactor_models(mo2, mo3, mo4, mo5, mo1, denominator = mo1)

expect_equal(BFM1, BFM2)
expect_equal(BFM1, BFM3)
expect_equal(BFM1, bayesfactor_models(list(mo2 = mo2, mo3 = mo3, mo4 = mo4, mo1 = mo1), denominator = 4))
expect_equal(BFM1, BFM2, tolerance = 1e-4, ignore_attr = TRUE)
expect_equal(BFM1, BFM3, tolerance = 1e-4, ignore_attr = TRUE)
expect_equal(
BFM1,
bayesfactor_models(list(mo2 = mo2, mo3 = mo3, mo4 = mo4, mo1 = mo1), denominator = 4),
tolerance = 1e-4, ignore_attr = TRUE
)

# only on same data!
expect_warning(bayesfactor_models(mo1, mo2, mo4_e))
Expand Down Expand Up @@ -105,11 +109,13 @@ test_that("bayesfactor_models STAN", {
set.seed(333)
suppressMessages({
expect_warning(
stan_models <- bayesfactor_models(stan_bf_0, stan_bf_1)
{
stan_models <- bayesfactor_models(stan_bf_0, stan_bf_1)
}
)
})
expect_s3_class(stan_models, "bayesfactor_models")
expect_equal(length(stan_models$log_BF), 2)
expect_length(stan_models$log_BF, 2)
expect_equal(stan_models$log_BF[2], log(bridge_BF$bf), tolerance = 0.1)
})

Expand Down Expand Up @@ -143,7 +149,9 @@ test_that("bayesfactor_models BRMS", {
set.seed(444)
suppressWarnings(suppressMessages(
expect_message(
bfm <- bayesfactor_models(stan_brms_model_0, stan_brms_model_1),
{
bfm <- bayesfactor_models(stan_brms_model_0, stan_brms_model_1)
},
regexp = "marginal"
)
))
Expand All @@ -163,7 +171,12 @@ test_that("bayesfactor_models BRMS", {
silent = 2
)

suppressWarnings(expect_message(bfmwc <- bayesfactor_models(stan_brms_model_0wc, stan_brms_model_1wc), regexp = NA))
suppressWarnings(expect_message(
{
bfmwc <- bayesfactor_models(stan_brms_model_0wc, stan_brms_model_1wc)
},
regexp = NA
))
expect_equal(bfmwc$log_BF, bfm$log_BF, tolerance = 0.01)
})

Expand All @@ -179,7 +192,8 @@ test_that("bayesfactor_inclusion | BayesFactor", {
BF_ToothGrowth <- BayesFactor::anovaBF(len ~ dose * supp, ToothGrowth)
expect_equal(
bayesfactor_inclusion(BF_ToothGrowth),
bayesfactor_inclusion(bayesfactor_models(BF_ToothGrowth))
bayesfactor_inclusion(bayesfactor_models(BF_ToothGrowth)),
tolerance = 1e-4, ignore_attr = TRUE
)
})

Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-brms.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ test_that("brms", {
expect_s3_class(hdi(model), "data.frame")
expect_s3_class(ci(model), "data.frame")
expect_s3_class(rope(model, verbose = FALSE), "data.frame")
expect_true(inherits(equivalence_test(model), "equivalence_test"))
expect_s3_class(equivalence_test(model), "equivalence_test")
expect_s3_class(map_estimate(model), "data.frame")
expect_s3_class(p_map(model), "data.frame")
expect_s3_class(p_direction(model), "data.frame")

expect_identical(colnames(hdi(model)), c("Parameter", "CI", "CI_low", "CI_high", "Effects", "Component"))
expect_identical(colnames(hdi(model, effects = "all")), c("Parameter", "CI", "CI_low", "CI_high", "Effects", "Component"))
expect_equal(nrow(equivalence_test(model)), 2L)
expect_named(hdi(model), c("Parameter", "CI", "CI_low", "CI_high", "Effects", "Component"))
expect_named(hdi(model, effects = "all"), c("Parameter", "CI", "CI_low", "CI_high", "Effects", "Component"))
expect_identical(nrow(equivalence_test(model)), 2L)

out <- describe_posterior(model, effects = "all", component = "all", centrality = "mean")
suppressWarnings({
Expand Down
16 changes: 9 additions & 7 deletions tests/testthat/test-weighted_posteriors.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test_that("weighted_posteriors for BayesFactor (intercept)", {
BFmods <- regressionBF(y ~ x1 + x2, data = dat, progress = FALSE)

res <- weighted_posteriors(BFmods)
expect_equal(attr(res, "weights")$weights, c(1032, 805, 1388, 775))
expect_equal(attr(res, "weights")$weights, c(1032, 805, 1388, 775), ignore_attr = TRUE)

wHDI <- hdi(res[c("x1", "x2")], ci = 0.9)
expect_equal(wHDI$CI_low, c(-0.519, -0.640), tolerance = 0.01)
Expand All @@ -64,7 +64,7 @@ test_that("weighted_posteriors for nonlinear BayesFactor", {

res <- weighted_posteriors(BFS)

expect_equal(attributes(res)$weights$weights, c(113, 3876, 11))
expect_equal(attributes(res)$weights$weights, c(113, 3876, 11), ignore_attr = TRUE)
})

test_that("weighted_posteriors vs posterior_average", {
Expand All @@ -87,7 +87,9 @@ test_that("weighted_posteriors vs posterior_average", {
)

set.seed(444)
expect_warning(res_BT <- weighted_posteriors(fit1, fit2))
expect_warning({
res_BT <- weighted_posteriors(fit1, fit2)
})

set.seed(444)
res_brms <- brms::posterior_average(fit1, fit2, weights = "bma", missing = 0)
Expand All @@ -96,8 +98,8 @@ test_that("weighted_posteriors vs posterior_average", {
res_BT1 <- eti(res_BT)
res_brms1 <- eti(res_brms)

expect_equal(res_BT1$Parameter, res_brms1$Parameter)
expect_equal(res_BT1$CI, res_brms1$CI)
expect_equal(res_BT1$CI_low, res_brms1$CI_low)
expect_equal(res_BT1$CI_high, res_brms1$CI_high)
expect_equal(res_BT1$Parameter, res_brms1$Parameter, tolerance = 1e-4)
expect_equal(res_BT1$CI, res_brms1$CI, tolerance = 1e-4)
expect_equal(res_BT1$CI_low, res_brms1$CI_low, tolerance = 1e-4)
expect_equal(res_BT1$CI_high, res_brms1$CI_high, tolerance = 1e-4)
})

0 comments on commit 3049fc2

Please sign in to comment.