File: pp_check.Rd

package info (click to toggle)
r-cran-bayesplot 1.11.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,080 kB
  • sloc: sh: 13; makefile: 2
file content (71 lines) | stat: -rw-r--r-- 2,888 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/pp_check.R
\name{pp_check}
\alias{pp_check}
\alias{pp_check.default}
\title{Posterior (or prior) predictive checks (S3 generic and default method)}
\usage{
pp_check(object, ...)

\method{pp_check}{default}(object, yrep, fun, ...)
}
\arguments{
\item{object}{Typically a fitted model object. The default method, however,
takes \code{object} to be a \code{y} (outcome) vector.}

\item{...}{For the generic, arguments passed to individual methods. For the
default method, these are additional arguments to pass to \code{fun}.}

\item{yrep}{For the default method, a \code{yrep} matrix passed to \code{fun}.}

\item{fun}{For the default method, the plotting function to call. Can be any
of the \link{PPC} functions. The \code{"ppc_"} prefix can optionally be dropped if
\code{fun} is specified as a string.}
}
\value{
The exact form of the value returned by \code{pp_check()} may vary by
the class of \code{object}, but for consistency we encourage authors of
methods to return the ggplot object created by one of \strong{bayesplot}'s
plotting functions. The default method returns the object returned by \code{fun}.
}
\description{
S3 generic with simple default method. The intent is to provide a generic so
authors of other \R packages who wish to provide interfaces to the functions
in \strong{bayesplot} will be encouraged to include \code{pp_check()} methods in their
package, preserving the same naming conventions for posterior (and prior)
predictive checking across many \R packages for Bayesian inference. This is
for the convenience of both users and developers. See the \strong{Details} and
\strong{Examples} sections, below, and the package vignettes for examples of
defining \code{pp_check()} methods.
}
\details{
A package that creates fitted model objects of class \code{"foo"}
can include a method \code{pp_check.foo()} that prepares the appropriate
inputs (\code{y}, \code{yrep}, etc.) for the \strong{bayesplot} functions. The
\code{pp_check.foo()} method may, for example, let the user choose between
various plots, calling the functions from \strong{bayesplot} internally as
needed. See \strong{Examples}, below, and the package vignettes.
}
\examples{
# default method
y <- example_y_data()
yrep <- example_yrep_draws()
pp_check(y, yrep[1:50,], ppc_dens_overlay)

g <- example_group_data()
pp_check(y, yrep, fun = "stat_grouped", group = g, stat = "median")

# defining a method
x <- list(y = rnorm(50), yrep = matrix(rnorm(5000), nrow = 100, ncol = 50))
class(x) <- "foo"
pp_check.foo <- function(object, ..., type = c("multiple", "overlaid")) {
  y <- object[["y"]]
  yrep <- object[["yrep"]]
  switch(match.arg(type),
         multiple = ppc_hist(y, yrep[1:min(8, nrow(yrep)),, drop = FALSE]),
         overlaid = ppc_dens_overlay(y, yrep))
}
pp_check(x)
pp_check(x, type = "overlaid")

}