posterior_predict: Generic function for drawing from the posterior predictive...

Description Usage Arguments Value See Also Examples

View source: R/posterior_predict.R

Description

Draw from the posterior predictive distribution of the outcome. See posterior_predict.stanreg in the rstanarm package for an example.

Usage

1

Arguments

object

The object to use.

...

Arguments passed to methods. See the methods in the rstanarm package for examples.

Value

posterior_predict methods should return a D by N matrix, where D is the number of draws from the posterior predictive distribution and N is the number of data points being predicted per draw.

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Example using rstanarm package:
# posterior_predict method for 'stanreg' objects

if (require("rstanarm")) {
  fit <- stan_glm(mpg ~ wt + am, data = mtcars)
  yrep <- posterior_predict(fit)
  all.equal(ncol(yrep), nobs(fit))

  nd <- data.frame(wt = mean(mtcars$wt), am = c(0, 1))
  ytilde <- posterior_predict(fit, newdata = nd)
  all.equal(ncol(ytilde), nrow(nd))
}


# Also see help("posterior_predict", package = "rstanarm")

stan-dev/rstantools documentation built on Dec. 6, 2018, 11:24 p.m.