# Quantile function with Normal distribution and Weibull distribution

A quantile function Q is defined in terms of its distribution function F as:

$Q(p)=inf\{ x\in R:p \le F(x)\},p\in(0,1)$

But i don't understand very well how it works exactly. Suppose we are managing a cdf for Normal Distribution N(0,1)

$F(x) = \frac{1}{2} \left[ 1 + erf \left( \frac{x-\mu}{\sigma \sqrt{2}} \right) \right]$

If i want to know the probability for Q(1) i have to find the minimum $x \in R$ such that $p \le F(x)$ where in this case:

$$\text{find the minimum x s.t. } \frac{1}{2} \left[ 1 + erf \left( \frac{x-0}{1 \sqrt{2}} \right) \right] \ge 1$$ $$\text{for }x = 0.841 \text{ we have } \frac{1}{2} \left[ 1 + erf \left( \frac{0.841}{ \sqrt{2}} \right) \right] = 1$$

Hence Q(1) for N(0,1) is 0.841.

Suppose now we want to use the Weibull Distribution with $k = 1$ and $\lambda = 1$, the cdf is $F(x) = 1 - e^{-(x/\lambda)^{k}}$

From an external quantile applet ( Quantile applet ) i know that Q(1) = 0.632

but i'm not able to compute this result:

$$\text{find the minimum x s.t. } 1 - e^{-(x/\lambda)^{k}} \ge 1$$ $$1 - e^{-(0.632/1)^{1}}$$ $$= 0.468472 \neq 1$$

Where i'm wrong?

-
Q(1) for the normal should be infinity. There does not exist any x such that $1 \le F(x)$ for the normal distribution. Same thing for the Weibull. I think the applet you are using is using percentages rather than probabilities, i.e. Q(1) for them corresponds to Q(.01) for you. – guy Jul 13 '11 at 15:17
F is a distribution, and therefore always in [0, 1]. Q(1) is the smallest value that it a.s. never exceeded. In the case of the normal distribution Q(1)=$\infty$ – deinst Jul 13 '11 at 15:18
Ok thank you, the applet i used has a wrong data representation and leads me to confuse "quantile" with "x". – Maurizio Jul 13 '11 at 15:41

Mathematically, Quantiles are simple the inverse of the CDF. As such the input $p$ is bounded by $(0,1)$ as $p$ is the probability that the event has occured. In order to understand this, one must understand the CDF. The CDF takes in a value and calculates the probability that the event occurs for any value before. When dealing with distributions such as Normal or Weibull, the CDF only equals $1$ at infinity, because there is a chance that the event occurs at near infinte values for the Random Variable. If you want to do the quantile of Weibull, you can take the CDF equation and solve for $X$ in terms of $P$. The result, for Weibull, should be $X = \lambda((-\log(1-P))^{1/k})$.

-
Thank you, can I ask you how you derived the final formula $X = \lambda ( (-ln(1-P))^{1/k} )$ ? – Maurizio Jul 13 '11 at 15:49
He took the definiton of the Weibull CDF: $P=1-\exp(-(X/\lambda)^k)$ and solved for $X$ – deinst Jul 13 '11 at 17:29
oh yes you are right i did not realize the first time.. :) – Maurizio Jul 13 '11 at 18:08

Let's get back to normal distribution. The cdf of normal distribution at $x=1$ is $0.841345$, hence the quantile of $0.841345$ is 1. The quantile of 1 for normal distribution is $+\infty$, because for all finite $x$, $cdf(x)<1$ in normal distribution.

Again, for Weibull distribution with $k=1$ and $\lambda=1$ the cdf at $x=1$ is 0.632121, hence the quantile $Q(0.63)$ is 1. The $Q(1)$ as for normal is $+\infty$.

-
Ok, hence i was confused with parameters representation :) The applet uses a wrong data representation because indicates "quantile" instead of "x"..So if I want to find p in the Weibull($\lambda=1$, $k=1$) of x=1 i use the formula $1-e^{{(1/1)}^1} = 0.632$ and the results are now correct. – Maurizio Jul 13 '11 at 15:38

