Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: modelbased
Title: Estimation of Model-Based Predictions, Contrasts and Means
Version: 0.17.0.18
Version: 0.17.0.19
Authors@R:
c(person(given = "Dominique",
family = "Makowski",
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@
`estimate_contrasts()` now uses the names of the response variables, not
their observed values, to find the response in the contrast labels.

* `estimate_contrasts()` now returns separate `Response1` and `Response2`
columns for multivariate *brms* models with dots in the response names, for
example `mvbind(Sepal.Length, Petal.Length) ~ Species`. Before, the response
names stayed in the `Level1` and `Level2` columns, because *brms* removes the
dots from the response names.

* The `grid` argument of `visualisation_recipe()` and `plot()` now changes the
facet grid of plots with four or more `by` variables. Before, these functions
applied the `facet` argument to the facet grid instead. If `facet` was not
Expand Down
10 changes: 9 additions & 1 deletion R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,15 @@ format.marginaleffects_contrasts <- function(
response_levels <- unique(as.character(response))
}
if (is_multivariate) {
response_levels <- unique(c(response_levels, insight::find_response(model)))
# brms drops dots from response names (e.g., "Sepal.Length" becomes
# "SepalLength"), and uses these names in the contrast labels. The names
# of `find_response()` hold these brms names
model_response <- insight::find_response(model)
response_levels <- unique(c(
response_levels,
model_response,
names(model_response)
))
}
if (!length(response_levels)) {
return(params)
Expand Down
21 changes: 21 additions & 0 deletions tests/testthat/test-brms.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,27 @@ test_that("estimate_contrasts - brms, multivariate, many observations", {
})


test_that("estimate_contrasts - brms, multivariate, response names with dots", {
# brms drops the dot from response names ("Sepal.Length" -> "SepalLength"),
# and the contrast labels use the brms names
m <- suppressWarnings(brms::brm(
brms::mvbind(Sepal.Length, Petal.Length) ~ Species,
data = iris,
refresh = 0,
iter = 500,
chains = 1,
seed = 123
))

out <- estimate_contrasts(m, "Species")
expect_identical(nrow(out), 15L)
expect_true(all(c("Response1", "Response2") %in% colnames(out)))
expect_identical(levels(out$Response1), c("SepalLength", "PetalLength"))
expect_true(all(as.character(out$Level1) %in% levels(iris$Species)))
expect_true(all(as.character(out$Level2) %in% levels(iris$Species)))
})


test_that("estimate_means - brms, Wiener", {
skip_if_not_installed("curl")
skip_if_offline()
Expand Down
Loading