Skip to content

Commit d1e452e

Browse files
authored
Merge pull request #543 from ishaan-arora-1/fix/ppc-accept-draws-objects-542
Accept posterior::draws objects in PPC/PPD functions
2 parents 009d7ec + c3fc6f2 commit d1e452e

15 files changed

Lines changed: 166 additions & 69 deletions

R/helpers-ppc.R

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,20 @@ validate_y <- function(y) {
5858
#' Validate predictions (`yrep` or `ypred`)
5959
#'
6060
#' Checks that `predictions` is a numeric matrix, doesn't have any NAs, and has
61-
#' the correct number of columns.
61+
#' the correct number of columns. If `predictions` is a `posterior::draws`
62+
#' object it is first coerced to a matrix.
6263
#'
63-
#' @param predictions The user's `yrep` or `ypred` object (SxN matrix).
64+
#' @param predictions The user's `yrep` or `ypred` object (SxN matrix or a
65+
#' `posterior::draws` object).
6466
#' @param `n_obs` The number of observations (columns) that `predictions` should
6567
#' have, if applicable.
6668
#' @return Either throws an error or returns a numeric matrix.
6769
#' @noRd
6870
validate_predictions <- function(predictions, n_obs = NULL) {
69-
# sanity checks
71+
if (posterior::is_draws(predictions)) {
72+
predictions <- posterior::as_draws_matrix(predictions)
73+
predictions <- unclass(predictions)
74+
}
7075
stopifnot(is.matrix(predictions), is.numeric(predictions))
7176
if (!is.null(n_obs)) {
7277
stopifnot(length(n_obs) == 1, n_obs == as.integer(n_obs))

man-roxygen/args-y-yrep.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#' @param y A vector of observations. See **Details**.
22
#' @param yrep An `S` by `N` matrix of draws from the posterior (or prior)
3-
#' predictive distribution. The number of rows, `S`, is the size of the
4-
#' posterior (or prior) sample used to generate `yrep`. The number of columns,
5-
#' `N` is the number of predicted observations (`length(y)`). The columns of
6-
#' `yrep` should be in the same order as the data points in `y` for the plots
7-
#' to make sense. See the **Details** and **Plot Descriptions** sections for
8-
#' additional advice specific to particular plots.
3+
#' predictive distribution, or a [`posterior::draws`] object. The number of
4+
#' rows, `S`, is the size of the posterior (or prior) sample used to generate
5+
#' `yrep`. The number of columns, `N` is the number of predicted observations
6+
#' (`length(y)`). The columns of `yrep` should be in the same order as the
7+
#' data points in `y` for the plots to make sense. See the **Details** and
8+
#' **Plot Descriptions** sections for additional advice specific to particular
9+
#' plots.

man-roxygen/args-ypred.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#' @param ypred An `S` by `N` matrix of draws from the posterior (or prior)
2-
#' predictive distribution. The number of rows, `S`, is the size of the
3-
#' posterior (or prior) sample used to generate `ypred`. The number of
4-
#' columns, `N`, is the number of predicted observations.
2+
#' predictive distribution, or a [`posterior::draws`] object. The number of
3+
#' rows, `S`, is the size of the posterior (or prior) sample used to generate
4+
#' `ypred`. The number of columns, `N`, is the number of predicted
5+
#' observations.

man/PPC-censoring.Rd

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/PPC-discrete.Rd

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/PPC-distributions.Rd

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/PPC-errors.Rd

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/PPC-intervals.Rd

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/PPC-loo.Rd

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/PPC-scatterplots.Rd

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)