# Variance as function of quantiles

Given a quantile function $$Q(p)=F^{-1}(p)$$ where $$F(x)$$ is the CDF, one can easily calculate the expected value as

$$E[X]=\int_0^1Q(p)dp$$. (see e.g., here)

Is there a similar way to get the Variance from the quantile function $$Q(p)$$? I tried deriving a similar function, but the best I can do is

$$Var[X]=\int_0^1(Q(p))^2dp-(\int_0^1Q(p)dp)^2$$,

simply by using the equality $$Var[X]=E[X^2]-(E[X])^2$$. But I fail to find any simpler formula based on the quantiles.

Are there any simplifications that could be performed on this?

Quantiles of a distribution are not in direct relation with the distribution variance since the former always exist while the variance may be infinite. A generic connection between the cdf and the variance is as follows.

Assuming the finiteness of the variance of $$F$$ and a support for $$F$$ included in $$\mathbb R^+$$, \begin{align} \int_0^\infty x² \text dF(x)&=-\int_0^\infty x² \text d(1-F)(x)\\ &=-\underbrace{[x²(1-F(x))]_0^\infty}_{0}+\int_0^\infty 2x(1-F(x))\text dx\tag{1}\\&=-\int_0^\infty 2x\frac{d}{dx}\left\{\mathbb E[X]-\int_0^x(1-F(y))\text dy\right\}\text dx\\ &=-\left[2x\left\{\mathbb E[X]-\int_0^x(1-F(y))\text dy\right\}\right]_0^\infty\\ &\qquad +2\int_0^\infty \left\{\mathbb E[X]-\int_0^x(1-F(y))\text dy\right\}\text dx\\ &=2\int_0^\infty \left\{{\int_0^\infty (1-F(y))\text dy}-\int_0^x(1-F(y))\text dy\right\}\text dx\\ &=2\int_0^\infty \int_x^\infty (1-F(y))\text dy\text dx\tag{2} \end{align} by successive integrations by parts. Note that (1) and (2) are identical by Fubini, i.e. by inverting the order of integration in (2). The extension to an arbitrary support in $$\mathbb R$$ proceeds by breaking $$\int x² \text dF(x)=\int^0_{-\infty} x² \text dF(x)+\int_0^\infty x² \text dF(x)$$

Contrary to the currently accepted answer, I'll point out that while the quantiles always exist, i.e. are finite for every $$p \in (0, 1)$$, this does not mean for instance the equation you have found relating the quantile function and the expectation is incorrect. The quantile function will always be finite whenever the random variable in question is always finite; we do not say that there is no relationship between the expectation/variance of X and the values of X, such as through equations like $$\mathbb{E}(X) = \int xF(dx)$$ or $$\mathrm{Var}(X) = \int (x-\mathbb{E}(X))^2 F(dx)$$, merely on the basis that the moments may be infinite or not even exist, while the integral happens over $$\mathbb{R}$$. In fact, it can be instructive to try evaluating these sorts of integrals (or more careful representations like the integrals of the positive and negative parts of $$X$$, which individually always exist, even if not finite) to understand why those quantities may still be problematic.

There is a somewhat intuitive form for the variance relating it to the quantile function, which you have started to obtain, as the $$\ell_2$$ norm of the "centered" quantile function (just as the variance is the $$F$$-weighted $$\ell_2$$ norm of the "centered" values of $$X$$). The derivation below will assume $$X$$ is absolutely continuous with respect to the Lebesgue measure (i.e. "continuous"), and has finite variance (hence finite expectation). This uses some of the implicit differentiation tricks utilized in the link you provided. However, let's begin upstream a little from where you started:

\begin{aligned} \mathrm{Var}(X) &= \mathbb{E}[(X-\mathbb{E}(X))^2] \\ &= \int [x - \mathbb{E}(X)]^2 f(x) dx \\ &= \int [x^2 - 2x\mathbb{E}(X) + \mathbb{E}(X)^2] f(x) dx \\ &= \int x^2 f(x) dx - 2\mathbb{E}(X) \int xf(x) dx + \mathbb{E}(X)^2 \\ &= \int_0^1 Q(p)^2 dp - 2\mathbb{E}(X)\int_0^1 Q(p)dp + \mathbb{E}(X)^2 \\ &= \int_0^1 [Q(p) - \mathbb{E}(X)]^2 dp. \end{aligned}

Of course, maybe you'd prefer: $$\mathrm{Var}(X) = \int_0^1 \left[ Q(p) - \int_0^1 Q(q) dq \right]^2 dp.$$

I myself would call this a direct relation between the quantile function and the variance. I suppose this holds for any random variable, continuous or otherwise, by expressing any discrete random variable's distribution function as a limit of a sequence of continuous random variables' distribution functions. Maybe there needs to be some care in how that is constructed.