-
-
Save richgillin/1638207 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source("http://www.openintro.org/stat/data/cdc.R") | |
# Lab 1 OpenIntro Stats | |
# Intro to Data | |
names(cdc) | |
length(cdc) | |
str(cdc) | |
head(cdc) | |
tail(cdc) | |
# Ex. 1 | |
summary(cdc$weight) | |
190.0 - 140.0 | |
mean(cdc$weight) | |
var(cdc$weight) | |
median(cdc$weight) | |
table(cdc$smoke100) | |
table(cdc$smoke100)/20000 | |
barplot(table(cdc$smoke100)) | |
# Ex. 2 | |
summary(cdc$height) | |
70-64 # interquartile range of height | |
summary(cdc$age) | |
57-31 # interquatile range of age | |
table(cdc$gender) | |
table(cdc$exerany) | |
table(cdc$gender)/20000 # rel.freq dist for gender | |
table(cdc$exerany)/20000 | |
table(cdc$genhlth) | |
table(cdc$genhlth)/20000 | |
mosaicplot (table(cdc$gender,cdc$smoke100)) | |
dim(cdc) | |
cdc[567,6] | |
names(cdc) | |
mdata <- subset(cdc, cdc$gender == "m") | |
head(mdata) | |
Under23Smokedata <- subset(cdc, cdc$smoke100 == "1" & cdc$age < 23) | |
head(Under23Smokedata) | |
boxplot(cdc$height) | |
boxplot(cdc$height ~ cdc$gender) | |
bmi <- (cdc $ weight / cdc $ height ^2) * 703 | |
boxplot (bmi ~ cdc $ genhlth ) | |
hist(cdc$age) | |
hist(bmi) | |
hist(bmi, breaks = 50) | |
# Ex: On Your Own | |
# 1. Scatterplot of weight vs. desired weight | |
names(cdc) | |
plot(cdc$weight ~ cdc$wtdesire) | |
library("car") | |
plot(cdc$weight, cdc$wtdesire) | |
scatterplot(cdc$weight ~ cdc$wtdesire) | |
pairs(~cdc$weight+cdc$wtdesire, data=cdc, main="CDC weight vs desired weight") | |
# In general, desired weight of the respondents is less than actual weight. | |
# 2. New variable: wdiff | |
wdiff <- cdc$wtdesire - cdc$weight | |
str(wdiff) | |
# 3. wdiff data is integer. if = 0 then person is ok with own weight. + or - relates to person's own eval of weight | |
plot(wdiff) | |
plot(cdc$weight, cdc$wtdesire) | |
hist(wdiff, breaks = 25) | |
fivenum(wdiff) | |
summary(wdiff) # 4. In general, people want to lose 10 to 15 pounds. Centered at 10lbs to lose, the wdiff is normally distributed with a range of 21lbs. | |
# 6. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment