20. Confidence Intervals
Although there are packages that can calculate confidence intervals, the standard installation of R does not. However they are easily calculated using your own code. For example:
CI <- 0.975 #95% CI
mean <- mean(data$bmi, na.rm=T)
stdev <- sd(data$bmi, na.rm=T)
n <- length(data$bmi)
error <- qt(0.975,df=n-1)*stdev/sqrt(n)
lowerCI <- mean-error
upperCI <- mean+error
mean
stdev
lowerCI
upperCI
Exercise: Write you own code to calculate the standard error of the mean for BMI. |