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_1718.csv")
head(data)
##      date average_price total_volume         type year            geography
## 1 12/3/17          1.39       139970 conventional 2017               Albany
## 2 12/3/17          1.44         3577      organic 2017               Albany
## 3 12/3/17          1.07       504933 conventional 2017              Atlanta
## 4 12/3/17          1.62        10609      organic 2017              Atlanta
## 5 12/3/17          1.43       658939 conventional 2017 Baltimore/Washington
## 6 12/3/17          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)
count(data, 'geography')
##               geography freq
## 1                Albany  108
## 2               Atlanta  108
## 3  Baltimore/Washington  108
## 4                 Boise  108
## 5                Boston  108
## 6     Buffalo/Rochester  108
## 7             Charlotte  108
## 8               Chicago  108
## 9     Cincinnati/Dayton  108
## 10             Columbus  108
## 11     Dallas/Ft. Worth  108
## 12               Denver  108
## 13              Detroit  108
## 14         Grand Rapids  108
## 15  Harrisburg/Scranton  108
## 16 Hartford/Springfield  108
## 17              Houston  108
## 18         Indianapolis  108
## 19         Jacksonville  108
## 20            Las Vegas  108
## 21          Los Angeles  108
## 22           Louisville  108
## 23 Miami/Ft. Lauderdale  108
## 24            Nashville  108
## 25   New Orleans/Mobile  108
## 26             New York  108
## 27              Orlando  108
## 28         Philadelphia  108
## 29       Phoenix/Tucson  108
## 30           Pittsburgh  108
## 31             Portland  108
## 32   Raleigh/Greensboro  108
## 33     Richmond/Norfolk  108
## 34           Sacramento  108
## 35            San Diego  108
## 36        San Francisco  108
## 37              Seattle  108
## 38              Spokane  108
## 39            St. Louis  108
## 40             Syracuse  108
## 41                Tampa  108
count(data, 'average_price')
##     average_price freq
## 1            0.50    1
## 2            0.51    1
## 3            0.53    1
## 4            0.54    1
## 5            0.56    3
## 6            0.57    1
## 7            0.58    2
## 8            0.59    3
## 9            0.61    2
## 10           0.62    1
## 11           0.64    4
## 12           0.66    3
## 13           0.67    6
## 14           0.68    4
## 15           0.69    3
## 16           0.70    1
## 17           0.71    7
## 18           0.72    7
## 19           0.73   12
## 20           0.74   10
## 21           0.75   10
## 22           0.76    8
## 23           0.77   11
## 24           0.78   11
## 25           0.79    8
## 26           0.80    8
## 27           0.81   12
## 28           0.82    4
## 29           0.83   10
## 30           0.84   14
## 31           0.85   12
## 32           0.86    7
## 33           0.87   16
## 34           0.88   17
## 35           0.89   16
## 36           0.90    8
## 37           0.91   16
## 38           0.92   24
## 39           0.93   20
## 40           0.94   18
## 41           0.95   26
## 42           0.96   31
## 43           0.97   27
## 44           0.98   31
## 45           0.99   44
## 46           1.00   30
## 47           1.01   46
## 48           1.02   30
## 49           1.03   43
## 50           1.04   43
## 51           1.05   33
## 52           1.06   32
## 53           1.07   37
## 54           1.08   40
## 55           1.09   51
## 56           1.10   45
## 57           1.11   31
## 58           1.12   42
## 59           1.13   54
## 60           1.14   64
## 61           1.15   59
## 62           1.16   78
## 63           1.17   54
## 64           1.18   53
## 65           1.19   54
## 66           1.20   58
## 67           1.21   45
## 68           1.22   45
## 69           1.23   55
## 70           1.24   51
## 71           1.25   63
## 72           1.26   51
## 73           1.27   63
## 74           1.28   60
## 75           1.29   59
## 76           1.30   49
## 77           1.31   53
## 78           1.32   60
## 79           1.33   36
## 80           1.34   53
## 81           1.35   56
## 82           1.36   64
## 83           1.37   56
## 84           1.38   65
## 85           1.39   57
## 86           1.40   55
## 87           1.41   63
## 88           1.42   57
## 89           1.43   61
## 90           1.44   50
## 91           1.45   59
## 92           1.46   51
## 93           1.47   37
## 94           1.48   45
## 95           1.49   32
## 96           1.50   44
## 97           1.51   38
## 98           1.52   40
## 99           1.53   46
## 100          1.54   36
## 101          1.55   45
## 102          1.56   47
## 103          1.57   38
## 104          1.58   29
## 105          1.59   47
## 106          1.60   41
## 107          1.61   30
## 108          1.62   31
## 109          1.63   34
## 110          1.64   41
## 111          1.65   39
## 112          1.66   38
## 113          1.67   32
## 114          1.68   26
## 115          1.69   33
## 116          1.70   25
## 117          1.71   19
## 118          1.72   25
## 119          1.73   22
## 120          1.74   21
## 121          1.75   23
## 122          1.76   22
## 123          1.77   22
## 124          1.78   20
## 125          1.79   25
## 126          1.80   23
## 127          1.81   20
## 128          1.82   20
## 129          1.83   27
## 130          1.84   15
## 131          1.85   18
## 132          1.86   14
## 133          1.87    9
## 134          1.88   14
## 135          1.89    6
## 136          1.90   12
## 137          1.91   12
## 138          1.92   17
## 139          1.93   11
## 140          1.94   12
## 141          1.95   13
## 142          1.96    5
## 143          1.97    5
## 144          1.98    4
## 145          1.99    7
## 146          2.00    6
## 147          2.01    6
## 148          2.02   11
## 149          2.03    7
## 150          2.04    9
## 151          2.05    9
## 152          2.06    8
## 153          2.07    9
## 154          2.08    7
## 155          2.09    7
## 156          2.10    4
## 157          2.11    8
## 158          2.12    3
## 159          2.13    4
## 160          2.14    7
## 161          2.15    5
## 162          2.16    8
## 163          2.17    1
## 164          2.18    4
## 165          2.19    2
## 166          2.20    3
## 167          2.21    4
## 168          2.22    3
## 169          2.23    2
## 170          2.24    4
## 171          2.25    6
## 172          2.26    3
## 173          2.27    4
## 174          2.28    1
## 175          2.30    3
## 176          2.31    2
## 177          2.32    1
## 178          2.33    1
## 179          2.35    1
## 180          2.39    1
## 181          2.40    1
## 182          2.41    1
## 183          2.43    1
## 184          2.48    1
## 185          2.49    1
## 186          2.50    1
## 187          2.52    1
## 188          2.56    1
## 189          2.60    1
## 190          2.66    1
## 191          2.71    1
mean(data$average_price)
## [1] 1.367866
median(data$average_price)
## [1] 1.35
cor(data$total_volume,data$average_price)
## [1] -0.4822304

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 
## -734315 -258668 -106296  115217 4288802 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    1330796      28850   46.13   <2e-16 ***
## average_price  -752078      20537  -36.62   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 437300 on 4426 degrees of freedom
## Multiple R-squared:  0.2325, Adjusted R-squared:  0.2324 
## F-statistic:  1341 on 1 and 4426 DF,  p-value: < 2.2e-16
coefficients(regr)
##   (Intercept) average_price 
##     1330796.1     -752077.7
Beta <- regr$coefficients[["average_price"]]
P <- mean(data$average_price)
Q <- mean(data$total_volume)
elasticity <-Beta*P/Q
elasticity
## [1] -3.405812

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/