r descr_models("linear_reg", "quantreg")

This model has the same structure as the model fit by lm(), but instead of optimizing the sum of squared errors, it optimizes "quantile loss" in order to produce better estimates of the predictive distribution.

Tuning Parameters

This engine has no tuning parameters.

Translation from parsnip to the original package

This model only works with the "quantile regression" model and requires users to specify which areas of the distribution to predict via the quantile_levels argument. For example:

linear_reg() %>% 
  set_engine("quantreg") %>% 
  set_mode("quantile regression", quantile_levels = (1:3) / 4) %>% 
  translate()

Output format

When multiple quantile levels are predicted, there are multiple predicted values for each row of new data. The predict() method for this mode produces a column named .pred_quantile that has a special class of "quantile_pred", and it contains the predictions for each row.

For example:

library(modeldata)
rlang::check_installed("quantreg")

n <- nrow(Chicago)
Chicago <- Chicago %>% select(ridership, Clark_Lake)

Chicago_train <- Chicago[1:(n - 7), ]
Chicago_test  <- Chicago[(n - 6):n, ]

qr_fit <- 
  linear_reg() %>% 
  set_engine("quantreg") %>% 
  set_mode("quantile regression", quantile_levels = (1:3) / 4) %>% 
  fit(ridership ~ Clark_Lake, data = Chicago_train)
qr_fit

qr_pred <- predict(qr_fit, Chicago_test)
qr_pred

We can unnest these values and/or convert them to a rectangular format:

as_tibble(qr_pred$.pred_quantile)

as.matrix(qr_pred$.pred_quantile)

Preprocessing requirements


Case weights


Saving fitted model objects


Examples

The "Fitting and Predicting with parsnip" article contains examples for linear_reg() with the "quantreg" engine.

References



Try the parsnip package in your browser

Any scripts or data that you put into this service are public.

parsnip documentation built on April 4, 2025, 1:53 a.m.