In: Statistics and Probability
Find the 95% confidence interval of the mean of a vector in r code. The vector length is 100.
## R command
## Generated a sample of size n=100, mean=10 and standard deviation (s)=2.
x=rnorm(n=100, mean=10, s=2)
n=length(x) ## Sample size
n
M=mean(x) #Mean of the sample
M
S=sd(x) ## Standard deviation of the sample
S
Q=qt(p=0.975, df=n-1) # Critical value of t for 95% CI
ME=Q*S/sqrt(n) # Margin of Error
# 95% confidence interval for population mean
Lower_bound=M-ME
Lower_bound
Upper_bound=M+ME
Upper_bound
## End