Giter VIP home page Giter VIP logo

conformalbayes's Introduction

conformalbayes

CRAN status Lifecycle: experimental License: MIT R-CMD-check

conformalbayes provides functions to construct finite-sample calibrated predictive intervals for Bayesian models, following the approach in Barber et al. (2021). These intervals are calculated efficiently using importance sampling for the leave-one-out residuals. By default, the intervals will also reflect the relative uncertainty in the Bayesian model, using the locally-weighted conformal methods of Lei et al. (2018).

Installation

You can install the development version of conformalbayes with:

# install.packages("devtools")
devtools::install_github("CoryMcCartan/conformalbayes")

Example

library(rstanarm)
library(conformalbayes)
data("Loblolly")

fit_idx = sample(nrow(Loblolly), 50)
d_fit = Loblolly[fit_idx, ]
d_test = Loblolly[-fit_idx, ]

# fit a simple linear regression
m = stan_glm(height ~ sqrt(age), data=d_fit,
    chains=1, control=list(adapt_delta=0.999), refresh=0)

# prepare conformal predictions
m = loo_conformal(m)

# make predictive intervals
pred_ci = predictive_interval(m, newdata=d_test, prob=0.9)
print(head(pred_ci))
#>             5%       95%
#> 1  -0.15888597  5.600095
#> 29 25.43314599 30.988491
#> 57 48.67648127 54.182655
#> 2  -0.09561987  5.447242
#> 30 25.42970114 30.938488
#> 72 58.01173186 63.596592

# are we covering?
mean(pred_ci[, "5%"] <= d_test$height &
         d_test$height <= pred_ci[, "95%"])
#> [1] 0.9117647

Read more on the Getting Started page.

Citations

Barber, R. F., Candes, E. J., Ramdas, A., & Tibshirani, R. J. (2021). Predictive inference with the jackknife+. The Annals of Statistics, 49(1), 486-507.

Lei, J., G’Sell, M., Rinaldo, A., Tibshirani, R. J., & Wasserman, L. (2018). Distribution-free predictive inference for regression. Journal of the American Statistical Association, 113(523), 1094-1111.

conformalbayes's People

Contributors

corymccartan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

valeman

conformalbayes's Issues

Conformal scores with respect to predictive density

Hi @CoryMcCartan! Cool package 👍🏽 I want to add support for Conformalized Bayes in my Julia package as outlined here (Section 2.4, pp 10-11). I just had a look at your code for some inspiration and want to make sure I understand correctly: it looks like you're conformalizing point predictions (drawn from the posterior), is that right? In other words, conformal scores are not computed with respect to the posterior predictive density as described in the linked tutorial.

Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.