quantile_pred: Create a vector containing sets of quantiles

View source: R/quantile-pred.R

quantile_predR Documentation

Create a vector containing sets of quantiles

Description

quantile_pred() is a special vector class used to efficiently store predictions from a quantile regression model. It requires the same quantile levels for each row being predicted.

Usage

quantile_pred(values, quantile_levels = double())

extract_quantile_levels(x)

## S3 method for class 'quantile_pred'
as_tibble(x, ..., .rows = NULL, .name_repair = "minimal", rownames = NULL)

## S3 method for class 'quantile_pred'
as.matrix(x, ...)

Arguments

values

A matrix of values. Each column should correspond to one of the quantile levels.

quantile_levels

A vector of probabilities corresponding to values.

x

An object produced by quantile_pred().

...

Not currently used.

.rows, .name_repair, rownames

Arguments not used but required by the original S3 method.

Value

  • quantile_pred() returns a vector of values associated with the quantile levels.

  • extract_quantile_levels() returns a numeric vector of levels.

  • as_tibble() returns a tibble with rows ".pred_quantile", ".quantile_levels", and ".row".

  • as.matrix() returns an unnamed matrix with rows as samples, columns as quantile levels, and entries are predictions.

Examples

.pred_quantile <- quantile_pred(matrix(rnorm(20), 5), c(.2, .4, .6, .8))

unclass(.pred_quantile)

# Access the underlying information
extract_quantile_levels(.pred_quantile)

# Matrix format
as.matrix(.pred_quantile)

# Tidy format
library(tibble)
as_tibble(.pred_quantile)

tidymodels/hardhat documentation built on Dec. 14, 2024, 11:11 a.m.