Skip to contents

quantile_reg() generates a quantile regression model specification for the tidymodels framework. Currently, the only supported engines are "rq", which uses quantreg::rq(). Quantile regression is also possible by combining parsnip::rand_forest() with the grf engine. See grf_quantiles.

Usage

quantile_reg(
  mode = "regression",
  engine = "rq",
  quantile_levels = 0.5,
  method = "br"
)

Arguments

mode

A single character string for the type of model. The only possible value for this model is "regression".

engine

Character string naming the fitting function. Currently, only "rq" and "grf" are supported.

quantile_levels

A scalar or vector of values in (0, 1) to determine which quantiles to estimate (default is 0.5).

method

A fitting method used by quantreg::rq(). See the documentation for a list of options.

Examples

library(quantreg)
#> Loading required package: SparseM
tib <- data.frame(y = rnorm(100), x1 = rnorm(100), x2 = rnorm(100))
rq_spec <- quantile_reg(quantile_levels = c(.2, .8)) %>% set_engine("rq")
ff <- rq_spec %>% fit(y ~ ., data = tib)
predict(ff, new_data = tib)
#> # A tibble: 100 × 1
#>                  .pred
#>                 <dist>
#>  1  quantiles(0.05)[2]
#>  2 quantiles(-0.05)[2]
#>  3   quantiles(0.3)[2]
#>  4 quantiles(-0.41)[2]
#>  5  quantiles(0.21)[2]
#>  6 quantiles(-0.05)[2]
#>  7  quantiles(-0.3)[2]
#>  8 quantiles(-0.25)[2]
#>  9 quantiles(-0.23)[2]
#> 10  quantiles(0.05)[2]
#> # ℹ 90 more rows