Quantile

Misc

  • Used to estimate the conditional quantiles of a target variable

    • Example: Assume we have a quantile regression model predicting the demand for apples tomorrow. Our model forecasts the 90th quantile as 100, which means that according to the model, there is a 90% probability that the actual demand will be 100 or lower.
  • Also see

  • Resources

    • Handbook of Quantile Regression - Koenker ({quantreg} book) (see R >> Documents >> Regression)
  • Packages

    • {quantregRanger} - uses Ranger to fit quantile RFs
      • In {tidymodels}, quantreg = TRUE tells ranger that you’re estimating quantiles rather than averages. Also predict(airquality, type = 'quantiles')
    • {grf} - generalized random forest
    • {quantreg} - Estimation and inference methods for models for conditional quantile functions: Linear and nonlinear parametric and non-parametric (total variation penalized) models for conditional quantiles of a univariate response.
    • {partykit} - conditional inference trees; model-based recursive partitioning trees
      • {bonsai}: tidymodels partykit conditional trees, forests; successor to treesnip - Model Wrappers for Tree-Based Models
    • {{quantile-forest}} - Zillow’s sklearn compatible quantile forest. Compared to other python implementations, optimized for training and inference speed, enabling it to scale to millions of samples with a runtime that is orders of magnitude faster than less-optimized solutions. It also allows specifying prediction quantiles after training, permitting a trained model to be reused to estimate conditional quantiles as needed.
      • Out-of-Bag Scoring: OOB scoring can be used to obtain unbiased estimates of prediction errors and quantile-specific metrics without the need for additional validation datasets.
      • Quantile Rank Calculation: Provide a measure of relative standing for each data point in the distribution. Allows you to compare and rank observations based on their position within the quantile distribution, providing valuable insights for various applications, such as risk assessment and anomaly detection.
      • Proximity and Similarity Estimation: Quantifies the similarity between pairs of observations based on their paths through the forest. Useful for clustering, anomaly detection, and identifying influential observations.
    • {{skgarden}} - Extension for sklearn tree and forest models. Produces online training models called Mondrian Forests (paper). Has a quantile random forest flavor.
    • {qrnn}: Quantile Regression Neural Network
      • Fit quantile regression neural network models with optional left censoring, partial monotonicity constraints, generalized additive model constraints, and the ability to fit multiple non-crossing quantile functions.
    • {qrcm} - A parsimonious parametric approach that directly models the linear regression coefficients as smooth functions of q, which succeeds in effectively pooling information across quantile levels. It also estimates different quantile coefficients simultaneously.
      • Note that Quantile RFs simulaneously estimate the entire conditional distribution
      • Benefits of Simultaneous Estimation:
        • Computational Efficiency: Reduces overall computation time compared to fitting each quantile separately.
        • No Quantile Crossing: Crossing violates the basic principle that higher quantiles should always have higher values than lower quantiles for any given set of predictor variables. This also violates the fundamental properties of cumulative distribution functions, which should be monotonically increasing.
        • Improved Stability: The joint estimation can lead to more stable estimates, especially in smaller samples or when dealing with extreme quantiles. In regions where data is sparse, borrowing information across quantiles can lead to more robust estimates.
        • Enhanced inference: Simultaneous estimation allows for easier joint hypothesis testing across multiple quantiles.
    • {qrcmNP} - Uses the method in {qrcm} for nonlinear and penalized parametric modeling of quantile regression coefficient functions.
    • {fastkqr} (paper) - A Fast Algorithm for Kernel Quantile Regression
      • Efficient algorithm to fit and tune kernel quantile regression models based on the majorization-minimization (MM) method.
      • Fits multiple quantile curves simultaneously without crossing.
  • For quantiles > 0.80, see quantile models in Extreme Value Theory (EVT)

    • Quantile Loss is not effective at predicting tail events
  • Harrell: To characterize an entire distribution or in other words, have a “high degree of confidence that no estimated quantile will be off by more than a probability of 0.01, n = 18,400 will achieve this.

    • For example, with n = 18,400, the sample 0.25 quantile (first quartile) may correspond to population quantiles 0.24-0.26.

    • To achieve a \(\pm\) 0.1 MOE requires n = 180, and to have \(\pm\) 0.05 requires n = 730 (see table)

      #>        n   MOE
      #> 1     20 0.294
      #> 2     50 0.188
      #> 3    100 0.134
      #> 4    180 0.100
      #> 5    250 0.085
      #> 6    500 0.060
      #> 7    730 0.050
      #> 8    750 0.049
      #> 9   1000 0.043
      #> 10  2935 0.025
      #> 11  5000 0.019
      #> 12 10000 0.014
      #> 13 18400 0.010
  • Harrell has a pretty cool text effect to display quantile values in his {HMisc::describe} that uses {gt} under the hood (See EDA >> Packages >> HMisc)

    • Histogram is a sparkline