Download R Supplement

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Version 1.0
Box Plots
Reloading data:
R Code
load(url("http://mobilize.stat.ucla.edu/day2/data/yrbss_07.Rda"))
Description
Load CDC data from UCLA
Output
>
R Code
women <- subset(cdc,gender=="Female")
Description
Save the subset of all Females into the object women
Output
>
R Code
men <- subset(cdc,gender=="Male")
Description
Save the subset of all Males into the object men
Output
>
Remember how to get a summary?
R Code
summary(men$weight)
Description
Summary of men’s weight.
Output
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
34.47 63.05 70.76 74.61 83.01 181.00 420.00
Exploring Computer Science—Unit 6: Participatory Urban Sensing “R” Supplement
Page 1
Version 1.0
We can look at it graphically:
R Code
boxplot(men$weight, range=0)
Description Create a box plot of men’s weight. It is a graphical representation of the summary.
Output
Exploring Computer Science—Unit 6: Participatory Urban Sensing “R” Supplement
Page 2
Version 1.0
Exploring Computer Science—Unit 6: Participatory Urban Sensing “R” Supplement
Page 3
Version 1.0
Exploring Computer Science—Unit 6: Participatory Urban Sensing “R” Supplement
Page 4
Version 1.0
Exploring Computer Science—Unit 6: Participatory Urban Sensing “R” Supplement
Page 5
Version 1.0
Exploring Computer Science—Unit 6: Participatory Urban Sensing “R” Supplement
Page 6
Version 1.0
***Box Plots can be placed side by side broken up by answers to a category
R Code
boxplot(cdc$weight~cdc$gender,range=0)
Description Boxplot of only the female’s weight on the left and only the male’s weights on the right. This
shows a relationship between a quantitative variable (weight) and a categorical (gender).
Output
1. According to the boxplots above, on average are females or males heavier?
2. What command would you use to compare weight and general_health? Write it down and paste the
resulting boxplots in a document. What story do you see?
Exploring Computer Science—Unit 6: Participatory Urban Sensing “R” Supplement
Page 7
Version 1.0
** Transforming data
If you want to see your height in feet instead of meters you can transform it.
R Code
cdc <- transform(cdc,
height=height/(0.0254*12),weight=weight/0.4536)
Description
Convert height from meters to feet and weight from kg to pounds. Once it is
converted this way, it will stay converted.
Output
>
R Code
summary(cdc$height)
Output
3. What is the mean height now?
Part IV—
***Zooming in on Box Plots
R Code
new_cdc<-cdc
Description Create a copy of cdc called new_cdc
Output
>
R Code
boxplot(new_cdc$weight~new_cdc$drink_soda, range=0)
Exploring Computer Science—Unit 6: Participatory Urban Sensing “R” Supplement
Page 8
Version 1.0
Description Comparing weight to drinking soda seems like not much of a difference zoomed out. We need
to zoom in to see a trend.
Output
R Code
boxplot(new_cdc$weight~new_cdc$drink_soda, range=0,ylim=c(135,150))
Description Zoom in between 135 and 150lbs (this was done after we changed kgs to lbs). Now
we can see a difference in weight.
Output
4. Paste the resulting plot below.
**BMI (if you’re interested)
If you want to look at weight taking to account height, you could use the BMI (Body Mass Index). BMI =
weight (kg) / [height (m)]^2. You can create it using:
> cdc$bmi <- cdc$weight/(cdc$height*cdc$height)
The weight and height must be in kg and m’s so if you transformed yours, you have to go back and load
the old data.
Exploring Computer Science—Unit 6: Participatory Urban Sensing “R” Supplement
Page 9
Version 1.0
R Code
names(cdc)
Description
All the survey questions
Output
5. Make 3 interesting plots and paste them in a document. Some of them may be Bar Plots or Mosaic
Plots using categorical variables like we did a few days ago. Include your interpretation of the plot.
Above are the names of all the questions and the possible answers are below:
Here is a list of the survey questions and answers:
Subset of questions from the YRBSS
age
grade
gender: Female or Male
hisp_latino: Are you Hispanic or Latino? (Yes or No)
race: What is your race? (Select one or more responses.)
A. American Indian or Alaska Native
B. Asian
C. Black or African American
D. Native Hawaiian or Other Pacific Islander
E White
height (in meters)
weight (in kilograms)
Exploring Computer Science—Unit 6: Participatory Urban Sensing “R” Supplement
Page 10
Version 1.0
general_health: How do you describe your health in general?
A. Excellent B. Very good C. Good D. Fair
hours_sleep: On an average school night, how many hours of sleep do you get?
A. 4 or less hours
B. 5 hours
C. 6 hours
D. 7 hours
E. 8 hours
F. 9 hours
G. 10 or more hours
asthma: Has a doctor or nurse ever told you that you have asthma?
Yes, No or Not Sure.
depressed: During the past 12 months, did you ever feel so sad or
hopeless almost every day for two weeks or more in a row that you
stopped doing some usual activities? Yes or No.
helmet: When you rode a bicycle during the past 12 months, how often
did you wear a helmet?
A. I did not ride a bicycle during the past 12 months
B. Never wore a helmet
C. Rarely wore a helmet
D. Sometimes wore a helmet
E. Most of the time wore a helmet
F. Always wore a helmet
seat_belt: How often do you wear a seat belt when riding in a car
driven by someone else?
A. Never B. Rarely C. Sometimes D. Most of the time E. Always
sunscreen: When you are outside for more than one hour on a sunny day,
how often do you wear sunscreen with an SPF of 15 or higher?
A. Never B. Rarely C. Sometimes D. Most of the time E. Always
describe_weight: How do you describe your weight?
A. Very underweight
B. Slightly underweight
C. About the right weight
D. Slightly overweight
E. Very overweight
eat_fruit:
(Do not
A. I
B. 1
C. 4
D. 1
E. 2
F. 3
G. 4
During the past 7 days, how many times did you eat fruit?
count fruit juice.)
did not eat fruit during the past 7 days
to 3 times during the past 7 days
to 6 times during the past 7 days
time per day
times per day
times per day
or more times per day
eat_salad: During the past 7 days, how many times did you eat green salad?
A. I did not eat green salad during the past 7 days
Exploring Computer Science—Unit 6: Participatory Urban Sensing “R” Supplement
Page 11
Version 1.0
B.
C.
D.
E.
F.
G.
1
4
1
2
3
4
to 3 times during the past 7 days
to 6 times during the past 7 days
time per day
times per day
times per day
or more times per day
drink_soda: During the past 7 days, how many times did you drink a can,
bottle, or glass of soda or pop, such as Coke, Pepsi, or Sprite?
(Do not include diet soda or diet pop.)
A. I did not drink soda or pop during the past 7 days
B. 1 to 3 times during the past 7 days
C. 4 to 6 times during the past 7 days
D. 1 time per day
E. 2 times per day
F. 3 times per day
G. 4 or more times per day
drink_milk:
During the past 7 days, how many glasses of milk did you
drink? (Include the milk you drank in a glass or cup, from a carton,
or with cereal. Count the half pint of milk served at school as equal
to one glass.)
A. I did not drink milk during the past 7 days
B. 1 to 3 glasses during the past 7 days
C. 4 to 6 glasses during the past 7 days
D. 1 glass per day
E. 2 glasses per day
F. 3 glasses per day
G. 4 or more glasses per day
days_exercise_20: On how many of the past 7 days did you exercise or
participate in physical activity for at least 20 minutes that made
you sweat and breathe hard, such as basketball, soccer, running,
swimming laps, fast bicycling, fast dancing, or similar
aerobic activities?
A. 0 days
B. 1 day
C. 2 days
D. 3 days
E. 4 days
F. 5 days
G. 6 days
H. 7 days
days_exercise_60: During the past 7 days, on how many days were you
physically
active for a total of at least 60 minutes per day? (Add up all the
time you spend in any kind of physical activity that increases your
heart rate and makes you breathe hard some of the time.)
A. 0 days
B. 1 day
C. 2 days
D. 3 days
E. 4 days
F. 5 days
Exploring Computer Science—Unit 6: Participatory Urban Sensing “R” Supplement
Page 12
Version 1.0
G. 6 days
H. 7 days
number_teams: During the past 12 months, on how many sports teams did
you play? (Include any teams run by your school or community groups.)
A. 0 teams B. 1 team C. 2 teams D. 3 or more teams
hours_tv: On an average school day, how many hours do you watch TV?
A. I do not watch TV on an average school day
B. Less than 1 hour per day
C. 1 hour per day
D. 2 hours per day
E. 3 hours per day
F. 4 hours per day
G. 5 or more hours per day
hours_videogame: On an average school day, how many hours do you play
video or computer games or use a computer for something that is not
school work? (Include activities such as Nintendo, Game Boy,
PlayStation, Xbox, computer games, and the Internet.)
A. I do not play video or computer games or use a computer
for something that is not school work
B. Less than 1 hour per day
C. 1 hour per day
D. 2 hours per day
E. 3 hours per day
F. 4 hours per day
G. 5 or more hours per day
days_smoking: During the past 30 days, on how many days did you
smoke cigarettes?
A. 0 days B. 1 or 2 days C. 3 to 5 days D. 6 to 9 days
E. 10 to 19 days F. 20 to 29 days G. All 30 days
fights: During the past 12 months, how many times were you in a
physical fight?
A. 0 times B. 1 time C. 2 or 3 times D. 4 or 5 times
E. 6 or 7 times F. 8 or 9 times G. 10 or 11 times H. 12 or more times
Exploring Computer Science—Unit 6: Participatory Urban Sensing “R” Supplement
Page 13