R version 2.9.0 (2009-04-17) Copyright (C) 2009 The R Foundation for Statistical Computing ISBN 3-900051-07-0 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(2916,2434,2540,2349,2310,2189,2660,2194,2419,2742,2137,2710,2173,2363,2126,1905,2121,1983,1734,2074,2049,2406,2558,2251,2059,2397,1747,1707,2319,1631,1627,1791,2034,1997,2169,2028,2253,2218,1855,2187,1852,1570,1851,1954,1828,2251,2277,2085,2282,2266,1878,2267,2069,1746,2299,2360,2214,2825,2355,2333,3016,2155,2172,2150,2533,2058,2160,2260,2498,2695,2799,2947,2930,2318,2540,2570,2669,2450,2842,3440,2678,2981,2260,2844,2546,2456,2295,2379,2479,2057,2280,2351,2276,2548,2311,2201,2725,2408,2139,1898,2537,2069,2063,2524,2437,2189,2793,2074,2622,2278,2144,2427,2139,1828,2072,1800,1758,2246,1987,1868,2514) > par10 = 'FALSE' > par9 = '1' > par8 = '1' > par7 = '1' > par6 = '3' > par5 = '12' > par4 = '0' > par3 = '1' > 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 ma1 sar1 sma1 0.0468 0.1857 0.2391 -0.8391 0.9603 -0.8230 s.e. 0.2232 0.1926 0.1432 0.1877 0.1141 0.2722 sigma^2 estimated as 61532: log likelihood = -669.14, aic = 1352.27 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 98 End = 121 Frequency = 1 [1] 2279.286 2204.261 2319.840 2337.930 2110.059 2287.870 2389.265 2319.946 [9] 2540.160 2373.361 2432.402 2529.008 2324.621 2226.896 2281.005 2344.421 [17] 2111.040 2276.066 2381.477 2310.741 2522.148 2363.110 2418.852 2511.777 $se Time Series: Start = 98 End = 121 Frequency = 1 [1] 248.9731 254.2465 269.2367 292.1405 301.3986 313.3699 324.6842 333.8391 [9] 343.3152 352.1776 360.5004 368.7937 385.5183 394.5001 404.3990 414.7974 [17] 423.7317 432.8148 441.6730 450.1343 458.5418 466.7178 474.6825 482.6853 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 98 End = 121 Frequency = 1 [1] 1791.299 1705.937 1792.136 1765.335 1519.318 1673.665 1752.884 1665.622 [9] 1867.262 1683.093 1725.821 1806.173 1569.005 1453.676 1488.383 1531.418 [17] 1280.526 1427.749 1515.798 1428.478 1623.406 1448.343 1488.475 1565.714 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 98 End = 121 Frequency = 1 [1] 2767.274 2702.584 2847.544 2910.525 2700.801 2902.075 3025.646 2974.271 [9] 3213.058 3063.629 3138.983 3251.844 3080.237 3000.117 3073.627 3157.423 [17] 2941.554 3124.383 3247.156 3193.005 3420.890 3277.877 3349.230 3457.840 > 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] 2916.000 2434.000 2540.000 2349.000 2310.000 2189.000 2660.000 2194.000 [9] 2419.000 2742.000 2137.000 2710.000 2173.000 2363.000 2126.000 1905.000 [17] 2121.000 1983.000 1734.000 2074.000 2049.000 2406.000 2558.000 2251.000 [25] 2059.000 2397.000 1747.000 1707.000 2319.000 1631.000 1627.000 1791.000 [33] 2034.000 1997.000 2169.000 2028.000 2253.000 2218.000 1855.000 2187.000 [41] 1852.000 1570.000 1851.000 1954.000 1828.000 2251.000 2277.000 2085.000 [49] 2282.000 2266.000 1878.000 2267.000 2069.000 1746.000 2299.000 2360.000 [57] 2214.000 2825.000 2355.000 2333.000 3016.000 2155.000 2172.000 2150.000 [65] 2533.000 2058.000 2160.000 2260.000 2498.000 2695.000 2799.000 2947.000 [73] 2930.000 2318.000 2540.000 2570.000 2669.000 2450.000 2842.000 3440.000 [81] 2678.000 2981.000 2260.000 2844.000 2546.000 2456.000 2295.000 2379.000 [89] 2479.000 2057.000 2280.000 2351.000 2276.000 2548.000 2311.000 2201.000 [97] 2725.000 2279.286 2204.261 2319.840 2337.930 2110.059 2287.870 2389.265 [105] 2319.946 2540.160 2373.361 2432.402 2529.008 2324.621 2226.896 2281.005 [113] 2344.421 2111.040 2276.066 2381.477 2310.741 2522.148 2363.110 2418.852 [121] 2511.777 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 98 End = 121 Frequency = 1 [1] 0.1092329 0.1153432 0.1160583 0.1249569 0.1428389 0.1369702 0.1358929 [8] 0.1438995 0.1351549 0.1483877 0.1482076 0.1458254 0.1658413 0.1771524 [15] 0.1772899 0.1769296 0.2007218 0.1901592 0.1854617 0.1948008 0.1818061 [22] 0.1975015 0.1962429 0.1921688 > postscript(file="/var/www/html/rcomp/tmp/1pb891260440276.ps",horizontal=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/html/rcomp/tmp/2pm4d1260440276.ps",horizontal=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/html/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/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/html/rcomp/tmp/3ut3x1260440276.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/html/rcomp/tmp/449at1260440276.tab") > > system("convert tmp/1pb891260440276.ps tmp/1pb891260440276.png") > system("convert tmp/2pm4d1260440276.ps tmp/2pm4d1260440276.png") > > > proc.time() user system elapsed 1.007 0.325 1.157