R version 2.12.0 (2010-10-15) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i486-pc-linux-gnu (32-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > x <- c(5.2 + ,7.9 + ,8.7 + ,8.9 + ,15.3 + ,15.4 + ,18.1 + ,19.7 + ,13 + ,12.6 + ,6.2 + ,3.5 + ,3.4 + ,0 + ,9.5 + ,8.9 + ,10.4 + ,13.2 + ,18.9 + ,19 + ,16.3 + ,10.6 + ,5.8 + ,3.6 + ,2.6 + ,5 + ,7.3 + ,9.2 + ,15.7 + ,16.8 + ,18.4 + ,18.1 + ,14.6 + ,7.8 + ,7.6 + ,3.8 + ,5.6 + ,2.2 + ,6.8 + ,11.8 + ,14.9 + ,16.7 + ,16.7 + ,15.9 + ,13.6 + ,9.2 + ,2.8 + ,2.5 + ,4.8 + ,2.8 + ,7.8 + ,9 + ,12.9 + ,16.4 + ,21.8 + ,17.8 + ,13.5 + ,10 + ,10.4 + ,5.5 + ,4 + ,6.8 + ,5.7 + ,9.1 + ,13.6 + ,15 + ,20.9 + ,20.4 + ,14 + ,13.7 + ,7.1 + ,0.8 + ,2.1 + ,1.3 + ,3.9 + ,10.7 + ,11.1 + ,16.4 + ,17.1 + ,17.3 + ,12.9 + ,10.9 + ,5.3 + ,0.7 + ,-0.2 + ,6.5 + ,8.6 + ,8.5 + ,13.3 + ,16.2 + ,17.5 + ,21.2 + ,14.8 + ,10.3 + ,7.3 + ,5.1 + ,4.4 + ,6.2 + ,7.7 + ,9.3 + ,15.6 + ,16.3 + ,16.6 + ,17.4 + ,15.3 + ,9.7 + ,3.7 + ,4.6 + ,5.4 + ,3.1 + ,7.9 + ,10.1 + ,15 + ,15.6 + ,19.7 + ,18.1 + ,17.7 + ,10.7 + ,6.2 + ,4.2 + ,4 + ,5.9 + ,7.1 + ,10.5 + ,15.1 + ,16.8 + ,15.3 + ,18.4 + ,16.1 + ,11.3 + ,7.9 + ,5.6 + ,3.4 + ,4.8 + ,6.5 + ,8.5 + ,15.1 + ,15.7 + ,18.7 + ,19.2 + ,12.9 + ,14.4 + ,6.2 + ,3.3 + ,4.6 + ,7.2 + ,7.8 + ,9.9 + ,13.6 + ,17.1 + ,17.8 + ,18.6 + ,14.7 + ,10.5 + ,8.6 + ,4.4 + ,2.3 + ,2.8 + ,8.8 + ,10.7 + ,13.9 + ,19.3 + ,19.5 + ,20.4 + ,15.3 + ,7.9 + ,8.3 + ,4.5 + ,3.2 + ,5 + ,6.6 + ,11.1 + ,12.8 + ,16.3 + ,17.4 + ,18.9 + ,15.8 + ,11.7 + ,6.4 + ,2.9 + ,4.7 + ,2.4 + ,7.2 + ,10.7 + ,13.4 + ,18.5 + ,18.3 + ,16.8 + ,16.6 + ,14.1 + ,6.1 + ,3.5 + ,1.7 + ,2.3 + ,4.5 + ,9.3 + ,14.2 + ,17.3 + ,23 + ,16.3 + ,18.4 + ,14.2 + ,9.1 + ,5.9 + ,7.2 + ,6.8 + ,8 + ,14.3 + ,14.6 + ,17.5 + ,17.2 + ,17.2 + ,14.1 + ,10.5 + ,6.8 + ,4.1 + ,6.5 + ,6.1 + ,6.3 + ,9.3 + ,16.4 + ,16.1 + ,18 + ,17.6 + ,14 + ,10.5 + ,6.9 + ,2.8 + ,0.7 + ,3.6 + ,6.7 + ,12.5 + ,14.4 + ,16.5 + ,18.7 + ,19.4 + ,15.8 + ,11.3 + ,9.7 + ,2.9) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '0' > par6 = '3' > par5 = '12' > par4 = '1' > par3 = '0' > par2 = '1' > par1 = '24' > #'GNU S' R Code compiled by R2WASP v. 1.0.44 () > #Author: Prof. Dr. P. Wessa > #To cite this work: Wessa P., (2009), ARIMA Forecasting (v1.0.5) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_arimaforecasting.wasp/ > #Source of accompanying publication: > #Technical description: > par1 <- as.numeric(par1) #cut off periods > par2 <- as.numeric(par2) #lambda > par3 <- as.numeric(par3) #degree of non-seasonal differencing > par4 <- as.numeric(par4) #degree of seasonal differencing > par5 <- as.numeric(par5) #seasonal period > par6 <- as.numeric(par6) #p > par7 <- as.numeric(par7) #q > par8 <- as.numeric(par8) #P > par9 <- as.numeric(par9) #Q > if (par10 == 'TRUE') par10 <- TRUE > if (par10 == 'FALSE') par10 <- FALSE > if (par2 == 0) x <- log(x) > if (par2 != 0) x <- x^par2 > lx <- length(x) > first <- lx - 2*par1 > nx <- lx - par1 > nx1 <- nx + 1 > fx <- lx - nx > if (fx < 1) { + fx <- par5 + nx1 <- lx + fx - 1 + first <- lx - 2*fx + } > first <- 1 > if (fx < 3) fx <- round(lx/10,0) > (arima.out <- arima(x[1:nx], order=c(par6,par3,par7), seasonal=list(order=c(par8,par4,par9), period=par5), include.mean=par10, method='ML')) Call: arima(x = x[1:nx], order = c(par6, par3, par7), seasonal = list(order = c(par8, par4, par9), period = par5), include.mean = par10, method = "ML") Coefficients: ar1 ar2 ar3 0.1244 0.0638 0.1625 s.e. 0.0690 0.0712 0.0711 sigma^2 estimated as 5.578: log likelihood = -464.84, aic = 937.68 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 217 End = 240 Frequency = 1 [1] 6.227890 6.190350 7.569547 14.049536 14.442278 17.394429 17.136090 [8] 17.159676 14.073745 10.483773 6.789751 4.093422 6.223780 6.187753 [15] 7.567892 14.048496 14.441621 17.394012 17.135828 17.159510 14.073640 [22] 10.483706 6.789709 4.093395 $se Time Series: Start = 217 End = 240 Frequency = 1 [1] 2.361741 2.379948 2.387305 2.425003 2.427620 2.428677 2.430175 2.430406 [9] 2.430499 2.430571 2.430588 2.430595 3.392064 3.404973 3.410203 3.436828 [17] 3.438696 3.439450 3.440515 3.440679 3.440746 3.440797 3.440809 3.440814 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 217 End = 240 Frequency = 1 [1] 1.59887712 1.52565122 2.89042851 9.29653078 9.68414289 12.63422220 [7] 12.37294652 12.39607924 9.30996652 5.71985341 2.02579875 -0.67054415 [13] -0.42466627 -0.48599464 0.88389421 7.31231304 7.70177743 10.65268973 [19] 10.39241865 10.41577799 7.32977846 3.73974467 0.04572408 -2.65059953 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 217 End = 240 Frequency = 1 [1] 10.856902 10.855049 12.248665 18.802541 19.200413 22.154635 21.899234 [8] 21.923272 18.837524 15.247692 11.553704 8.857388 12.872225 12.861501 [15] 14.251890 20.784679 21.181464 24.135334 23.879237 23.903241 20.817502 [22] 17.227668 13.533695 10.837390 > if (par2 == 0) { + x <- exp(x) + forecast$pred <- exp(forecast$pred) + lb <- exp(lb) + ub <- exp(ub) + } > if (par2 != 0) { + x <- x^(1/par2) + forecast$pred <- forecast$pred^(1/par2) + lb <- lb^(1/par2) + ub <- ub^(1/par2) + } > if (par2 < 0) { + olb <- lb + lb <- ub + ub <- olb + } > (actandfor <- c(x[1:nx], forecast$pred)) [1] 5.200000 7.900000 8.700000 8.900000 15.300000 15.400000 18.100000 [8] 19.700000 13.000000 12.600000 6.200000 3.500000 3.400000 0.000000 [15] 9.500000 8.900000 10.400000 13.200000 18.900000 19.000000 16.300000 [22] 10.600000 5.800000 3.600000 2.600000 5.000000 7.300000 9.200000 [29] 15.700000 16.800000 18.400000 18.100000 14.600000 7.800000 7.600000 [36] 3.800000 5.600000 2.200000 6.800000 11.800000 14.900000 16.700000 [43] 16.700000 15.900000 13.600000 9.200000 2.800000 2.500000 4.800000 [50] 2.800000 7.800000 9.000000 12.900000 16.400000 21.800000 17.800000 [57] 13.500000 10.000000 10.400000 5.500000 4.000000 6.800000 5.700000 [64] 9.100000 13.600000 15.000000 20.900000 20.400000 14.000000 13.700000 [71] 7.100000 0.800000 2.100000 1.300000 3.900000 10.700000 11.100000 [78] 16.400000 17.100000 17.300000 12.900000 10.900000 5.300000 0.700000 [85] -0.200000 6.500000 8.600000 8.500000 13.300000 16.200000 17.500000 [92] 21.200000 14.800000 10.300000 7.300000 5.100000 4.400000 6.200000 [99] 7.700000 9.300000 15.600000 16.300000 16.600000 17.400000 15.300000 [106] 9.700000 3.700000 4.600000 5.400000 3.100000 7.900000 10.100000 [113] 15.000000 15.600000 19.700000 18.100000 17.700000 10.700000 6.200000 [120] 4.200000 4.000000 5.900000 7.100000 10.500000 15.100000 16.800000 [127] 15.300000 18.400000 16.100000 11.300000 7.900000 5.600000 3.400000 [134] 4.800000 6.500000 8.500000 15.100000 15.700000 18.700000 19.200000 [141] 12.900000 14.400000 6.200000 3.300000 4.600000 7.200000 7.800000 [148] 9.900000 13.600000 17.100000 17.800000 18.600000 14.700000 10.500000 [155] 8.600000 4.400000 2.300000 2.800000 8.800000 10.700000 13.900000 [162] 19.300000 19.500000 20.400000 15.300000 7.900000 8.300000 4.500000 [169] 3.200000 5.000000 6.600000 11.100000 12.800000 16.300000 17.400000 [176] 18.900000 15.800000 11.700000 6.400000 2.900000 4.700000 2.400000 [183] 7.200000 10.700000 13.400000 18.500000 18.300000 16.800000 16.600000 [190] 14.100000 6.100000 3.500000 1.700000 2.300000 4.500000 9.300000 [197] 14.200000 17.300000 23.000000 16.300000 18.400000 14.200000 9.100000 [204] 5.900000 7.200000 6.800000 8.000000 14.300000 14.600000 17.500000 [211] 17.200000 17.200000 14.100000 10.500000 6.800000 4.100000 6.227890 [218] 6.190350 7.569547 14.049536 14.442278 17.394429 17.136090 17.159676 [225] 14.073745 10.483773 6.789751 4.093422 6.223780 6.187753 7.567892 [232] 14.048496 14.441621 17.394012 17.135828 17.159510 14.073640 10.483706 [239] 6.789709 4.093395 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 217 End = 240 Frequency = 1 [1] 0.3792201 0.3844610 0.3153829 0.1726037 0.1680912 0.1396238 0.1418162 [8] 0.1416348 0.1726974 0.2318413 0.3579790 0.5937807 0.5450168 0.5502762 [15] 0.4506146 0.2446403 0.2381101 0.1977376 0.2007790 0.2005115 0.2444816 [22] 0.3282042 0.5067682 0.8405769 > postscript(file="/var/www/rcomp/tmp/1blr71293467651.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > opar <- par(mar=c(4,4,2,2),las=1) > ylim <- c( min(x[first:nx],lb), max(x[first:nx],ub)) > plot(x,ylim=ylim,type='n',xlim=c(first,lx)) > usr <- par('usr') > rect(usr[1],usr[3],nx+1,usr[4],border=NA,col='lemonchiffon') > rect(nx1,usr[3],usr[2],usr[4],border=NA,col='lavender') > abline(h= (-3:3)*2 , col ='gray', lty =3) > polygon( c(nx1:lx,lx:nx1), c(lb,rev(ub)), col = 'orange', lty=2,border=NA) > lines(nx1:lx, lb , lty=2) > lines(nx1:lx, ub , lty=2) > lines(x, lwd=2) > lines(nx1:lx, forecast$pred , lwd=2 , col ='white') > box() > par(opar) > dev.off() null device 1 > prob.dec <- array(NA, dim=fx) > prob.sdec <- array(NA, dim=fx) > prob.ldec <- array(NA, dim=fx) > prob.pval <- array(NA, dim=fx) > perf.pe <- array(0, dim=fx) > perf.mape <- array(0, dim=fx) > perf.mape1 <- array(0, dim=fx) > perf.se <- array(0, dim=fx) > perf.mse <- array(0, dim=fx) > perf.mse1 <- array(0, dim=fx) > perf.rmse <- array(0, dim=fx) > for (i in 1:fx) { + locSD <- (ub[i] - forecast$pred[i]) / 1.96 + perf.pe[i] = (x[nx+i] - forecast$pred[i]) / forecast$pred[i] + perf.se[i] = (x[nx+i] - forecast$pred[i])^2 + prob.dec[i] = pnorm((x[nx+i-1] - forecast$pred[i]) / locSD) + prob.sdec[i] = pnorm((x[nx+i-par5] - forecast$pred[i]) / locSD) + prob.ldec[i] = pnorm((x[nx] - forecast$pred[i]) / locSD) + prob.pval[i] = pnorm(abs(x[nx+i] - forecast$pred[i]) / locSD) + } > perf.mape[1] = abs(perf.pe[1]) > perf.mse[1] = abs(perf.se[1]) > for (i in 2:fx) { + perf.mape[i] = perf.mape[i-1] + abs(perf.pe[i]) + perf.mape1[i] = perf.mape[i] / i + perf.mse[i] = perf.mse[i-1] + perf.se[i] + perf.mse1[i] = perf.mse[i] / i + } > perf.rmse = sqrt(perf.mse1) > postscript(file="/var/www/rcomp/tmp/27dpg1293467651.ps",horizontal=F,onefile=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > plot(forecast$pred, pch=19, type='b',main='ARIMA Extrapolation Forecast', ylab='Forecast and 95% CI', xlab='time',ylim=c(min(lb),max(ub))) > dum <- forecast$pred > dum[1:par1] <- x[(nx+1):lx] > lines(dum, lty=1) > lines(ub,lty=3) > lines(lb,lty=3) > dev.off() null device 1 > > #Note: the /var/www/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/rcomp/createtable") > > a<-table.start() > a<-table.row.start(a) > a<-table.element(a,'Univariate ARIMA Extrapolation Forecast',9,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'time',1,header=TRUE) > a<-table.element(a,'Y[t]',1,header=TRUE) > a<-table.element(a,'F[t]',1,header=TRUE) > a<-table.element(a,'95% LB',1,header=TRUE) > a<-table.element(a,'95% UB',1,header=TRUE) > a<-table.element(a,'p-value
(H0: Y[t] = F[t])',1,header=TRUE) > a<-table.element(a,'P(F[t]>Y[t-1])',1,header=TRUE) > a<-table.element(a,'P(F[t]>Y[t-s])',1,header=TRUE) > mylab <- paste('P(F[t]>Y[',nx,sep='') > mylab <- paste(mylab,'])',sep='') > a<-table.element(a,mylab,1,header=TRUE) > a<-table.row.end(a) > for (i in (nx-par5):nx) { + a<-table.row.start(a) + a<-table.element(a,i,header=TRUE) + a<-table.element(a,x[i]) + a<-table.element(a,'-') + a<-table.element(a,'-') + a<-table.element(a,'-') + a<-table.element(a,'-') + a<-table.element(a,'-') + a<-table.element(a,'-') + a<-table.element(a,'-') + a<-table.row.end(a) + } > for (i in 1:fx) { + a<-table.row.start(a) + a<-table.element(a,nx+i,header=TRUE) + a<-table.element(a,round(x[nx+i],4)) + a<-table.element(a,round(forecast$pred[i],4)) + a<-table.element(a,round(lb[i],4)) + a<-table.element(a,round(ub[i],4)) + a<-table.element(a,round((1-prob.pval[i]),4)) + a<-table.element(a,round((1-prob.dec[i]),4)) + a<-table.element(a,round((1-prob.sdec[i]),4)) + a<-table.element(a,round((1-prob.ldec[i]),4)) + a<-table.row.end(a) + } > a<-table.end(a) > table.save(a,file="/var/www/rcomp/tmp/37nld1293467651.tab") > a<-table.start() > a<-table.row.start(a) > a<-table.element(a,'Univariate ARIMA Extrapolation Forecast Performance',7,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'time',1,header=TRUE) > a<-table.element(a,'% S.E.',1,header=TRUE) > a<-table.element(a,'PE',1,header=TRUE) > a<-table.element(a,'MAPE',1,header=TRUE) > a<-table.element(a,'Sq.E',1,header=TRUE) > a<-table.element(a,'MSE',1,header=TRUE) > a<-table.element(a,'RMSE',1,header=TRUE) > a<-table.row.end(a) > for (i in 1:fx) { + a<-table.row.start(a) + a<-table.element(a,nx+i,header=TRUE) + a<-table.element(a,round(perc.se[i],4)) + a<-table.element(a,round(perf.pe[i],4)) + a<-table.element(a,round(perf.mape1[i],4)) + a<-table.element(a,round(perf.se[i],4)) + a<-table.element(a,round(perf.mse1[i],4)) + a<-table.element(a,round(perf.rmse[i],4)) + a<-table.row.end(a) + } > a<-table.end(a) > table.save(a,file="/var/www/rcomp/tmp/4ao211293467651.tab") > > try(system("convert tmp/1blr71293467651.ps tmp/1blr71293467651.png",intern=TRUE)) character(0) > try(system("convert tmp/27dpg1293467651.ps tmp/27dpg1293467651.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.910 0.410 1.303