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

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 
## -655706 -290480 -136151  114574 4927991 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    1118605      21201   52.76   <2e-16 ***
## average_price  -576686      15117  -38.15   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 500600 on 8198 degrees of freedom
## Multiple R-squared:  0.1508, Adjusted R-squared:  0.1507 
## F-statistic:  1455 on 1 and 8198 DF,  p-value: < 2.2e-16
coefficients(regr)
##   (Intercept) average_price 
##     1118604.9     -576686.2
Beta <- regr$coefficients[["average_price"]]
P <- mean(data$average_price)
Q <- mean(data$total_volume)
elasticity <-Beta*P/Q
elasticity
## [1] -2.31154

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/