hrs <- read.csv("/Users/yunis/Desktop/HRS_w1sub.csv")
# we will need the bmi (r1bmi) data # 
hrs.bmi <- hrs$r1bmi

summary (hrs.bmi)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    12.8    23.6    26.5    27.1    29.6   102.7
mean (hrs.bmi)
## [1] 27.09804
## 1 - confidence interval for the average BMI  ## 
t.test (hrs.bmi)
## 
##  One Sample t-test
## 
## data:  hrs.bmi
## t = 588.4, df = 12651, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  27.00777 27.18831
## sample estimates:
## mean of x 
##  27.09804
## 1 - Construct a 90% confidence interval for the average BMI  ## 
t.test(hrs.bmi,conf.level=.90)
## 
##  One Sample t-test
## 
## data:  hrs.bmi
## t = 588.4, df = 12651, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 90 percent confidence interval:
##  27.02228 27.17380
## sample estimates:
## mean of x 
##  27.09804
## 2 - Construct a 95% confidence interval for the average BMI  ## 
t.test(hrs.bmi,conf.level=.95)
## 
##  One Sample t-test
## 
## data:  hrs.bmi
## t = 588.4, df = 12651, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  27.00777 27.18831
## sample estimates:
## mean of x 
##  27.09804
## 3 - Construct a 99% confidence interval for the average BMI  ## 
t.test(hrs.bmi,conf.level=.99)
## 
##  One Sample t-test
## 
## data:  hrs.bmi
## t = 588.4, df = 12651, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 99 percent confidence interval:
##  26.97939 27.21668
## sample estimates:
## mean of x 
##  27.09804
## 4 - Given the results obtained above, can you reason why we may not always prefer
## a higher confidence level? That is, why do we not always prefer a 99% ##
## confidence interval? ## 

## both accuracy of confidence interval level and precision of a confidence interval needs to be considered, if data are lacking, we might achieve higher confidence, but less precision. If we increase confidence interval and wider confidence interval width, result will be more accurate but less precise. Overall, 99% confidence interval would be wider than the 95% confidence interval, 99% CI interval is more accurate than the 95% CI##