-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
481 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#' Linear quantile regression via the quantreg package | ||
#' | ||
#' [quantreg::rq()] optimizes quantile loss to fit models with numeric outcomes. | ||
#' | ||
#' @includeRmd man/rmd/linear_reg_quantreg.md details | ||
#' | ||
#' @name details_linear_reg_quantreg | ||
#' @keywords internal | ||
NULL | ||
|
||
# See inst/README-DOCS.md for a description of how these files are processed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
```{r, child = "aaa.Rmd", include = FALSE} | ||
``` | ||
|
||
`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: | ||
|
||
```{r quantreg-reg} | ||
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: | ||
|
||
```{r 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: | ||
|
||
```{r example-format} | ||
as_tibble(qr_pred$.pred_quantile) | ||
as.matrix(qr_pred$.pred_quantile) | ||
``` | ||
|
||
## Preprocessing requirements | ||
|
||
```{r child = "template-makes-dummies.Rmd"} | ||
``` | ||
|
||
## Case weights | ||
|
||
```{r child = "template-uses-case-weights.Rmd"} | ||
``` | ||
|
||
## Saving fitted model objects | ||
|
||
```{r child = "template-butcher.Rmd"} | ||
``` | ||
|
||
## Examples | ||
|
||
The "Fitting and Predicting with parsnip" article contains [examples](https://parsnip.tidymodels.org/articles/articles/Examples.html#linear-reg-quantreg) for `linear_reg()` with the `"quantreg"` engine. | ||
|
||
## References | ||
|
||
- Waldmann, E. (2018). Quantile regression: a short story on how and why. _Statistical Modelling_, 18(3-4), 203-218. |
Oops, something went wrong.