Vous êtes sur la page 1sur 4

load_lab( )

Lab 1E: What's the Relationship?

Finding patterns in data

1. What is the objective for this lab?To discover


(really) interesting observations or relationships in
data, we need to find them!
Habits campaign? Go to
2. What steps did you take to import the data from the Food
mobilize.lausd.net and log into your account. Next go to the campaign section on the upper
left of the page. Next go to the campaign that you are trying to download and press on the
responses option and press export data. Go onto Rstudio and click on files on the bottom right
section of the page. Then upload your exported data from your files to rstudio. Lastly go to
Import Dataset on the top right section of the page and click on From local file and press
your data set, you rename it to the necessary name needed them click okay, all done.

Where's the variables?

3. How many variables were used to create this plot? Which variables were used and how were
they used? 3 variables were used in the data set below. Male, Female, and height were used
in the data set and they were used to compare heights and separate them by gender.

Scatterplots

4. Describe in your own words what a scatterplot looks like. A graph where two variables are
plotted along two axes, the organization is not well to understand, but the two variable that are in
the chart are all scattered.

Creating Scatterplots

5. What kind of variables are represented in scatterplots? Numerical Variables ae represented in


a scatterplot..
6. a) Fill in the blanks to create a scatterplot with sodium on the y-axis and sugar on the x-axis.
xyplot(__sodium__ ~ __sugar__, data = food)
b) Paste the plot here:
load_lab( )
5

Scatterplots in action

7. Use a scatterplot to answer the following question: Do snacks that have more calories also
have more total_fat? Why do you think that?
a) What code did you use to create the scatterplot? xyplot(total_fat~calories, data=
food)
b) Paste the scatterplot here:

c) Answer the original question. Snacks that have more calories do have more total fat. I
think this because the data set shows this by the calories and total fat being so clustered
together.
d) What happens if you swap the calories and total_fat variables in your code? Does the
relationship between the variables change? The relationship does not change the calories
and total fat are still clustered together in the same area.
e) Does the relationship between calories and total_fat change when the snack is either Salty
or Sweet? Write down the code you used to answer this question. The answer does not
change in the chart. The total fat and calories os still clustered in the same area even
though the food was salty or sweet. The code I used was
xyplot(total_fat~calories|salty_sweet, data= food ).
load_lab( )
5

4-variable scatterplots

8. How can we change the color of the points in a scatterplot? You add the groups argument.
9. Create a scatterplot that uses these 4 variables: sodium, sugar, healthy_level, salty_sweet.
a) What code did you use?xyplot(sodium+sugar~healthy_level+salty_sweet,data=food)
b) Paste the scatterplot here:

Multiple facets

10. How do you modify a code to facet by two variables instead of just one? By splitting the the data
using 2 facets can give us additional insights that might otherwise be hidden.
11. How does the healthy_level of a Salty or Sweet snack impact the number of calories in the
snack?
a) What is the code that you used to create a plot?histogram(~calories|healthy_level+salty_sweet,
data = food)
b) Paste the plot here:

c) Answer the question. If the snack were to have a low healthy level it may have a higher
amount of sugar and sodium and if the healthy level were higher it would have less
sodium and sugar.
load_lab( )
5

On your own

12. Do healthier snacks cost more or less than less healthy snacks?
a) What is the code that you used to create a plot?histogram(~cost|healthy_level, data = food)

b) Paste the plot here:

c) Answer the question. Food that is more healthy tended to cost more than the food that was
less healthy.

13. What other variables seem to be related to the cost of a snack? Indicate the code and the
plot
you used to answer the questions. Describe their relationships.

Vous aimerez peut-être aussi