Robiłem to w R, oto mój kod dla moich danych zarówno dla danych w próbie, jak i poza próbką:
#accuracy testing for out-of-sample sample#
M<-#data#
deltaT<-#set observations per year,1/4 for quarterly, 1/12 for monthly
horiz<-#set amount of forecasts required
startY<-c(#,#) #set start date
N<-head(M,-horiz)
Nu<-log(Nu)
Nu<-ts(Nu,deltat=deltaT,start=startY)
#Run your forecasting method#
##My forecasting method is arima##
N<-#data#
N<-ts(N,deltat=deltaT,start=startY)
N<-tail(N,horiz)
fitted<-ts(append(fitted(Arimab), fArimab$mean[1]), deltat=deltaT, start = startY) #where Arimab is the ARIMA model and fArimab<-forecast(Arimab, h=horiz*2, simulate= TRUE, fan=TRUE)
N<-log(N)
fitted<-head(fitted,length(N))
error<-N-fitted
percenterror<-100*error/N
plus<-N+fitted
rmse<-function(error)
sqrt(mean(error^2))
mae<-function(error)
mean(abs(error))
mape<-function(percenterror)
mean(abs(percenterror))
smape<-function(error,plus)
mean(200*abs(error)/(plus))
mse<-function(error)
mean(error^2)
me<-function(error)
mean(error)
mpe<-function(percenterror)
mean(percenterror)
accuracy<-matrix(c("rmse","mae","mape","smape","mse","me","mpe",(round(rmse(error),digits=3)),(round(mae(error),digits=3)),(round(mape(percenterror),digits=3)),(round(smape(error,plus),digits=3)),(round(mse(error),digits=3)),(round(me(error),digits=3)),(round(mpe(percenterror),digits=3))),ncol=2,byrow=FALSE)
View(accuracy,title="Accuracy of ARIMA out sample")
#Accuracy testing for the in sample
M<-#data#
deltaT<-#set observations per year,1/4 for quarterly, 1/12 for monthly
horiz<-#set amount of forecasts required
startY<-c(#,#) #set start date
Nu<-log(Nu)
Nu<-ts(Nu,deltat=deltaT,start=startY)
#run your forecasting method#
fitted<-ts(append(fitted(Arimab), fArimab$mean[1]), deltat=deltaT, start = startY)
N<-exp(Nu)
fitted<-exp(fitted)
fitted<-head(fitted,length(N))
error<-N-fitted
percenterror<-100*error/N
plus<-N+fitted
rmse<-function(error)
sqrt(mean(error^2))
mae<-function(error)
mean(abs(error))
mape<-function(percenterror)
mean(abs(percenterror))
smape<-function(error,plus)
mean(200*abs(error)/(plus))
mse<-function(error)
mean(error^2)
me<-function(error)
mean(error)
mpe<-function(percenterror)
mean(percenterror)
accuracy<-matrix(c("rmse","mae","mape","smape","mse","me","mpe",(round(rmse(error),digits=3)),(round(mae(error),digits=3)),(round(mape(percenterror),digits=3)),(round(smape(error,plus),digits=3)),(round(mse(error),digits=3)),(round(me(error),digits=3)),(round(mpe(percenterror),digits=3))),ncol=2,byrow=FALSE)
View(accuracy,title="Accuracy of ARIMA in sample")
mam nadzieję, że to trochę pomoże. jeśli chcesz mój pełny kod, który kiedyś uruchamiałem, zapytaj, ponieważ jest to bardzo proste