Getting confidence intervals
Using confidence intervals allows us to estimate the interval range of unknown parameters in the data. In this recipe, we will teach you methods that can help obtain confidence intervals in R.
Getting ready
Ensure that you installed R on your operating system.
How to do it…
Perform the following steps to obtain confidence intervals:
Let's first generate a normal distribution using the
rnorm
function:>set.seed(123) >population<- rnorm(1000, mean = 10, sd = 3) >plot(dens, col="red", main="A density plot of normal distribution")
Next, we will sample 100 samples out of the population:
>samp<- sample(population, 100) >mean(samp) [1] 10.32479 >sd(samp) [1] 3.167692
At this point, we can obtain the Z-score at a confidence of 99%:
> 1 - 0.01 / 2 [1] 0.995 >qnorm(0.995) [1] 2.575829
We can now compute the standard deviation error and estimate the upper and lower bounds of the population mean:
>...