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(423.4,404.1,500,472.6,496.1,562,434.8,538.2,577.6,518.1,625.2,561.2,523.3,536.1,607.3,637.3,606.9,652.9,617.2,670.4,729.9,677.2,710,844.3,748.2,653.9,742.6,854.2,808.4,1819,1936.5,1966.1,2083.1,1620.1,1527.6,1795,1685.1,1851.8,2164.4,1981.8,1726.5,2144.6,1758.2,1672.9,1837.3,1596.1,1446,1898.4,1964.1,1755.9,2255.3,1881.2,2117.9,1656.5,1544.1,2098.9,2133.3,1963.5,1801.2,2365.4,1936.5,1667.6,1983.5,2058.6,2448.3,1858.1,1625.4,2130.6,2515.7,2230.2,2086.9,2235,2100.2,2288.6,2490,2573.7,2543.8,2004.7,2390,2338.4,2724.5,2292.5,2386,2477.9,2337,2605.1,2560.8,2839.3,2407.2,2085.2,2735.6,2798.7,3053.2,2405,2471.9,2727.3,2790.7,2385.4,3206.6,2705.6,3518.4,1954.9,2584.3,2535.8,2685.9,2866,2236.6,2934.9,2668.6,2371.2,3165.9,2887.2,3112.2,2671.2,2432.6,2812.3,3095.7,2862.9,2607.3,2862.5) > par10 = 'FALSE' > par9 = '1' > par8 = '2' > par7 = '1' > par6 = '2' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '1' > par1 = '12' > #'GNU S' R Code compiled by R2WASP v. 1.0.44 () > #Author: Prof. Dr. P. Wessa > #To cite this work: AUTHOR(S), (YEAR), YOUR SOFTWARE TITLE (vNUMBER) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_YOURPAGE.wasp/ > #Source of accompanying publication: Office for Research, Development, and Education > #Technical description: Write here your technical program description (don't use hard returns!) > 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 ma1 sar1 sar2 sma1 0.3460 0.3482 -0.9556 -0.0992 -0.3318 -0.3438 s.e. 0.1148 0.1071 0.0600 0.2055 0.1297 0.2113 sigma^2 estimated as 76322: log likelihood = -672.69, aic = 1359.37 > (forecast <- predict(arima.out,fx)) $pred Time Series: Start = 109 End = 120 Frequency = 1 [1] 2737.755 2623.568 3186.707 2943.090 3455.431 2365.740 2782.747 2817.457 [9] 3063.024 3013.050 2667.805 3121.985 $se Time Series: Start = 109 End = 120 Frequency = 1 [1] 276.2787 296.6007 330.5182 345.4110 358.9884 368.0273 375.4703 381.2704 [9] 386.1364 390.2471 393.8437 397.0456 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 109 End = 120 Frequency = 1 [1] 2196.249 2042.231 2538.892 2266.085 2751.814 1644.407 2046.825 2070.167 [9] 2306.197 2248.166 1895.871 2343.775 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 109 End = 120 Frequency = 1 [1] 3279.261 3204.906 3834.523 3620.095 4159.048 3087.074 3518.669 3564.747 [9] 3819.852 3777.935 3439.739 3900.194 > 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] 423.400 404.100 500.000 472.600 496.100 562.000 434.800 538.200 [9] 577.600 518.100 625.200 561.200 523.300 536.100 607.300 637.300 [17] 606.900 652.900 617.200 670.400 729.900 677.200 710.000 844.300 [25] 748.200 653.900 742.600 854.200 808.400 1819.000 1936.500 1966.100 [33] 2083.100 1620.100 1527.600 1795.000 1685.100 1851.800 2164.400 1981.800 [41] 1726.500 2144.600 1758.200 1672.900 1837.300 1596.100 1446.000 1898.400 [49] 1964.100 1755.900 2255.300 1881.200 2117.900 1656.500 1544.100 2098.900 [57] 2133.300 1963.500 1801.200 2365.400 1936.500 1667.600 1983.500 2058.600 [65] 2448.300 1858.100 1625.400 2130.600 2515.700 2230.200 2086.900 2235.000 [73] 2100.200 2288.600 2490.000 2573.700 2543.800 2004.700 2390.000 2338.400 [81] 2724.500 2292.500 2386.000 2477.900 2337.000 2605.100 2560.800 2839.300 [89] 2407.200 2085.200 2735.600 2798.700 3053.200 2405.000 2471.900 2727.300 [97] 2790.700 2385.400 3206.600 2705.600 3518.400 1954.900 2584.300 2535.800 [105] 2685.900 2866.000 2236.600 2934.900 2737.755 2623.568 3186.707 2943.090 [113] 3455.431 2365.740 2782.747 2817.457 3063.024 3013.050 2667.805 3121.985 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 109 End = 120 Frequency = 1 [1] 0.1009143 0.1130524 0.1037178 0.1173634 0.1038911 0.1555654 0.1349279 [8] 0.1353243 0.1260638 0.1295189 0.1476284 0.1271773 > postscript(file="/var/www/html/rcomp/tmp/1j4b31259788892.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.se <- array(0, dim=fx) > perf.mse <- 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.mape[i] = perf.mape[i] + abs(perf.pe[i]) + perf.se[i] = (x[nx+i] - forecast$pred[i])^2 + perf.mse[i] = perf.mse[i] + perf.se[i] + 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 = perf.mape / fx > perf.mse = perf.mse / fx > perf.rmse = sqrt(perf.mse) > postscript(file="/var/www/html/rcomp/tmp/263jn1259788892.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:12] <- 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/3u44d1259788892.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.mape[i],4)) + a<-table.element(a,round(perf.se[i],4)) + a<-table.element(a,round(perf.mse[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/4i5151259788892.tab") > > system("convert tmp/1j4b31259788892.ps tmp/1j4b31259788892.png") > system("convert tmp/263jn1259788892.ps tmp/263jn1259788892.png") > > > proc.time() user system elapsed 3.039 0.339 3.187