pintervals is an R package for computing model-agnostic prediction intervals. It provides a unified, easy-to-use interface for generating such intervals using inductive conformal prediction, bootstrapping, and parametric methods. The model-agnostic nature of the functions allows the user to quantify the uncertainty around predictions from any model that produces point predictions — linear models, machine learning algorithms, or anything else.
Point predictions on their own don't tell you how much to trust them. pintervals lets you attach calibrated uncertainty to predictions without being tied to a specific modelling framework. Prediction intervals are generated with the pinterval_* functions, where each function maps to a specific framework for generating the predictions. pintervals generally require an out-of-sample calibration data set on which errors can be computed.
pinterval_conformal()) — distribution-free intervals with finite-sample marginal coverage guarantees under the assumption of exchangeability. pintervals implements the split/inductive conformal prediction algorithm.pinterval_mondrian()) — group-conditional coverage for heterogeneous data with finite-sample marginal coverage guarantees within each group, under the assumption of exchangeability.pinterval_ccp()) — pools similar groups together for more efficient group-conditional intervals when groups are numerous or small.pinterval_bccp()) — adaptive conformal prediction intervals conditional on the outcome, for skewed or imbalanced outcome distributions with finite-sample marginal coverage guarantees within binned ranges of the outcome.pinterval_bootstrap()) — resampling-based intervals that make no distributional assumptions.pinterval_parametric()) — fast, interpretable intervals under a specified (or custom) error distribution.All pinterval_*() functions share a common interface: point predictions for a test set, plus predicted and true values from a calibration set, in — a tibble with the resulting lower and upper bounds out. Functions to evaluate interval performance, such as interval_coverage(), interval_width(), and interval_score(), are also included.
Install the released version from CRAN:
install.packages("pintervals")
Or install the development version from GitHub:
# install.packages("remotes")
# remotes::install_github("Doktorandahl/pintervals")
install.packages("pintervals", repos = c('https://doktorandahl.r-universe.dev', 'https://cloud.r-project.org'))
library(pintervals)
# Split predicted/true outcome pairs into calibration and test sets
data("county_turnout", package = "pintervals")
set.seed(1)
calib_idx <- sample(nrow(county_turnout), size = 0.5 * nrow(county_turnout))
calib_data <- county_turnout[calib_idx, ]
test_data <- county_turnout[-calib_idx, ]
# Conformal prediction intervals at 90% coverage
intervals <- pinterval_conformal(
pred = test_data$predicted_turnout,
calib = calib_data$predicted_turnout,
calib_truth = calib_data$turnout,
alpha = 0.1
)
# Check empirical coverage and average width
interval_coverage(
truth = test_data$turnout,
lower_bound = intervals$lower_bound,
upper_bound = intervals$upper_bound
)
For a full introduction to the package, the theory behind each method, and a worked example predicting U.S. county-level voter turnout, see the package vignette:
vignette("pintervals", package = "pintervals")
| dataset | description |
|---|---|
county_turnout |
U.S. county-level turnout + demographics for the 2016 election, with a leave-one-out random-forest predicted_turnout. Used in the vignette and the quick example above. |
county_turnout_panel |
A tidy five-wave county panel (2008, 2012, 2016, 2020, 2024) of presidential turnout (votes / Citizen Voting-Age Population), votes and vote shares by party, per-election turnout/vote-share aggregates, and ACS demographic context. county_turnout is superseded by this but retained. |
elections |
Election-year V-Dem democracy indicators, 1946–2024. |
county_turnout_panel
The panel is assembled entirely from public data by a reproducible pipeline in
data-raw/. To rebuild it from scratch:
# 1. free Census Bureau API key -> https://api.census.gov/data/key_signup.html
# 2. add to ~/.Renviron: CENSUS_API_KEY=xxxx
# 3. from the package root:
Rscript data-raw/county_turnout_panel.R
Raw downloads (~260 MB) are cached under data-raw/cache/, so re-runs take
seconds. A variable-by-variable codebook is installed with the package:
file.show(system.file("extdata", "county_turnout_panel_codebook.md", package = "pintervals"))
Upstream sources (see data-raw/README.md for full citations):
If you use pintervals in your research, please cite:
Randahl, D., Hjort, A., & Williams, J. P. (2026). pintervals: an R package for model-agnostic prediction intervals. arXiv preprint arXiv:2601.03994.
GPL (>= 3). See LICENSE.md for details.