First, we load the data into R and preview the data.
data = read.csv('/Users/Max/Desktop/Exam1.csv')
head(data)
## BMI FEMALE
## 1 27.7 1
## 2 23.0 1
## 3 29.1 0
## 4 29.1 1
## 5 22.9 1
## 6 32.7 1
Compute the mean, standard deviation, 5th, 25th, median, 75th, 95th quantile, as well as 95% confidence interval of the mean of BMI.
bmi_mean = mean(data$BMI); bmi_mean
## [1] 31.76547
bmi_sd = sd(data$BMI); bmi_sd
## [1] 7.259151
bmi_quantile = quantile(data$BMI, probs = c(.05, .25, .5, .75, .95))
bmi_quantile
## 5% 25% 50% 75% 95%
## 22.000 26.600 30.700 35.700 45.605
error <- qt(0.975,df=length(data$BMI)-1)*sd(data$BMI)/sqrt(length(data$BMI))
error
## [1] 0.3077321
conf_interval = bmi_mean + c(-1,1)*error
conf_interval
## [1] 31.45774 32.07320
Compute 90% confidence interval of the proportion of female.
fem_data = data[data$FEMALE==1,]
fem_bmi_mean = mean(fem_data$BMI); fem_bmi_mean
## [1] 32.50974
fem_error <- qt(0.95,df=length(fem_data$BMI)-1)*sd(fem_data$BMI)/sqrt(length(fem_data$BMI))
fem_error
## [1] 0.3750694
fem_conf_interval = fem_bmi_mean + c(-1,1)*fem_error
fem_conf_interval
## [1] 32.13467 32.88481