diff --git a/R/map_estimate.R b/R/map_estimate.R index c0ee9345c..9731e7023 100644 --- a/R/map_estimate.R +++ b/R/map_estimate.R @@ -50,7 +50,9 @@ map_estimate <- function(x, precision = 2^10, method = "kernel", ...) { #' @export map_estimate.numeric <- function(x, precision = 2^10, method = "kernel", ...) { out <- map_estimate(data.frame(x = x), - precision, method = method, ...) + precision, + method = method, ... + ) out[[1]] <- NULL attr(out, "data") <- x out diff --git a/tests/testthat/test-blavaan.R b/tests/testthat/test-blavaan.R index cf30057c1..da0125acd 100644 --- a/tests/testthat/test-blavaan.R +++ b/tests/testthat/test-blavaan.R @@ -82,19 +82,19 @@ test_that("blavaan, all", { x <- suppressWarnings(weighted_posteriors(bfit, bfit2)) expect_identical(ncol(x), 14L) - # bfit_prior <- unupdate(bfit) - # capture.output(x <- expect_warning(bayesfactor_parameters(bfit, prior = bfit_prior))) - # expect_identical(nrow(x), 14L) - # - # x <- expect_warning(si(bfit, prior = bfit_prior)) - # expect_identical(nrow(x), 14L) - # - # ## Prior/posterior checks ---- - # suppressWarnings(x <- check_prior(bfit)) - # expect_equal(nrow(x), 13) - # - # x <- check_prior(bfit, simulate_priors = FALSE) - # expect_identical(nrow(x), 14L) + bfit_prior <- unupdate(bfit) + capture.output(x <- expect_warning(bayesfactor_parameters(bfit, prior = bfit_prior))) + expect_identical(nrow(x), 14L) + + x <- expect_warning(si(bfit, prior = bfit_prior)) + expect_identical(nrow(x), 14L) + + ## Prior/posterior checks ---- + suppressWarnings(x <- check_prior(bfit)) + expect_equal(nrow(x), 13) + + x <- check_prior(bfit, simulate_priors = FALSE) + expect_identical(nrow(x), 14L) x <- diagnostic_posterior(bfit) expect_identical(nrow(x), 14L) @@ -107,6 +107,6 @@ test_that("blavaan, all", { expect_identical(nrow(x), 13L) # YES this is 13! We have two parameters with the same prior. - # x <- describe_posterior(bfit, test = "all", rope_range = c(-0.1, 0.1)) - # expect_identical(nrow(x), 14L) + x <- describe_posterior(bfit, test = "all", rope_range = c(-0.1, 0.1)) + expect_identical(nrow(x), 14L) }) diff --git a/tests/testthat/test-different_models.R b/tests/testthat/test-different_models.R index fdc4e5116..feec60e4d 100644 --- a/tests/testthat/test-different_models.R +++ b/tests/testthat/test-different_models.R @@ -26,14 +26,14 @@ test_that("insight::get_predicted", { rez <- p_direction(x) expect_equal(c(nrow(rez), ncol(rez)), c(32, 2)) - # rez <- p_map(x) - # expect_equal(c(nrow(rez), ncol(rez)), c(2, 2)) - # - # rez <- p_significance(x) - # expect_equal(c(nrow(rez), ncol(rez)), c(2, 2)) - # - # rez <- rope(x) - # expect_equal(c(nrow(rez), ncol(rez)), c(2, 5)) + rez <- p_map(x) + expect_equal(c(nrow(rez), ncol(rez)), c(2, 2)) + + rez <- p_significance(x) + expect_equal(c(nrow(rez), ncol(rez)), c(2, 2)) + + rez <- rope(x) + expect_equal(c(nrow(rez), ncol(rez)), c(2, 5)) rez <- describe_posterior(x) expect_equal(c(nrow(rez), ncol(rez)), c(32, 5)) diff --git a/tests/testthat/test-rope.R b/tests/testthat/test-rope.R index 740172614..fa837eb2b 100644 --- a/tests/testthat/test-rope.R +++ b/tests/testthat/test-rope.R @@ -18,7 +18,6 @@ test_that("rope", { expect_equal(equivalence_test(distribution_normal(1000, 0, 0.001), ci = 1)$ROPE_Equivalence, "Accepted") - # print(rope(rnorm(1000, mean = 0, sd = 3), ci = .5)) expect_equal(rope(rnorm(1000, mean = 0, sd = 3), ci = c(.1, .5, .9), verbose = FALSE)$CI, c(.1, .5, .9)) x <- equivalence_test(distribution_normal(1000, 1, 1), ci = c(.50, .99)) @@ -71,31 +70,31 @@ test_that("rope", { }) -# if ( skip_if_not_or_load_if_installed("brms")) { -# set.seed(123) -# model <- brm(mpg ~ wt + gear, data = mtcars, iter = 500) -# rope <- rope(model, verbose = FALSE) -# -# test_that("rope (brms)", { -# expect_equal(rope$ROPE_high, -rope$ROPE_low, tolerance = 0.01) -# expect_equal(rope$ROPE_high[1], 0.6026948) -# expect_equal(rope$ROPE_Percentage, c(0.00, 0.00, 0.50), tolerance = 0.1) -# }) -# -# model <- brm(mvbind(mpg, disp) ~ wt + gear, data = mtcars, iter = 500) -# rope <- rope(model, verbose = FALSE) -# -# test_that("rope (brms, multivariate)", { -# expect_equal(rope$ROPE_high, -rope$ROPE_low, tolerance = 0.01) -# expect_equal(rope$ROPE_high[1], 0.6026948, tolerance = 0.01) -# expect_equal(rope$ROPE_high[4], 12.3938694, tolerance = 0.01) -# expect_equal( -# rope$ROPE_Percentage, -# c(0, 0, 0.493457, 0.072897, 0, 0.508411), -# tolerance = 0.1 -# ) -# }) -# } +skip_if_not_or_load_if_installed("brms") +set.seed(123) +model <- brm(mpg ~ wt + gear, data = mtcars, iter = 500) +rope <- rope(model, verbose = FALSE) + +test_that("rope (brms)", { + expect_equal(rope$ROPE_high, -rope$ROPE_low, tolerance = 0.01) + expect_equal(rope$ROPE_high[1], 0.6026948) + expect_equal(rope$ROPE_Percentage, c(0.00, 0.00, 0.50), tolerance = 0.1) +}) + +model <- brm(mvbind(mpg, disp) ~ wt + gear, data = mtcars, iter = 500) +rope <- rope(model, verbose = FALSE) + +test_that("rope (brms, multivariate)", { + expect_equal(rope$ROPE_high, -rope$ROPE_low, tolerance = 0.01) + expect_equal(rope$ROPE_high[1], 0.6026948, tolerance = 0.01) + expect_equal(rope$ROPE_high[4], 12.3938694, tolerance = 0.01) + expect_equal( + rope$ROPE_Percentage, + c(0, 0, 0.493457, 0.072897, 0, 0.508411), + tolerance = 0.1 + ) +}) + test_that("BayesFactor", { skip_if_not_or_load_if_installed("BayesFactor")