47  Quantile Regression

Every regression model covered so far predicts the average outcome for a given value of \(X\). That is often not the number a farmer actually needs. A risk-averse farmer deciding how much to invest in a season cares less about the average yield across many possible rainfall outcomes and more about what yield to expect if the season turns out poorly. Quantile regression answers that question directly by modeling a chosen percentile (quantile) of the outcome rather than its mean.

Instead of minimizing squared error, quantile regression minimizes an asymmetric loss function, often called the pinball or check loss, that penalizes over-predictions and under-predictions differently depending on which quantile is being targeted:

\[ \rho_\tau(e) = \begin{cases} \tau \cdot e & \text{if } e \geq 0 \\ (\tau - 1) \cdot e & \text{if } e < 0 \end{cases} \]

where \(e = Y - \hat{Y}\) is the residual and \(\tau\) is the target quantile (for example, \(\tau = 0.10\) for the 10th percentile). At \(\tau = 0.5\) this loss reduces to minimizing absolute error, which targets the median rather than the mean.

47.1 Why Rainfall and Yield Are a Good Fit for This

Yield’s relationship with rainfall is typically heteroscedastic: at low rainfall, nearly every field underperforms in roughly the same way, so the spread of outcomes is narrow. At high rainfall, some fields do very well while others are held back by drainage, pests, or disease that thrive in wet conditions, so the spread widens considerably. A single mean-regression line cannot describe that widening spread; fitting several quantile lines can.

47.2 Worked Example

Ten fields across different seasons recorded the following seasonal rainfall and eventual yield.

Rainfall (mm) Yield (quintals/ha)
300 18
400 22
500 24
600 30
700 28
800 34
900 40
1000 33
1100 42
1200 38

Yield generally rises with rainfall, but the scatter around that rise grows wider at the higher rainfall values, exactly the pattern that makes an average-only model insufficient here.

47.3 Quantile Regression in R

Rather than relying on a package that may not be available in every R environment, the fit below implements quantile regression directly from its definition: minimizing the pinball loss using optim(). This is the same optimization idea a dedicated package like quantreg automates, just written out explicitly.

47.4 Reading the Two Lines Together

The gap between the 10th-percentile line and the median line is itself informative. Where the gap is small, the crop’s outcome is fairly predictable at that rainfall level. Where the gap widens, at higher rainfall in this dataset, the outcome is far less certain, and a farmer or an insurer planning around the 10th-percentile number rather than the median is effectively planning for the realistic downside rather than hoping for the average. This is the practical value quantile regression adds over the regression models covered earlier in this topic: it describes the shape of the risk, not only the shape of the average relationship.


Summary

Concept Description
Foundations
Quantile Regression Models a chosen percentile of the outcome instead of its mean, useful when the average is not the number that matters
Pinball (Check) Loss An asymmetric loss function that penalizes over- and under-predictions differently depending on the target quantile
Heteroscedasticity A relationship where the spread of outcomes changes across the range of the predictor, common in rainfall-yield data
Worked Example
Worked Example: Rainfall and Yield Ten fields where the spread between poor and good yield widens as seasonal rainfall increases
Fitting via optim() and Pinball Loss Minimizing pinball loss directly with optim() reproduces the quantile regression estimate without a dedicated package
Interpreting Multiple Quantile Lines The gap between quantile lines shows how uncertain the outcome is at a given predictor value, not just its expected level