Skip to content

Commit

Permalink
styler
Browse files Browse the repository at this point in the history
  • Loading branch information
mattansb committed Sep 4, 2024
1 parent a872a71 commit 5078773
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion R/describe_posterior.R
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ describe_posterior.slopes <- function(posterior,
verbose = TRUE,
...) {
if (any(c("all", "bf", "bayesfactor", "bayes_factor") %in% tolower(test)) ||
"si" %in% tolower(ci_method)) {
"si" %in% tolower(ci_method)) {
samps <- .clean_priors_and_posteriors(posterior, bf_prior, verbose = verbose)
bf_prior <- samps$prior
posterior_samples <- samps$posterior
Expand Down
41 changes: 24 additions & 17 deletions tests/testthat/test-marginaleffects.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

test_that("emmGrid descrive_posterior", {
skip_on_ci()
skip_on_cran()
Expand All @@ -13,27 +12,34 @@ test_that("emmGrid descrive_posterior", {
mfx <- marginaleffects::avg_slopes(mod, by = "am")
mfx_samps <- as.data.frame(t(attr(mfx, "posterior_draws")))

results <- describe_posterior(mfx, centrality = "MAP", ci_method = "hdi",
test = c("pd", "rope", "p_map", "equivalence_test"))
results_draws <- describe_posterior(mfx_samps, centrality = "MAP", ci_method = "hdi",
test = c("pd", "rope", "p_map", "equivalence_test"))
results <- describe_posterior(mfx,
centrality = "MAP", ci_method = "hdi",
test = c("pd", "rope", "p_map", "equivalence_test")
)
results_draws <- describe_posterior(mfx_samps,
centrality = "MAP", ci_method = "hdi",
test = c("pd", "rope", "p_map", "equivalence_test")
)

expect_true(all(c("term", "contrast") %in% colnames(results)))
expect_equal(results[setdiff(colnames(results), c("term", "contrast"))],
results_draws[setdiff(colnames(results_draws), "Parameter")],
ignore_attr = TRUE)
results_draws[setdiff(colnames(results_draws), "Parameter")],
ignore_attr = TRUE
)

# estimate_density
mfx <- marginaleffects::comparisons(mod, variables = "cyl",
newdata = data.frame(hp = 100, am = 0))
mfx <- marginaleffects::comparisons(mod,
variables = "cyl",
newdata = data.frame(hp = 100, am = 0)
)
samps <- insight::get_parameters(mod)[c("cyl6", "cyl8")]

res <- estimate_density(mfx)
resref <- estimate_density(samps)
expect_equal(res[intersect(colnames(res), colnames(resref))],
resref[intersect(colnames(res), colnames(resref))],
ignore_attr = TRUE)

resref[intersect(colnames(res), colnames(resref))],
ignore_attr = TRUE
)
})

test_that("emmGrid bayesfactors", {
Expand All @@ -60,14 +66,15 @@ test_that("emmGrid bayesfactors", {

expect_true(all(c("term", "contrast") %in% colnames(outsi)))
expect_equal(outsi[setdiff(colnames(outsi), c("term", "contrast"))],
outsiref[setdiff(colnames(outsiref), "Parameter")],
ignore_attr = TRUE)
outsiref[setdiff(colnames(outsiref), "Parameter")],
ignore_attr = TRUE
)

# bayesfactor_parameters
bfp <- bayesfactor_parameters(mfx, prior = mfxp, verbose = FALSE)
bfpref <- bayesfactor_parameters(mfx_samps, prior = mfxp_samps, verbose = FALSE)
expect_equal(bfp[setdiff(colnames(bfp), c("term", "contrast"))],
bfpref[setdiff(colnames(bfpref), "Parameter")],
ignore_attr = TRUE)

bfpref[setdiff(colnames(bfpref), "Parameter")],
ignore_attr = TRUE
)
})

0 comments on commit 5078773

Please sign in to comment.