
Last chance! 50% off unlimited learning
Sale ends in
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 matrices accepts the matrix returned by
posterior_predict
as input and can be used to avoid multiple calls to
posterior_predict
.
# S3 method for stanreg
predictive_interval(
object,
prob = 0.9,
newdata = NULL,
draws = NULL,
re.form = NULL,
fun = NULL,
seed = NULL,
offset = NULL,
...
)# S3 method for matrix
predictive_interval(object, prob = 0.9, ...)
# S3 method for ppd
predictive_interval(object, prob = 0.9, ...)
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
, prob=0.9
is
specified (a
"5%"
and "95%"
, respectively.
Either a fitted model object returned by one of the
rstanarm modeling functions (a stanreg
object) or, for the matrix method, a matrix of draws from the
posterior predictive distribution returned by
posterior_predict
.
A number prob=0.9
) rather than the traditionally used
Passed to
posterior_predict
.
Currently ignored.
predictive_error
, posterior_predict
,
posterior_interval
if (.Platform$OS.type != "windows" || .Platform$r_arch != "i386") {
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 matrix methods
preds <- posterior_predict(fit, seed = 123)
all.equal(
predictive_interval(fit, seed = 123),
predictive_interval(preds)
)
}
Run the code above in your browser using DataLab