From 329a6ae8b0b0208c98a2ea5a7d9e16eb667d4623 Mon Sep 17 00:00:00 2001 From: Sandhu-SS Date: Sun, 18 Oct 2026 17:57:23 +0530 Subject: [PATCH 1/2] fix: support multivariate brms predictions --- R/brms-functions.R | 3 ++- tests/testthat/test_predictions_as_draws.R | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/testthat/test_predictions_as_draws.R diff --git a/R/brms-functions.R b/R/brms-functions.R index 4f8b947..09580fc 100644 --- a/R/brms-functions.R +++ b/R/brms-functions.R @@ -51,8 +51,9 @@ predictions_as_draws <- function( } pred_draws <- list() predictions <- predict_fn(x, ...) + dim_pred <- dim(predictions) if (!(mv)) { - dim_pred <- dim(predictions) + # dim_pred <- dim(predictions) # Moved up before if (!(mv)) { if (length(dim_pred) == 3) { if (warn_dims) { warning( diff --git a/tests/testthat/test_predictions_as_draws.R b/tests/testthat/test_predictions_as_draws.R new file mode 100644 index 0000000..45c61fc --- /dev/null +++ b/tests/testthat/test_predictions_as_draws.R @@ -0,0 +1,18 @@ +testthat::test_that( + "predictions_as_draws handles multivariate brms models", + { + testthat::skip_if_not_installed("brms") + + data("BTdata", package = "MCMCglmm") + head(BTdata) + + suppressWarnings({ + bform1 <- brms::bf(mvbind(tarsus, back) ~ sex + hatchdate + (1|p|fosternest) + (1|q|dam)) + brms::set_rescor(TRUE) + fit1 <- brms::brm(bform1, data = BTdata, chains = 2, cores = 2, iter = 10) + }) + + result <- priorsense::predictions_as_draws(fit1, brms::posterior_epred) + + testthat::expect_s3_class(result, "draws") + } +) From 360dca28d40b5a1158a29a70ee4c7035f417f12e Mon Sep 17 00:00:00 2001 From: Sandhu-SS Date: Mon, 19 Oct 2026 09:15:09 +0530 Subject: [PATCH 2/2] test: use base R data for multivariate brms regression --- R/brms-functions.R | 1 - tests/testthat/test_predictions_as_draws.R | 15 ++++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/R/brms-functions.R b/R/brms-functions.R index 09580fc..6d67c41 100644 --- a/R/brms-functions.R +++ b/R/brms-functions.R @@ -53,7 +53,6 @@ predictions_as_draws <- function( predictions <- predict_fn(x, ...) dim_pred <- dim(predictions) if (!(mv)) { - # dim_pred <- dim(predictions) # Moved up before if (!(mv)) { if (length(dim_pred) == 3) { if (warn_dims) { warning( diff --git a/tests/testthat/test_predictions_as_draws.R b/tests/testthat/test_predictions_as_draws.R index 45c61fc..f99566f 100644 --- a/tests/testthat/test_predictions_as_draws.R +++ b/tests/testthat/test_predictions_as_draws.R @@ -1,17 +1,18 @@ testthat::test_that( - "predictions_as_draws handles multivariate brms models", + "predictions_as_draws_multivariate handles multivariate brms models", { testthat::skip_if_not_installed("brms") - data("BTdata", package = "MCMCglmm") - head(BTdata) - suppressWarnings({ - bform1 <- brms::bf(mvbind(tarsus, back) ~ sex + hatchdate + (1|p|fosternest) + (1|q|dam)) + brms::set_rescor(TRUE) - fit1 <- brms::brm(bform1, data = BTdata, chains = 2, cores = 2, iter = 10) + fit <- brms::brm( + brms::bf(mpg ~ wt) + brms::bf(disp ~ wt) + brms::set_rescor(TRUE), + data = mtcars, + chains = 1, + iter = 10, + refresh = 0) }) - result <- priorsense::predictions_as_draws(fit1, brms::posterior_epred) + result <- priorsense::predictions_as_draws(fit, brms::posterior_epred) testthat::expect_s3_class(result, "draws") }