Practice Exercise - The Weymouth Health Survey
In 2003-2004 Weymouth conducted a town-wide health survey, the results of which raised concerns about the general health of the residents. The data set below is a subset of the actual data that was collected and analyzed by John Snow, Inc.
First, open the Weymouth data set from this link: WeymouthSurveyData.csv
Save the data set to your computer. Then load the data set into R either be using the import data set function or by using the command
Begin a new script in the RStudio editor with the following code:WeymouthSurveyData <- read.csv(file.choose())
### Part 1###
# The first command below creates a data frame object called 'wey'. This is a short nickname for the data set.
wey<-WeymouthSurveyData
# Next, attach the data set
attach(wey)
# Create a derived variable for the respondent's age in 2002 (when the data was collected) based on their reported birth year.
age=(2002-birth_yr)
# Compute body mass index (BMI) as shown below.
bmi=weight/(hgt_inch)^2*703
# Compute the mean and standard deviation of bmi and quantiles
mean(bmi)
[1] 26.62516
sd(bmi)
[1] 5.257648
quantile(bmi)
0% 25% 50% 75% 100%
3.719577 23.052515 25.799445 29.190311 54.548669
summary(bmi)
Min. 1st Qu. Median Mean 3rd Qu. Max.
3.72 23.05 25.80 26.63 29.19 54.55
The next page continues the exercise with code that produces histograms and boxplots.