Skip to content

Commit

Permalink
fix #688
Browse files Browse the repository at this point in the history
  • Loading branch information
mattansb committed Dec 17, 2024
1 parent c1e9392 commit 90eb057
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: bayestestR
Title: Understand and Describe Bayesian Models and Posterior Distributions
Version: 0.15.0.3
Version: 0.15.0.4
Authors@R:
c(person(given = "Dominique",
family = "Makowski",
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# bayestestR 0.15.0.4

## Bug fixes

* Fix to `emmeans` / `marginaleffects` / `data.frame(<rvar>)` methods when using multiple credible levels (#688).


# bayestestR 0.15.0

## Changes
Expand Down
4 changes: 2 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
datagrid <- insight::get_datagrid(object)
grid_names <- colnames(datagrid)

if (long) {
if (long || nrow(datagrid) < nrow(results)) {
datagrid$Parameter <- unique(results$Parameter)
results <- datawizard::data_merge(datagrid, results, by = "Parameter")
results$Parameter <- NULL
Expand Down Expand Up @@ -270,7 +270,7 @@
grid_names <- colnames(object)[!is_rvar]
datagrid <- data.frame(object[, grid_names, drop = FALSE])

if (long) {
if (long || nrow(datagrid) < nrow(results)) {
datagrid$Parameter <- unique(results$Parameter)
results <- datawizard::data_merge(datagrid, results, by = "Parameter")
results$Parameter <- NULL
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-data.frame-with-rvar.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ test_that("data.frame w/ rvar_col descrive_posterior etc", {
res <- eti(dfx, rvar_col = "my_rvar", ci = c(0.8, 0.95))
res.ref <- eti(dfx$my_rvar, ci = c(0.8, 0.95))
expect_true(all(c("mu", "sigma") %in% colnames(res)))
expect_identical(as.data.frame(res[c("mu", "sigma")]),
data.frame(mu = c(0, 0, 0.5, 0.5, 1, 1),
sigma = c(1, 1, 0.5, 0.5, 0.25, 0.25)))
expect_identical(nrow(format(res)), 3L)
expect_identical(ncol(format(res)), 4L)
expect_equal(res[setdiff(colnames(res), c("mu", "sigma"))],
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-emmGrid.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ test_that("emmGrid hdi", {

xhdi2 <- hdi(emc_, ci = 0.95)
expect_equal(xhdi$CI_low, xhdi2$CI_low)

Check warning on line 33 in tests/testthat/test-emmGrid.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-emmGrid.R,line=33,col=3,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=.

xhdi3 <- hdi(all_, ci = c(0.9, 0.95))
expect_equal(as.data.frame(xhdi3[1:2]),

Check warning on line 36 in tests/testthat/test-emmGrid.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-emmGrid.R,line=36,col=3,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=.
data.frame(group = c("1", "1", "2", "2", ".", "."),

Check warning on line 37 in tests/testthat/test-emmGrid.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-emmGrid.R,line=37,col=16,[strings_as_factors_linter] Supply an explicit value for stringsAsFactors for this code to work before and after R version 4.0.
contrast = c(".", ".", ".", ".", "group1 - group2", "group1 - group2")))
})

test_that("emmGrid point_estimate", {
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-marginaleffects.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ withr::with_environment(
ignore_attr = TRUE
)

# multi ci levels
res <- hdi(mfx, ci = c(0.8, 0.9))
expect_equal(as.data.frame(res[1:3]),
data.frame(term = c("am", "am", "am", "am", "cyl", "cyl",
"cyl", "cyl", "cyl", "cyl", "cyl", "cyl",
"hp", "hp", "hp", "hp"),
contrast = c("1 - 0", "1 - 0", "1 - 0", "1 - 0",
"6 - 4", "6 - 4", "8 - 4", "8 - 4",
"6 - 4", "6 - 4", "8 - 4", "8 - 4",
"dY/dX", "dY/dX", "dY/dX", "dY/dX"),
am = c(0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0,
1, 1)))

# estimate_density
mfx <- marginaleffects::comparisons(mod,
variables = "cyl",
Expand Down

0 comments on commit 90eb057

Please sign in to comment.