predictive_interval.stapreg: Predictive intervals

Description Usage Arguments Value See Also Examples

View source: R/predictive_interval.R

Description

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.

Usage

1
2
3
4
5
6
7
8
## S3 method for class '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 class '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.

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% .

newsubjdata

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.

newdistdata

If newsubjdata is provided a data frame of the subject-distance must also be given for models with a spatial component

newtimedata

If newsubjdata is provided, a data frame of the subject-time data

draws, fun, offset, re.form, seed

Passed to posterior_predict.

subject_ID

same as stap_glm

group_ID

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α/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

predictive_error, posterior_predict, posterior_interval

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
if (!exists("example_model")) example(example_model)

predictive_interval(example_model)
newdata <- 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")

rstap documentation built on May 1, 2019, 9:21 p.m.