# R: Confidence interval and tail probabilities confusion

## Introduction

I am working in R and I am getting confused how to compute confidence interval of normal distributions and tail probabilities of unobserved points. I have looked at other posts on here that does not help me answer these questions properly.

## Question Summary:

I have two questions.

1. How to compute the confidence interval of a normal distribution on R knowing the mean, the standard-deviation and the number of samples?
2. How to compute the tail probability of a new point?

## Toy Example:

Here is a toy example to illustrate my issue:

Imagine I have some variable X that is taken from a normal distribution. I have 50 samples from which I have estimated the mean to be equal to 10 and standard deviation to 2.

n = 50
X.mean <- 10
X.SD <- 2


$$\textrm{CI} = \left[\mu + \frac{c_{\alpha}\ast SD}{\sqrt{n}}, \mu - \frac{c_{\alpha}\ast SD}{\sqrt{n}}\right]$$

With $$\mu$$ = mean, $$SD$$ = standard deviation and $$c_{\alpha}$$ = as the $$\alpha$$ percentile of the distribution.

So if I want to have the 95% confidence interval I would write:

# value of the 95% quantile
c_95 <- qt(p = 0.95, df = n-1)

# CI margin
error <- (c_95 * X.SD / sqrt(n))

# CI values:
ci_interval <- c(X.mean - error, X.mean + error)


which gives me ci_interval = $$[9.5258, 10.4742]$$. (Aleady, I feel that it is smaller than I expected)

Then, I have other issues with the computation of the tail probability with the pnorm() function.

On wikipedia, I can read that "The confidence interval can be expressed in terms of statistical significance, e.g.: "The 95% confidence interval represents values that are not statistically significantly different from the point estimate at the .05 level"."

So if I compute the tail probabily at the upper confidence interval, I should get 0.025.

But if I do this:

pnorm(q = ci_interval[2], mean = X.mean, sd = X.SD, lower.tail = T)


I get $$0.4062896$$ and not the expected 0,0025.

What I am understanding / doing wrong?

1. If you want a 95% confidence interval, then you need an area of 0.025 above and below the interval. That means the value in qt() should be 0.975, not 0.95. 0.95 leads to a 90% confidence interval.
2. The tail probability will be calculated on the distribution of the sample mean. If $$X \sim N(\mu = 10, \sigma = 2)$$, and $$n = 50$$, then $$\bar{X} \sim N(\mu = 10, \sigma = 2/\sqrt{50})$$. Additionally, if you want to see the value 0.025, you need either the upper tail of the upper limit, or the lower tail of the lower limit. Changing your final call to pnorm(q = ci_interval[2], mean = X.mean, sd = X.SD/sqrt(n), lower.tail = F) gives the expected result. (Except for small differences between the t-distribution and normal distribution.)