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_C.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.07       504933 conventional 2017              Atlanta
## 3 12/3/17          1.43       658939 conventional 2017 Baltimore/Washington
## 4 12/3/17          1.14        86646 conventional 2017                Boise
## 5 12/3/17          1.40       488588 conventional 2017               Boston
## 6 12/3/17          1.13       153282 conventional 2017    Buffalo/Rochester
##   Mileage
## 1    2832
## 2    2199
## 3    2679
## 4     827
## 5    2998
## 6    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.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   10
## 19           0.70   21
## 20           0.71   20
## 21           0.72   23
## 22           0.73   32
## 23           0.74   34
## 24           0.75   25
## 25           0.76   36
## 26           0.77   29
## 27           0.78   35
## 28           0.79   24
## 29           0.80   39
## 30           0.81   46
## 31           0.82   37
## 32           0.83   40
## 33           0.84   52
## 34           0.85   48
## 35           0.86   48
## 36           0.87   55
## 37           0.88   61
## 38           0.89   77
## 39           0.90   70
## 40           0.91   81
## 41           0.92   81
## 42           0.93   84
## 43           0.94   80
## 44           0.95   97
## 45           0.96   85
## 46           0.97   96
## 47           0.98  101
## 48           0.99  100
## 49           1.00  104
## 50           1.01  119
## 51           1.02   82
## 52           1.03  114
## 53           1.04  116
## 54           1.05   87
## 55           1.06  100
## 56           1.07   91
## 57           1.08   94
## 58           1.09  114
## 59           1.10  114
## 60           1.11   88
## 61           1.12   96
## 62           1.13  107
## 63           1.14  136
## 64           1.15  109
## 65           1.16  119
## 66           1.17  115
## 67           1.18  104
## 68           1.19  102
## 69           1.20  108
## 70           1.21   81
## 71           1.22   87
## 72           1.23   76
## 73           1.24   76
## 74           1.25   82
## 75           1.26   82
## 76           1.27   90
## 77           1.28   86
## 78           1.29   97
## 79           1.30   68
## 80           1.31   80
## 81           1.32   75
## 82           1.33   54
## 83           1.34   62
## 84           1.35   71
## 85           1.36   70
## 86           1.37   61
## 87           1.38   69
## 88           1.39   60
## 89           1.40   54
## 90           1.41   60
## 91           1.42   61
## 92           1.43   44
## 93           1.44   40
## 94           1.45   43
## 95           1.46   36
## 96           1.47   41
## 97           1.48   33
## 98           1.49   33
## 99           1.50   41
## 100          1.51   30
## 101          1.52   35
## 102          1.53   42
## 103          1.54   18
## 104          1.55   23
## 105          1.56   19
## 106          1.57   19
## 107          1.58   16
## 108          1.59   22
## 109          1.60   17
## 110          1.61   15
## 111          1.62   11
## 112          1.63   10
## 113          1.64   13
## 114          1.65   10
## 115          1.66   11
## 116          1.67   11
## 117          1.68    7
## 118          1.69    7
## 119          1.70    7
## 120          1.71    4
## 121          1.72    9
## 122          1.73    3
## 123          1.74    8
## 124          1.75    6
## 125          1.76    4
## 126          1.77    7
## 127          1.78    6
## 128          1.79    4
## 129          1.80    4
## 130          1.81    3
## 131          1.82    4
## 132          1.83    2
## 133          1.84    1
## 134          1.86    2
## 135          1.87    2
## 136          1.88    1
## 137          1.89    2
## 138          1.90    1
## 139          1.91    2
## 140          1.92    1
## 141          1.95    1
## 142          1.96    2
## 143          1.98    2
## 144          2.01    1
## 145          2.02    1
mean(data$average_price)
## [1] 1.142566
median(data$average_price)
## [1] 1.13
cor(data$total_volume,data$average_price)
## [1] -0.177141

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 
## -668069 -397312 -181986  201191 4813886 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    1159708      38139   30.41   <2e-16 ***
## average_price  -467729      32709  -14.30   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 604800 on 6312 degrees of freedom
## Multiple R-squared:  0.03138,    Adjusted R-squared:  0.03123 
## F-statistic: 204.5 on 1 and 6312 DF,  p-value: < 2.2e-16
coefficients(regr)
##   (Intercept) average_price 
##     1159708.1     -467728.6
Beta <- regr$coefficients[["average_price"]]
P <- mean(data$average_price)
Q <- mean(data$total_volume)
elasticity <-Beta*P/Q
elasticity
## [1] -0.8546503

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/