R Markdown

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.

Objective

Your explanation here

Descriptive statistics

Your explanation here

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)
mean(data$average_price)
## [1] 1.358841
median(data$average_price)
## [1] 1.32
cor(data$total_volume,data$average_price)
## [1] -0.4169306

Price elasticity

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

Elasticity

Your conclusions here:

Ref: Salem, 2014. Price Elasticity with R. http://www.salemmarafi.com/code/price-elasticity-with-r/

365datascience. https://365datascience.com/trending/price-elasticity/