I have a large sample of experimental observations for different categories (specifically, the runtime of an algorithm in different scenarios). I want to plot the mean runtime for each category/scenario and also show the 95% confidence interval using R.

According to the central limit theorem, the mean of each category should be normally distributed (because it is based on a large number of independent observations).

I know how to plot the means as scatter plot and how to add error bars. I'm just unsure about the 95% confidence interval. The 95% confidence interval is the interval in which a new value lays with 95% probability? Or is only the actual mean in the interval with 95% probability?

I found this code on calculating the confidence interval:

error <- qnorm(0.975)*sd/sqrt(n)

Where n is the sample size and sd is the standard deviation. Unfortunately, it lacks further explanation. What exactly is qnorm(0.975) and why do we choose 0.975 to get the 95% confidence interval?

  • $\begingroup$ Requests for statistical tutoring belong on CrossValidated.com $\endgroup$
    – DWin
    Commented Feb 2, 2017 at 18:23
  • $\begingroup$ Also see ?qnorm and maybe the Wikipedia Simple English page for confidence intervals. While this is certainly topically more appropriate for crossvalidated, I think they appreciate users who do a bit of background reading as much as we do. $\endgroup$ Commented Feb 2, 2017 at 18:28

2 Answers 2


qnorm is the quantile function for the normal distribution. More details are available by typing ?qnorm. You pick 0.975 to get a two-sided confidence interval. This gives 2.5% of the probability in the upper tail and 2.5% in the lower tail, as in the picture. Two-Tailed normal distribution


The 95% confidence interval is the interval in which a new value lays with 95% probability?

No. If you sample very often and compute a 95%-CI every time, than the true value will be within 95% of those confidence intervalls. Sound disturbing? It is.

The standard deviation of the mean is called it's 'standard error'.

The qnorm-part has been explained by G5W.

  • $\begingroup$ With "true value" you mean the actual mean as opposed to the sample mean, right? $\endgroup$ Commented Feb 4, 2017 at 8:50
  • $\begingroup$ Right. Be carefull not to mix standard deviation of a distribution and standard error of the mean up. They are very different. If you want to go deeper into what a confidence intercal is and is not - if you really, really want that, read the "cookie" answer from Keith Winstein in this thread: stats.stackexchange.com/questions/2272/… $\endgroup$
    – Bernhard
    Commented Feb 4, 2017 at 17:20
  • $\begingroup$ Is there a difference between the standard error of the mean and the confidence interval? $\endgroup$ Commented Feb 4, 2017 at 19:03
  • $\begingroup$ The standard error of the mean is a single number and the confidence interval consists of two (a lower and an upper border)? $\endgroup$
    – Bernhard
    Commented Feb 4, 2017 at 22:05
  • $\begingroup$ But error <- qnorm(0.975)*sd/sqrt(n) does compute the confidence interval doesn't it? So it's always a certain deviation from the sample mean in both directions that expresses the confidence interval, e.g., mean +/- 1? Or is it also possible that the confidence interval is not symmetric, e.g., [mean-1, mean+2]? I guess not, as we are assuming a normal distribution of the mean. $\endgroup$ Commented Feb 5, 2017 at 12:58

Your Answer

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

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