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

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 
## -29036 -16186  -9212   5385 471453 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      13574       1836   7.392 1.63e-13 ***
## average_price     7395       1143   6.467 1.08e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 28420 on 6312 degrees of freedom
## Multiple R-squared:  0.006582,   Adjusted R-squared:  0.006425 
## F-statistic: 41.82 on 1 and 6312 DF,  p-value: 1.075e-10
coefficients(regr)
##   (Intercept) average_price 
##     13574.048      7394.563
Beta <- regr$coefficients[["average_price"]]
P <- mean(data$average_price)
Q <- mean(data$total_volume)
elasticity <-Beta*P/Q
elasticity
## [1] 0.4618033

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/