Is it possible to use function
to create an equation which will produce a normal distribution and simultaneously produce a 95% confidence interval of said data? I know that I can use rnorm(n,mean,sd)
to generate a random normal distribution but how do I get the output to tell me the confidence interval?
I have attempted sample_CI<- function(n,j,k){list(g<-rnorm(n, mean=j, sd=k), confint(g, level=.95))}
.
All help appreciated.
It may be this what you were looking for:
sample_CI <- function(n,j,k){
error <- qnorm(0.975)*k/sqrt(n)
left <- j-error
right <- j+error
paste("[",round(left,4)," ; ",round(right,4),"]")
}
sample_CI(1000,2,4)