pth Quantile of Standard Normal Distribution - R
-
20-12-2019 - |
Question
I'm learning statistics and R from a book called "Discovering Statistics using R"... Although it's very informative, it seems to skip over areas even though it suggests no prior knowledge of statistics or R is needed. So to the problem:
How can you calculate in R the pth quantile of the Standard Normal Distribution using the Dichotomy (or division in halves) method? (and assuming no use of qnorm()
). that is:
pnorm(x) = p
pnorm(x)-p = 0
f (x) = 0
Update:
Dichotomy is a method where you take an interval [a,b]
which takes values of different
signs at the end points of the interval and has a single root x
within [a,b]
. You then half if to find F(x1)
, and if f(x1) != 0
it gives you [a,x1]
and [x1,b]
... where the sequence x1, x2,...,
converges to 0
.
Solution
Clumsy, but this works:
tolerance <- 1e-6
interval <- c(-1000,1000)
quantile <- 0.2
while(interval[2]-interval[1] > tolerance) {
cat('current interval: ',interval,'\n')
interval.left <- c(interval[1],mean(interval))
interval.right <- c(mean(interval),interval[2])
if(sum(sign(pnorm(interval.left)-quantile))==0) {
interval <- interval.left
} else {
interval <- interval.right
}
}
mean(interval)
qnorm(quantile)