Using the following population:
sample <- c(41.5, 56.7, 54.2, 98.9, 56.7, 43.9, 35.8, 28.8)
I get a different result for the upper and lower confidence intervals when calculating them "manually" than what result from the standard library t.test()
function.
s <- sd(sample) # standard deviation
se <- s/sqrt(NROW(sample)) # standard error
# Using t.test()
lower <- (t.test(sample))$conf.int[1] # yields 34.11755
upper <- (t.test(sample))$conf.int[2] # yields 70.00745
# Calculating manually
lower <- mean(sample)-(1.96*se) # yields 37.18821
upper <- mean(sample)+(1.96*se) # yields 66.93679
Can somebody explain what is going on here?
Update: Thanks for the information everybody! This was really enlightening.