Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

predictive_interval.stanreg

Predictive intervals


Description

For models fit using MCMC (algorithm="sampling") or one of the variational approximations ("meanfield" or "fullrank"), the predictive_interval function computes Bayesian predictive intervals. The method for stanreg objects calls posterior_predict internally, whereas the method for objects of class "ppd" accepts the matrix returned by posterior_predict as input and can be used to avoid multiple calls to posterior_predict.

Usage

## S3 method for class 'stanreg'
predictive_interval(
  object,
  prob = 0.9,
  newdata = NULL,
  draws = NULL,
  re.form = NULL,
  fun = NULL,
  seed = NULL,
  offset = NULL,
  ...
)

## S3 method for class 'ppd'
predictive_interval(object, prob = 0.9, ...)

Arguments

object

Either a fitted model object returned by one of the rstanarm modeling functions (a stanreg object) or, for the "ppd" method, a matrix of draws from the posterior predictive distribution returned by posterior_predict.

prob

A number p (0 < p < 1) indicating the desired probability mass to include in the intervals. The default is to report 90% intervals (prob=0.9) rather than the traditionally used 95% (see Details).

newdata, draws, fun, offset, re.form, seed

Passed to posterior_predict.

...

Currently ignored.

Value

A matrix with two columns and as many rows as are in newdata. If newdata is not provided then the matrix will have as many rows as the data used to fit the model. For a given value of prob, p, the columns correspond to the lower and upper 100p% central interval limits and have the names 100α/2% and 100(1 - α/2)%, where α = 1-p. For example, if prob=0.9 is specified (a 90% interval), then the column names will be "5%" and "95%", respectively.

See Also

Examples

fit <- stan_glm(mpg ~ wt, data = mtcars, iter = 300)
predictive_interval(fit)
predictive_interval(fit, newdata = data.frame(wt = range(mtcars$wt)), 
                    prob = 0.5)

# stanreg vs ppd methods
preds <- posterior_predict(fit, seed = 123)
all.equal(
  predictive_interval(fit, seed = 123),
  predictive_interval(preds)
)

rstanarm

Bayesian Applied Regression Modeling via Stan

v2.21.1
GPL (>= 3)
Authors
Jonah Gabry [aut], Imad Ali [ctb], Sam Brilleman [ctb], Jacqueline Buros Novik [ctb] (R/stan_jm.R), AstraZeneca [ctb] (R/stan_jm.R), Trustees of Columbia University [cph], Simon Wood [cph] (R/stan_gamm4.R), R Core Deveopment Team [cph] (R/stan_aov.R), Douglas Bates [cph] (R/pp_data.R), Martin Maechler [cph] (R/pp_data.R), Ben Bolker [cph] (R/pp_data.R), Steve Walker [cph] (R/pp_data.R), Brian Ripley [cph] (R/stan_aov.R, R/stan_polr.R), William Venables [cph] (R/stan_polr.R), Paul-Christian Burkner [cph] (R/misc.R), Ben Goodrich [cre, aut]
Initial release
2020-07-20

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.