The predictive_interval function computes Bayesian predictive intervals. The method for stapreg 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.

# S3 method for stapreg
predictive_interval(object, prob = 0.9,
newsubjdata = NULL, newdistdata = NULL, newtimedata = NULL,
draws = NULL, subject_ID = NULL, group_ID = NULL, re.form = NULL,
fun = NULL, seed = NULL, offset = NULL, ...)

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

## Arguments

object Either a fitted model object returned by one of the rstap modeling functions (a stapreg object) or, for the "ppd" method, a matrix of draws from the posterior predictive distribution returned by posterior_predict. A number $$p \in (0,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$$% . Optionally, a data frame of the subject-specific data in which to look for variables with which to predict. If omitted, the original datasets are used. If newsubjdata is provided and any variables were transformed (e.g. rescaled) in the data used to fit the model, then these variables must also be transformed in newsubjdata. This only applies if variables were transformed before passing the data to one of the modeling functions and not if transformations were specified inside the model formula. Also see the Note section below for a note about using the newsubjdata argument with with binomial models. If newsubjdata is provided a data frame of the subject-distance must also be given for models with a spatial component If newsubjdata is provided, a data frame of the subject-time data Passed to posterior_predict. same as stap_glm same as stap_glmer Currently ignored.

## Value

A matrix with two columns and as many rows as are in newsubjdata. If newsubjdata 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\alpha/2$$% and $$100(1 - \alpha/2)$$%, where $$\alpha = 1-p$$. For example, if prob=0.9 is specified (a $$90$$% interval), then the column names will be "5%" and "95%", respectively.

predictive_error, posterior_predict, posterior_interval

## Examples

if (!exists("example_model")) example(example_model)

predictive_interval(example_model)#>             5%       95%
#> 1  -0.91361950 0.5923939
#> 2   0.38982645 1.8163569
#> 3  -0.68441754 1.3982590
#> 4  -0.52202020 1.0468239
#> 5  -0.98687036 1.0890773
#> 6  -0.84245759 1.0759630
#> 7  -0.75337265 0.8983179
#> 8  -0.29379107 1.1993876
#> 9  -0.31435650 1.3375969
#> 10 -0.96855691 1.4766913
#> 11 -1.10827140 0.5568126
#> 12 -0.03448876 1.5262871
#> 13 -0.28995199 1.1379683
#> 14 -0.07574048 1.0876035
#> 15 -0.54809164 1.3042049
#> 16 -0.51060592 1.0289610
#> 17 -0.19669231 1.6501689
#> 18 -0.63965550 1.2795562
#> 19 -0.35125135 0.8809490newdata <- data.frame(subj_ID = c(1,1), measure_ID = c(1,2),
centered_income = c(-1,-.7), sex = c(0,0),
centered_age = c(-1,-.7))
# newdata
predictive_interval(example_model, newsubjdata = newdata,
newdistdata = distdata,
newtimedata = timedata,
subject_ID = "subj_ID",
group_ID = "measure_ID")#>           5%       95%
#> 1 -0.5953371 1.1372906
#> 2 -0.8271130 0.9755302