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 Hackathon 2018.csv")
head(data)
## date average_price total_volume type year geography
## 1 1/1/2018 1.47 113514 conventional 2018 Albany
## 2 1/1/2018 1.46 3464 organic 2018 Albany
## 3 1/1/2018 0.95 649353 conventional 2018 Atlanta
## 4 1/1/2018 1.28 17218 organic 2018 Atlanta
## 5 1/1/2018 1.15 849488 conventional 2018 Baltimore/Washington
## 6 1/1/2018 1.53 40942 organic 2018 Baltimore/Washington
## Mileage Total.sales.volume
## 1 2832 166865.58
## 2 2832 5057.44
## 3 2199 616885.35
## 4 2199 22039.04
## 5 2679 976911.20
## 6 2679 62641.26
install.packages('plyr')
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.1'
## (as 'lib' is unspecified)
## also installing the dependency 'Rcpp'
library(plyr)
count(data, 'geography')
## geography freq
## 1 Albany 98
## 2 Atlanta 98
## 3 Baltimore/Washington 98
## 4 Boise 98
## 5 Boston 98
## 6 Buffalo/Rochester 98
## 7 Charlotte 98
## 8 Chicago 98
## 9 Cincinnati/Dayton 98
## 10 Columbus 98
## 11 Dallas/Ft. Worth 98
## 12 Denver 98
## 13 Detroit 98
## 14 Grand Rapids 98
## 15 Harrisburg/Scranton 98
## 16 Hartford/Springfield 98
## 17 Houston 98
## 18 Indianapolis 98
## 19 Jacksonville 98
## 20 Las Vegas 98
## 21 Los Angeles 98
## 22 Louisville 98
## 23 Miami/Ft. Lauderdale 98
## 24 Nashville 98
## 25 New Orleans/Mobile 98
## 26 New York 98
## 27 Orlando 98
## 28 Philadelphia 98
## 29 Phoenix/Tucson 98
## 30 Pittsburgh 98
## 31 Portland 98
## 32 Raleigh/Greensboro 98
## 33 Richmond/Norfolk 98
## 34 Sacramento 98
## 35 San Diego 98
## 36 San Francisco 98
## 37 Seattle 98
## 38 Spokane 98
## 39 St. Louis 98
## 40 Syracuse 98
## 41 Tampa 98
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 3
## 12 0.66 3
## 13 0.67 6
## 14 0.68 4
## 15 0.69 3
## 16 0.71 7
## 17 0.72 6
## 18 0.73 11
## 19 0.74 10
## 20 0.75 7
## 21 0.76 8
## 22 0.77 10
## 23 0.78 10
## 24 0.79 7
## 25 0.80 7
## 26 0.81 11
## 27 0.82 4
## 28 0.83 8
## 29 0.84 13
## 30 0.85 11
## 31 0.86 6
## 32 0.87 15
## 33 0.88 15
## 34 0.89 14
## 35 0.90 6
## 36 0.91 15
## 37 0.92 22
## 38 0.93 18
## 39 0.94 16
## 40 0.95 25
## 41 0.96 30
## 42 0.97 24
## 43 0.98 29
## 44 0.99 38
## 45 1.00 28
## 46 1.01 37
## 47 1.02 26
## 48 1.03 36
## 49 1.04 40
## 50 1.05 30
## 51 1.06 29
## 52 1.07 32
## 53 1.08 37
## 54 1.09 50
## 55 1.10 41
## 56 1.11 29
## 57 1.12 41
## 58 1.13 44
## 59 1.14 55
## 60 1.15 54
## 61 1.16 73
## 62 1.17 50
## 63 1.18 46
## 64 1.19 51
## 65 1.20 55
## 66 1.21 44
## 67 1.22 45
## 68 1.23 53
## 69 1.24 47
## 70 1.25 57
## 71 1.26 44
## 72 1.27 58
## 73 1.28 54
## 74 1.29 54
## 75 1.30 45
## 76 1.31 49
## 77 1.32 59
## 78 1.33 33
## 79 1.34 50
## 80 1.35 53
## 81 1.36 59
## 82 1.37 48
## 83 1.38 62
## 84 1.39 48
## 85 1.40 47
## 86 1.41 56
## 87 1.42 53
## 88 1.43 56
## 89 1.44 43
## 90 1.45 51
## 91 1.46 44
## 92 1.47 36
## 93 1.48 41
## 94 1.49 30
## 95 1.50 41
## 96 1.51 35
## 97 1.52 36
## 98 1.53 43
## 99 1.54 30
## 100 1.55 42
## 101 1.56 40
## 102 1.57 37
## 103 1.58 23
## 104 1.59 37
## 105 1.60 37
## 106 1.61 24
## 107 1.62 29
## 108 1.63 31
## 109 1.64 39
## 110 1.65 37
## 111 1.66 37
## 112 1.67 29
## 113 1.68 24
## 114 1.69 31
## 115 1.70 24
## 116 1.71 17
## 117 1.72 21
## 118 1.73 20
## 119 1.74 19
## 120 1.75 20
## 121 1.76 21
## 122 1.77 19
## 123 1.78 19
## 124 1.79 19
## 125 1.80 20
## 126 1.81 16
## 127 1.82 16
## 128 1.83 22
## 129 1.84 14
## 130 1.85 17
## 131 1.86 12
## 132 1.87 8
## 133 1.88 13
## 134 1.89 5
## 135 1.90 10
## 136 1.91 11
## 137 1.92 16
## 138 1.93 10
## 139 1.94 11
## 140 1.95 13
## 141 1.96 5
## 142 1.97 5
## 143 1.98 4
## 144 1.99 6
## 145 2.00 5
## 146 2.01 5
## 147 2.02 11
## 148 2.03 6
## 149 2.04 9
## 150 2.05 8
## 151 2.06 6
## 152 2.07 8
## 153 2.08 7
## 154 2.09 7
## 155 2.10 3
## 156 2.11 7
## 157 2.12 1
## 158 2.13 4
## 159 2.14 6
## 160 2.15 5
## 161 2.16 8
## 162 2.17 1
## 163 2.18 4
## 164 2.19 2
## 165 2.20 3
## 166 2.21 4
## 167 2.22 3
## 168 2.23 2
## 169 2.24 4
## 170 2.25 6
## 171 2.26 3
## 172 2.27 3
## 173 2.28 1
## 174 2.30 3
## 175 2.31 2
## 176 2.32 1
## 177 2.33 1
## 178 2.35 1
## 179 2.39 1
## 180 2.40 1
## 181 2.41 1
## 182 2.43 1
## 183 2.48 1
## 184 2.49 1
## 185 2.50 1
## 186 2.52 1
## 187 2.56 1
## 188 2.60 1
## 189 2.66 1
## 190 2.71 1
mean(data$average_price)
## [1] 1.367302
median(data$average_price)
## [1] 1.34
cor(data$total_volume,data$average_price)
## [1] -0.4794885
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
## -741002 -264115 -109322 118520 4282049
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1339942 30637 43.74 <2e-16 ***
## average_price -755356 21815 -34.63 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 443600 on 4016 degrees of freedom
## Multiple R-squared: 0.2299, Adjusted R-squared: 0.2297
## F-statistic: 1199 on 1 and 4016 DF, p-value: < 2.2e-16
coefficients(regr)
## (Intercept) average_price
## 1339942 -755356
Beta <- regr$coefficients[["average_price"]]
P <- mean(data$average_price)
Q <- mean(data$total_volume)
elasticity <-Beta*P/Q
elasticity
## [1] -3.362613
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/