Learn R Programming

conformalbayes (version 0.1.4)

loo_conformal: Enable leave-one-out conformal predictive intervals for a fit model

Description

Prepares for jackknife(+) conformal prediction by performing Pareto-smoothed importance sampling to yield leave-one-out residuals.

Usage

loo_conformal(fit, ...)

# S3 method for default loo_conformal( fit, truth, chain = NULL, trans = function(x) x, inv_trans = function(x) x, est_fun = c("mean", "median"), ... )

# S3 method for stanreg loo_conformal( fit, trans = function(x) x, inv_trans = function(x) x, est_fun = c("mean", "median"), ... )

# S3 method for brmsfit loo_conformal( fit, trans = function(x) x, inv_trans = function(x) x, est_fun = c("mean", "median"), ... )

Value

A modified fit object with an additional class conformal. Calling predictive_interval() on this new object will yield conformal intervals.

Arguments

fit

Model fit; an object with posterior_predict() and log_lik() methods. Can also be an array of posterior predictions.

...

Ignored.

truth

True values to predict. Not required for rstanarm or brms models.

chain

An integer vector identifying the chain numbers for the posterior draws. Should be provided if multiple chains are used.

trans, inv_trans

A pair of functions to transform the predictions before performing conformal inference.

est_fun

Whether to use the posterior mean (the default) or median as a point estimate.

References

Vehtari, A., Simpson, D., Gelman, A., Yao, Y., & Gabry, J. (2015). Pareto smoothed importance sampling. arXiv preprint arXiv:1507.02646.

Examples

Run this code
 # takes several seconds
if (requireNamespace("rstanarm", quietly=TRUE)) suppressWarnings({
    library(rstanarm)
    # fit a simple linear regression
    m = stan_glm(mpg ~ disp + cyl, data=mtcars,
        chains=1, iter=500,
        control=list(adapt_delta=0.999), refresh=0)

    loo_conformal(m)
})


Run the code above in your browser using DataLab