R version 2.8.0 (2008-10-20) Copyright (C) 2008 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(1593,1477.9,1733.7,1569.7,1843.7,1950.3,1657.5,1772.1,1568.3,1809.8,1646.7,1808.5,1763.9,1625.5,1538.8,1342.4,1645.1,1619.9,1338.1,1505.5,1529.1,1511.9,1656.7,1694.4,1662.3,1588.7,1483.3,1585.6,1658.9,1584.4,1470.6,1618.7,1407.6,1473.9,1515.3,1485.4,1496.1,1493.5,1298.4,1375.3,1507.9,1455.3,1363.3,1392.8,1348.8,1880.3,1669.2,1543.6,1701.2,1516.5,1466.8,1484.1,1577.2,1684.5,1414.7,1674.5,1598.7,1739.1,1674.6,1671.8,1802,1526.8,1580.9,1634.8,1610.3,1712,1678.8,1708.1,1680.6,2056,1624,2021.4,1861.1,1750.8,1767.5,1710.3,2151.5,2047.9,1915.4,1984.7,1896.5,2170.8,2139.9,2330.5,2121.8,2226.8,1857.9,2155.9,2341.7,2290.2,2006.5,2111.9,1731.3,1762.2,1863.2,1943.5,1975.2) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '0' > 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 sma1 -0.7311 -0.4136 -0.9999 s.e. 0.1091 0.1130 0.3248 sigma^2 estimated as 11370: log likelihood = -450.36, aic = 908.73 > (forecast <- predict(arima.out,fx)) $pred Time Series: Start = 86 End = 97 Frequency = 1 [1] 2094.432 2085.937 2014.915 2230.648 2236.500 2051.742 2176.686 2088.125 [9] 2312.950 2211.272 2311.954 2274.535 $se Time Series: Start = 86 End = 97 Frequency = 1 [1] 114.4023 118.3605 126.2383 143.9039 150.8110 159.6679 169.5259 176.8737 [9] 184.8769 192.4911 199.3690 206.6848 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 86 End = 97 Frequency = 1 [1] 1870.204 1853.950 1767.488 1948.596 1940.911 1738.792 1844.415 1741.453 [9] 1950.591 1833.990 1921.191 1869.433 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 86 End = 97 Frequency = 1 [1] 2318.661 2317.923 2262.342 2512.700 2532.090 2364.691 2508.956 2434.798 [9] 2675.308 2588.555 2702.717 2679.637 > 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] 1593.000 1477.900 1733.700 1569.700 1843.700 1950.300 1657.500 1772.100 [9] 1568.300 1809.800 1646.700 1808.500 1763.900 1625.500 1538.800 1342.400 [17] 1645.100 1619.900 1338.100 1505.500 1529.100 1511.900 1656.700 1694.400 [25] 1662.300 1588.700 1483.300 1585.600 1658.900 1584.400 1470.600 1618.700 [33] 1407.600 1473.900 1515.300 1485.400 1496.100 1493.500 1298.400 1375.300 [41] 1507.900 1455.300 1363.300 1392.800 1348.800 1880.300 1669.200 1543.600 [49] 1701.200 1516.500 1466.800 1484.100 1577.200 1684.500 1414.700 1674.500 [57] 1598.700 1739.100 1674.600 1671.800 1802.000 1526.800 1580.900 1634.800 [65] 1610.300 1712.000 1678.800 1708.100 1680.600 2056.000 1624.000 2021.400 [73] 1861.100 1750.800 1767.500 1710.300 2151.500 2047.900 1915.400 1984.700 [81] 1896.500 2170.800 2139.900 2330.500 2121.800 2094.432 2085.937 2014.915 [89] 2230.648 2236.500 2051.742 2176.686 2088.125 2312.950 2211.272 2311.954 [97] 2274.535 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 86 End = 97 Frequency = 1 [1] 0.05462210 0.05674215 0.06265192 0.06451217 0.06743170 0.07782068 [7] 0.07788259 0.08470454 0.07993124 0.08704992 0.08623399 0.09086903 > postscript(file="/var/www/html/rcomp/tmp/1rjk41229364006.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/2mbrr1229364006.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/3z4z81229364007.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/4wn2t1229364007.tab") > > system("convert tmp/1rjk41229364006.ps tmp/1rjk41229364006.png") > system("convert tmp/2mbrr1229364006.ps tmp/2mbrr1229364006.png") > > > proc.time() user system elapsed 0.818 0.345 3.480