library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6 ✔ purrr 0.3.4
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.4.1
## ✔ readr 2.1.2 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(readr)
dat <- read.csv("avocado.csv", header=TRUE, sep = ",")
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
Note: this analysis was performed using the open source software R and Rstudio.
Interpreting the data given on the sales of conventional and organic avocados across the nation. Take note of factors that may effect avocado sales. Notice the difference in sales between the two different types of avocados and how they vary by each city. Explain your reasonings below:
Which city has the largest sales of organic and conventional Hass avocados in the dollar amount, respectively, for each year (i.e., 2017, 2018, 2019, 2020)? In 2017, the highest avocado sales for organic was in New York, for conventional avocados the highest avocado sales were in Los Angeles.
What could be the possible reasons for Hass avocado’s popularity in these cities? You may use summary statistics, a pivot table (or chart), or any additional analysis to show your results. The state of California has the highest number of sales for avocados specifically San Francisco and Los Angeles. When looking at all the data nationwide, you can see that the most avocado sales are in larger cities. This is probably because they tend to be more health conscious that other cities.
Are there any effects of Hass avocado prices on sales volumes? You may use a pivot table (or chart) or regression analysis for this analysis. Regardless of the price, people will continue to purchase avocados. Yes, a change in price will have a slight impact on demand therefore it will result in lower sales, however for people that consume avocados almost daily, it makes no difference.
Are there any seasonal factors that may affect Hass avocado prices and sales volume? If so, please use figures or tables to explain what the seasonality patterns might look like. How would you suggest avocado growers and trade associations deal with seasonality issues or factors? Seasonal factors might affect avocado prices however, they could always be imported from other countries which is why we have most fruits and vegetables year-round in our grocery stores.
Open-ended question - Propose a business problem you could answer with the dashboard and explain your answers briefly. Do you think the temporary ban on imported avocados from Mexico effected avocado sales. Will the limited supply on avocados cause their price to increase?
data <- read.csv("avocado.csv")
head(data)
## date average_price total_volume type year geography
## 1 2017/12/3 1.39 139970 conventional 2017 Albany
## 2 2017/12/3 1.44 3577 organic 2017 Albany
## 3 2017/12/3 1.07 504933 conventional 2017 Atlanta
## 4 2017/12/3 1.62 10609 organic 2017 Atlanta
## 5 2017/12/3 1.43 658939 conventional 2017 Baltimore/Washington
## 6 2017/12/3 1.58 38754 organic 2017 Baltimore/Washington
## Mileage
## 1 2832
## 2 2832
## 3 2199
## 4 2199
## 5 2679
## 6 2679
#install.packages('plyr')
library(plyr)
## ------------------------------------------------------------------------------
## You have loaded plyr after dplyr - this is likely to cause problems.
## If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
## library(plyr); library(dplyr)
## ------------------------------------------------------------------------------
##
## Attaching package: 'plyr'
## The following objects are masked from 'package:dplyr':
##
## arrange, count, desc, failwith, id, mutate, rename, summarise,
## summarize
## The following object is masked from 'package:purrr':
##
## compact
mean(data$average_price)
## [1] 1.358841
median(data$average_price)
## [1] 1.32
cor(data$total_volume,data$average_price)
## [1] -0.4169306
To calculate Price Elasticity of Demand we use the formula: PE = (ΔQ/ΔP) * (P/Q) # (Iacobacci, 2015, p.134-135).
(ΔQ/ΔP) is determined by the coefficient in our regression analysis below. Here Beta represents the change in the dependent variable y with respect to x (i.e. Δy/Δx = (ΔQ/ΔP)). To determine (P/Q) we will use the average price and average sales volume (Salem, 2014).
plot(total_volume ~ average_price, data)
regr <- lm(total_volume ~ average_price, data)
abline(regr, col='red')
summary(regr)
##
## Call:
## lm(formula = total_volume ~ average_price, data = data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -679205 -277566 -128592 118917 4901891
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1179545 17117 68.91 <2e-16 ***
## average_price -628687 12198 -51.54 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 480300 on 12626 degrees of freedom
## Multiple R-squared: 0.1738, Adjusted R-squared: 0.1738
## F-statistic: 2657 on 1 and 12626 DF, p-value: < 2.2e-16
coefficients(regr)
## (Intercept) average_price
## 1179544.8 -628686.6
Beta <- regr$coefficients[["average_price"]]
P <- mean(data$average_price)
Q <- mean(data$total_volume)
elasticity <-Beta*P/Q
elasticity
## [1] -2.626474
Your conclusions here: The elasticity for avocados is -2.63 meaning that an increase in price will result in a decrease in quality demanded. Although, people will continue to purchase it but not as much due to the high price.
Ref: Salem, 2014. Price Elasticity with R. http://www.salemmarafi.com/code/price-elasticity-with-r/
365datascience. https://365datascience.com/trending/price-elasticity/