# Quantile Regression
### Overview
Normally we are interested in finding the *conditional mean*:
$\mathbb{E} (y|x)$
But we may also consider the *conditional median*:
$Median(y|x)$
Or more generally, the *conditional percentiles*, $\tau \in (0, 1)$:
$Percentile_{\tau}(y|x)$
To understand this is it helpful to first define what a **quantile** is.
> **Definition: Quantile**
> The $\tau^{\text{th}}$ quantile of $y$ is $\mu_{\tau}$ such that:
> $\tau = P(y \leq \mu_{\tau}) = F_y(\mu_{\tau})$
> Hence:
> $\mu_{\tau} = F_y^{-1}(\tau)$
To spell this out a bit more, let's say $y$ is a set of prices. Then $\mu_{\tau}$ will be a member of the set of prices, such that if we sorted all prices in $y$, the value $\mu_{\tau}$ would be located in this sorted set such that it split the set so that the fraction $\tau$ elements lie *before* it, and the fraction $1 - \tau$ lie *after* it.
We can visualize this below as follows. First, let us look at the [Cumulative Distribution Function](Cumulative%20Distribution%20Function.md) of $x$. This takes in elements of the domain, in this case $x$ (of which $\mu_{\tau} \in x$), and returns values in the codomain of $(0, 1)$:

We can then simply take the inverse CDF, map $\tau$ through it, and get back the quantile $\mu_{\tau}$:

The **conditional quantile** is the same thing except that our CDF is now conditional on $x$:
> **Definition: Conditional Quantile**
> The conditional $\tau$ quantile of $y$ is :
> $\mu_{\tau} = F^{-1}_{y|x}(\tau|x)$
Now let's look at another nice example. Consider we have the following dataset:

Say that we want to look at quantiles conditional on some $x$. Here is what that may look like if we conditioned on $x \approx 5.3$: 
So above we are looking at a specific $x$ (well, almost - it technically needs to be infinitely narrow), and given this $x$ we have a distribution of $y