What is the difference between the R-functions quantile and qnorm?

I have normal distributed data and want to calculate rejection areas for my given hypothesis test. In order to do this I found quantile to calculate the .025 and .975 quantiles ($\alpha = 0.05$), as well as qnorm. The difference is that qnorm works with the calculated mean and sd of my data. But why do I sometimes have different values?

I use those function calls for the upper (right-handed) rejection area and alpha <- 0.05:

qnorm(1-alpha/2, mean = mean(data), sd = sqrt(var(data))

quantile(data, .975)


1 Answer 1


quantile does not assume any distribution, in the quantile() function from R, for the case of 97.5 quantile, it finds the two values between which the quantile value should lie, and does an interpolation, so for example in the below example of 100 values, it interpolates between the 97th and 98th sorted value:

x = runif(100)
[1] 0.8806992 0.9071830

qnorm is quite different. It returns you the value at 97.5 quantile of a normal distribution with mean and variance estimated from your data. So whether this coincides with the above value, depends on how well the normal distribution with estimated mean and variance, can describe your data.

Below I give a simple example, where you have small sample size and causing the two estimates can differ. I simulate draw from samples of 20,200 and 2000 from a normal distribution of mean

norm_data_quantiles = function(i,n){
alpha = 0.05
data = rnorm(n,2,1)
norm_quantile = qnorm(1-alpha/2, mean = mean(data), sd = sd(data))

h = hist(data,freq=FALSE,main=paste("n=",n,"rep=",i))

D = expand.grid(sim=1:3,n=c(20,200,2000))
for(i in 1:nrow(D)){

enter image description here

The blue line is meant to show the expected normal probability while the histogram reflects the distribution in the actual data. The red dotted line is the 0.975 quantile while blue dotted is that estimated from the normal.

So you can see when you increase sample size, the two values differ less.

There are other reasons when they can differ, for example, your data is heavy tailed, big outliers, basically anything that can throw off the estimation of the mean and standard deviation.

  • $\begingroup$ So is it correct to say, if you don't know the exact values of your normal distribution (and they would be approximated), it is better to interpolate rejection areas using quantile ? $\endgroup$
    – nomeal
    Apr 12, 2020 at 17:36
  • $\begingroup$ Before i tell you something wrong, what do you mean by rejection areas? What are you using qnorm or quantile for? Because you question only ask difference between qnorm and quantile $\endgroup$
    – StupidWolf
    Apr 12, 2020 at 17:38
  • $\begingroup$ I have a hypothesis test and want to specify the critical area for a given significance level $\alpha$. As my data is distributed normally and my test is two-sided, my aim is to calculate the $\alpha /2$ and $1- \alpha /2$-quantiles of my distribution. But this distribution is simulated, therefore I don't have exact values of mean and sd. $\endgroup$
    – nomeal
    Apr 12, 2020 at 18:32
  • $\begingroup$ Ok if I guess correctly, you are doing something like a bootstrap or permutation, you simulate what your data would look like under the null hypothesis, then you want to find the 0.975 quantile to reject. Yes in this case you can use quantile. $\endgroup$
    – StupidWolf
    Apr 12, 2020 at 18:35
  • $\begingroup$ Or you can simply calculate the p-value as (sum(t_sim > t_obs)+1)/(n_sim + 1). you can check this paper, arxiv.org/pdf/1603.05766.pdf, hope I guessed correctly $\endgroup$
    – StupidWolf
    Apr 12, 2020 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.