source("http://www.openintro.org/stat/data/cdc.R")
general health-ordinal categorical recent exercise-regular categorical health plan-regular categorical smoker status-regular categorical height-numerical, discrete weight-numerical, discrete desired weight-numerical, discrete age-numerical, discrete gender-regular categorical
IQR(Height)=70-64=6 IQR(Age)=57-31=26
# enter code for Ex2 below
summary(cdc$height)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 48.0 64.0 67.0 67.2 70.0 93.0
70 - 64
## [1] 6
summary(cdc$age)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 18.0 31.0 43.0 45.1 57.0 99.0
57 - 31
## [1] 26
9569 males in the survey
# enter code for Ex3 below
table(cdc$gender)/20000
##
## m f
## 0.4784 0.5215
table(cdc$genhlth)/20000
##
## excellent very good good fair poor
## 0.23285 0.34860 0.28375 0.10095 0.03385
table(cdc$gender)
##
## m f
## 9569 10431
# code for Ex4 already given in lab
mosaicplot(table(cdc$gender, cdc$smoke100))
# enter code for Ex5 below
under23_and_smoke <- subset(cdc, cdc$age < 23 & cdc$smoke100 == "1")
# code for bmi vs. genhlth already given in lab
bmi = (cdc$weight/cdc$height^2) * 703
boxplot(bmi ~ cdc$genhlth, main = "BMI vs. general health")
# enter code for Ex6 below (boxplot for bmi vs. your chosen variable)
boxplot(bmi ~ +cdc$exerany, main = "BMI vs. exercised in the past month")
# enter code for Ex7 below
plot(x = cdc$weight, y = cdc$wtdesire)
No text needed for this question, just code.
# enter code for Ex8 below
wdiff <- (cdc$weight - cdc$wtdesire)
# enter code for Ex10 below - numerical summary
summary(wdiff)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -500.0 0.0 10.0 14.6 21.0 300.0
# enter code for Q4 below - plot(s)
boxplot(wdiff)
# enter code dfor Ex11 below - numerical summary
malecdc = cdc[cdc$gender == "m", ]
malewtdiff = malecdc$weight - malecdc$wtdesire
femalecdc = cdc[cdc$gender == "f", ]
femalewtdiff = femalecdc$weight - femalecdc$wtdesire
summary(malewtdiff)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -500.0 0.0 5.0 10.7 20.0 300.0
summary(femalewtdiff)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -83.0 0.0 10.0 18.2 27.0 300.0
# enter code for Ex11 below - side-by-side box plot
boxplot(wdiff ~ cdc$gender)
# enter code for Ex12 below
summary(cdc$weight)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 68 140 165 170 190 500
sd(cdc$weight)
## [1] 40.08
length(cdc$weight[cdc$weight < 209.78097 & cdc$weight > 129.61903])
## [1] 14152
14152/20000
## [1] 0.7076