First of all, for any real-valued random variable $X$ holds $Q_X(1) = \infty$ if there is no $M$ such that $X\leq M$ a.s. For sure it holds for both distributions you have mentioned.

I am not so familiar with error functions - but the formula you use seems to be correct and should lead you to an answer $Q(1) = \infty$.

I've just checked in Mathematica and it tells that $$F(1) = 0.841$$ rather then $F(0.841) = 1$ as you stated in your post. In fact, $F(0.841) = 0.799826...$

-
Yes, you are right. I was confused with the representation of parameters! Thank you very much. – Maurizio Jul 13 '11 at 15:45

For the Weibull quantile derivation, I find it easiest to write the quantile function as the inverse CDF:

$$Q(p)=F^{-1}(p)$$

Now the way I do these inversion calculations is to use the inverse property:

$$F[Q(p)]=p$$

Have to be careful about this is general, but for most random variables this is fine. CDF needs to be 1-to-1, but this is usually the case (as for Normal and Weibull), and you can do away with annoying $inf$ where this is the case. But we know that $F(x)=1-\exp\left(-\left[\frac{x}{\lambda}\right]^{k}\right)$ so we just substitute $Q(p)$ for $x$ here on the LHS:

$$1-\exp\left(-\left[\frac{Q(p)}{\lambda}\right]^{k}\right)=p$$

You then solve for $Q(p)$

$$\log(1-p)=-\left[\frac{Q(p)}{\lambda}\right]^{k}$$ $$\lambda\left[\log\left(\frac{1}{1-p}\right)\right]^{\frac{1}{k}}=Q(p)$$

So there's a derivation you asked of @cyanrook.

In terms of understanding the quantile function, your definition is not a clear way to see what it's doing. I think its easier to intuitively think of a quantile function in terms of reading off the graph of a CDF (as in @sasha's answer). You draw a horizontal line on this graph for the quantile you want, starting from the left at $-\infty$ to the right, and you stop drawing the line the first time the line touches the CDF. The pth quantile is given by the $x$ co-ordinate of this point. So the line "goes" like $\rightarrow,\rightarrow,\rightarrow,\downarrow$. Reading @Sasha's graph by eye, we have the 0.6 quantile as roughly 0.3

-

A good, fast Normal Quantile function can be found at http://home.online.no/~pjacklam/notes/invnorm/. Using the Mathematica-encoded function there, the inverse normal becomes:

InverseNormal[d_] := Module[{x = AcklamQuantile[d], e, u},
If[ (d > 0) && (d < 1),
e = Erfc[-x/Sqrt[2]]/2 - d;
u = e * Sqrt[2*Pi] * Exp[x*x/2];
x -=  u/(1 + x*u/2)];
Return[x]];
InverseNormal[d_, \[Mu]_, \[Sigma]_] :=
Module[{x = AcklamQuantile[d], e, u},
If[ (d > 0) && (d < 1),
e = Erfc[-x/Sqrt[2]]/2 - d;
u = e * Sqrt[2*Pi] * Exp[x*x/2];
x -=  u/(1 + x*u/2)];
Return[\[Sigma]*x +  \[Mu]]];
InverseNormal[d_, \[Mu]_, \[Sigma]_, tol_] :=
Module[{x = AcklamQuantile[d], e, u, adj, iters = 1},
If[ (d > 0) && (d < 1),
e = Erfc[-x/Sqrt[2]]/2 - d;
u = e * Sqrt[2*Pi] * Exp[x*x/2];
x -=  (adj = u/(1 + x*u/2));
While[((adj > tol) && (iters < 11)),
++iters;
e = Erfc[-x/Sqrt[2]]/2 - d;
u = e * Sqrt[2*Pi] * Exp[x*x/2];
x -=  (adj = u/(1 + x*u/2))]];
Print[iters, " iterations"];
Return[\[Sigma]*x +  \[Mu]]];

-