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

Do a b c and d

Descriptive statistics

Our variables are listed below

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