d=read.csv(file.choose(),header=TRUE,sep=",")
head(d)
da=d[1:145,3]
class(d)
## [1] "data.frame"
price=ts(da)
class(price)
## [1] "ts"
a=price
plot=plot(a, xlab= 'Time in Months', ylab= 'Prices in Rupees', main= 'Monthly Price of Tomatoes')
library(tseries)
## Warning: package 'tseries' was built under R version 3.4.4
adf.test(a)
## Warning in adf.test(a): p-value smaller than printed p-value
##
## Augmented Dickey-Fuller Test
##
## data: a
## Dickey-Fuller = -5.0146, Lag order = 5, p-value = 0.01
## alternative hypothesis: stationary
acf(a)
pacf(a)
b=diff(a,1)
plot(b,xlab= 'Time in Months', ylab='Differenced prices in Rupees', main='Monthly Price of Tomatoes',col='blue')
acf(b,col="black")
pacf(b,col="black")
m1=arima (a,order=c(3,1, 0))
m1
##
## Call:
## arima(x = a, order = c(3, 1, 0))
##
## Coefficients:
## ar1 ar2 ar3
## -0.2879 -0.2553 -0.2529
## s.e. 0.0856 0.0869 0.0850
##
## sigma^2 estimated as 119: log likelihood = -548.61, aic = 1105.21
m2=arima(a,order=c(2,1,0))
m2
##
## Call:
## arima(x = a, order = c(2, 1, 0))
##
## Coefficients:
## ar1 ar2
## -0.2396 -0.1875
## s.e. 0.0866 0.0865
##
## sigma^2 estimated as 126.5: log likelihood = -552.89, aic = 1111.77
m3=arima (a,order=c(3,1,1))
m3
##
## Call:
## arima(x = a, order = c(3, 1, 1))
##
## Coefficients:
## ar1 ar2 ar3 ma1
## -0.2227 -0.2396 -0.2406 -0.0690
## s.e. 0.3489 0.1192 0.1098 0.3569
##
## sigma^2 estimated as 119: log likelihood = -548.59, aic = 1107.18
m4=arima (a,order=c(0,1,1))
m4
##
## Call:
## arima(x = a, order = c(0, 1, 1))
##
## Coefficients:
## ma1
## -0.3777
## s.e. 0.1189
##
## sigma^2 estimated as 126.8: log likelihood = -553.09, aic = 1110.18
plot (m1$residuals, col="blue" , main='Plot for Residuals of ARIMA(3,1,0)')
plot (m2$residuals, col="blue" , main='Plot for Residuals of ARIMA (2,1,0)')
plot (m3$residuals, col="blue", main='Plot for Residuals of ARIMA(3,1,1)')
plot (m4$residuals, col="blue",main='Plot for Residuals of ARIMA (0,1,1)')
library (forecast)
## Warning: package 'forecast' was built under R version 3.4.4
f1=forecast (m1, 12)
plot (f1)
f2=forecast (m2, 12)
plot(f2)
f3= forecast(m3, 12)
plot(f3)
f4= forecast(m4, 12)
plot(f4)
c=d[146:157,3]
f11=c(82.93997,73.46262,68.92472,76.27024,77.71155,76.56911, 74.67200, 75.145521, 75.78231, 75.95796, 75.62505,75.51488)
mse1=mean((c-f11)^2)
rmse1=sqrt(mse1)
rmse1
## [1] 31.7467
f22=c(84.99727,79.83876,83.37218,83.49276,82.80135,82.94441,83.03977,82.99010,82.98412,82.99487,82.99341,82.99175)
mse2=mean((c-f22)^2)
rmse2=sqrt(mse2)
rmse2
## [1] 36.47405
f33=c(74.14848,58.57164,58.57164,58.57164,58.57164,58.57164,58.57164,58.57164,58.57164,58.57164,58.57164,58.57164)
mse3=mean((c-f33)^2)
rmse3=sqrt(mse3)
rmse3
## [1] 25.31735
f44=c( 79.92707, 79.92707, 79.92707, 79.92707,79.92707, 79.92707,79.92707,79.92707,79.92707,79.92707,79.92707,79.92707)
mse4=mean((c-f44)^2)
rmse4=sqrt(mse4)
rmse4
## [1] 34.57647