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.
To analyze the difference in price between organic and conventional avocados
My first goal is to look at the summary statistics of the dataset.
data_organic <- read.csv("avocado_organic.csv")
data_conventional <- read.csv("avocado_conventional.csv")
#install.packages('plyr')
library(plyr)
mean(data_organic$average_price)
## [1] 1.575117
mean(data_conventional$average_price)
## [1] 1.142566
hist(data_organic$average_price ,
main = "Histogram of average_price for organic avocados",
xlab = "Price in USD (US Dollar)")
hist(data_conventional$average_price ,
main = "Histogram of average_price for conventional avocados",
xlab = "Price in USD (US Dollar)")
cor(data_organic$total_volume,data_organic$average_price)
## [1] 0.08112979
cor(data_conventional$total_volume,data_conventional$average_price)
## [1] -0.177141
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_organic)
regr <- lm(total_volume ~ average_price, data_organic)
abline(regr, col='red')
summary(regr)
##
## Call:
## lm(formula = total_volume ~ average_price, data = data_organic)
##
## 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_organic$average_price)
Q <- mean(data_organic$total_volume)
elasticity <-Beta*P/Q
elasticity
## [1] 0.4618033
plot(total_volume ~ average_price, data_conventional)
regr <- lm(total_volume ~ average_price, data_conventional)
abline(regr, col='red')
summary(regr)
##
## Call:
## lm(formula = total_volume ~ average_price, data = data_conventional)
##
## 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_conventional$average_price)
Q <- mean(data_conventional$total_volume)
elasticity <-Beta*P/Q
elasticity
## [1] -0.8546503
# Using Smoothing average forecasting
timeseries <- ts(data_organic$average_price)
plot.ts(timeseries)
library("forecast") # load the "forecast" R library
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
timeseriesarima <- arima(timeseries, order=c(0,1,1)) # fit an ARIMA(0,1,1) model
# Use the function ets() to perform a forecasting model
fit <- ets(timeseries)
# Plot 20-year forecasts of the lynx series
fit %>% forecast(h = 200) %>% autoplot()
#We can plot the observed prices for the current periods, as well as the prices that would be predicted for the next 200 time periods.
# Using Smoothing average forecasting
timeseries <- ts(data_conventional$average_price)
plot.ts(timeseries)
library("forecast") # load the "forecast" R library
timeseriesarima <- arima(timeseries, order=c(0,1,1)) # fit an ARIMA(0,1,1) model
# Use the function ets() to perform a forecasting model
fit <- ets(timeseries)
# Plot 20-year forecasts of the lynx series
fit %>% forecast(h = 200) %>% autoplot()
#We can plot the observed prices for the current periods, as well as the prices that would be predicted for the next 200 time periods.
My conclusions will be added once I finish the analysis!
Salem, 2014. Price Elasticity with R. http://www.salemmarafi.com/code/price-elasticity-with-r/ 365datascience. https://365datascience.com/trending/price-elasticity/