[Solved] R-Midterm Exam

$25

File Name: R-Midterm_Exam.zip
File Size: 131.88 KB

SKU: [Solved] R-Midterm Exam Category: Tag:
5/5 - (1 vote)

Question 1

  1. Consider code chunk Q1 and give the resulting output from the following R commands (or the resulting error if one is produced):
    1. my_Costco_list[2]
    2. my_Costco_list[[1]][2]
  • my_Costco_list[[1]][2,2]
  1. Consider code chunk Q1 and answer the following multiple choice questions (please list all that apply for each question):
    1. Which of the following commands returns the result Coffee?
    2. The class of the object returned by both_lists[2] is a
  • The class of the object returned by both_lists[[2]]$Location is a
  1. Consider code chunk Q1 for the following questions:
    1. Write a line of code that will change the Location column of the tibble in my_Costco_list to an ordered factor where the order of the levels is in the following order: Clothes, Cereal, Refrigerated.
    2. Write a line of code using your answer to part (i) to compute the minimum amount of items (not the number of different items) required in each location.

Question 2

  1. [15 marks] Please indicate which plot best summarizes the characeristic the characteristic (the name of the plot, not the function):
  1. Which plot best allows one to identify points that are outliers (i.e. far from the central location the data): A: Boxplot B: Histogram?
  2. Which plot best allows one to assess the skew of the data: A: Boxplot B: Histogram?
  • Which plot should be used to summarize the distribution of quantitative data that take on a large number of unique values: A: Histogram B: Barplot?
  1. Which plot should be used to summarize the counts from different levels of a qualitative factor variable: A: Histogram B: Barplot?
  2. If we want to compare the central 50% of the values of a quantiative variable across multiple levels of a separate qualitative variable, which plot should be used:
    1. One boxplot for each group in the same plot
    2. One boxplot for each group in a different plot
    3. One hisotogram for each group in the same plot
    4. One histogram for each group in a different plot?

Answer the parts (b), (c), and (d) below based on a dataset from Kaggle containing the prices of Hass avocados over a period of over three years. The original dataset is used in the book Introduction to Data Analysis and is available through the aida package in R (which you can install to access the data).

### You can install the aida package via:

### install.packages(remotes) ### remotes::install_github(michael-franke/aida-package)

library(aida) glimpse(data_avocado)

Rows: 18,249

Columns: 7

$ Date <date> 2015-12-27, 2015-12-20, 2015-12-13, 2015-12-06, 201

$ average_price <dbl> 1.33, 1.35, 0.93, 1.08, 1.28, 1.26, 0.99, 0.98, 1.02

$ total_volume_sold <dbl> 64236.62, 54876.98, 118220.22, 78992.15, 51039.60, 5

$ small <dbl> 1036.74, 674.28, 794.70, 1132.00, 941.48, 1184.27, 1

$ medium <dbl> 54454.85, 44638.81, 109149.67, 71976.41, 43838.39, 4

$ large <dbl> 48.16, 58.33, 130.50, 72.58, 75.78, 43.61, 93.26, 80 $ type <chr> conventional, conventional, conventional, con

data_avocado %>% arrange(Date) %>% head(.) %>% kable(.) %>% kable_styling()

Date average_price total_volume_sold small medium large type
2015-01-04 1.22 40873.28 2819.50 28287.42 49.90 conventional
2015-01-04 1.00 435021.49 364302.39 23821.16 82.15 conventional
2015-01-04 1.08 788025.06 53987.31 552906.04 39995.03 conventional
2015-01-04 1.01 80034.32 44562.12 24964.23 2752.35 conventional
2015-01-04 1.02 491738.00 7193.87 396752.18 128.82 conventional

2015-01-04 1.40 116253.44 3267.97 55693.04 109.55 conventional

Each row in the dataset contains information on the price and volume (in pounds) of avocados sold from one outlet on a particular date for a particular type of avocado (organic or conventional). The variables in the data set for each outlet one each date are as follows:

  1. Figure 1 shows three different panels examining the relationship between average price and type of avocado.
    1. Compare the distributions of the average prices for the conventional and organic avocados. In particular, compare their central locations, spreads and skew to conclude whether there is evidence in this data that the average prices of organic avocados is different from those of conventional avocados.
    2. The lines in the center of the boxes in Panel (a) indicate the value of a summary statistic of the daily outlet average prices for each of the two types of avocado in the dataset.

Write a function that will use the data_avocado object to compute these two values and return them in a tibble with one column for the type and the other with the summary statistic.

  • Explain what was changed or added to the code to yield the different figures for (b) and panel (c). In particular, explain why the bars look different in the two plots and why the y-axis scales of the figures are different.
  1. Figure 2 shows two different panels comparing how the total volume sold of conventional avocados change over time (note that both plots are plotted on a log scale).
    1. Which of the two panels, (a) or (b), best shows the pattern of total volume sold?

Explain your answer.

  1. Would a 2D histogram make sense to use for summarizing this particular relationship? Briefly explain why or why not.
  • Below is the line of code that generated the plot in panel (b). Change the line of code below so that it produces a pair plots that contains total_volume_sold for both conventional and organic separately over time (i.e. in different plotting areas of the same plot). s

ggplot(data_avocado %>% filter(type==conventional), aes(x=Date,y=total_volume_sold,group=Date)) + geom_boxplot() + ggtitle(Panel (b))+ scale_y_log10()

Why cant you use the original data_avocado data object to plot the total volume sold by the size of the avocados using the same figure you gave code to generate in part (iii) above? Explain why and then write a line of code which would allow you to generate the necessary data object which could then be used to make such a plot (you dont need to include the code for the plot).

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] R-Midterm Exam
$25