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(2072.65,2020.13,2032.76,2050.31,2128.98,2122.14,2122.89,2091.95,2002.97,1923.21,1834.44,1819.15,1792.00,1822.40,1900.70,1903.00,1958.80,1820.50,1719.80,1661.10,1664.40,1703.40,1774.90,1795.00,1816.30,1867.40,1900.00,1961.10,2065.70,2073.50,2080.80,2118.00,2099.00,2085.20,1937.70,1749.50,1750.30,1675.60,1697.50,1699.80,1655.90,1636.00,1614.20,1602.30,1548.70,1556.10,1526.90,1509.20,1566.30,1596.00,1654.50,1664.20,1687.70,1691.00,1664.60,1697.50,1685.10,1643.00,1559.60,1560.20,1590.16,1604.93,1661.80,1670.73,1692.40,1688.17,1658.04,1613.46,1595.11,1558.83,1526.65,1475.19) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '0' > par6 = '1' > par5 = '12' > par4 = '0' > par3 = '1' > par2 = '-1.7' > 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 sma1 0.4415 0.0372 s.e. 0.1339 0.1615 sigma^2 estimated as 1.901e-14: log likelihood = 675.65, aic = -1345.3 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 49 End = 72 Frequency = 1 [1] 3.971861e-06 3.992354e-06 3.994857e-06 3.997020e-06 4.003761e-06 [6] 4.006843e-06 4.010025e-06 4.011873e-06 4.019764e-06 4.018604e-06 [11] 4.022745e-06 4.024950e-06 4.025924e-06 4.026353e-06 4.026543e-06 [16] 4.026627e-06 4.026664e-06 4.026680e-06 4.026687e-06 4.026691e-06 [21] 4.026692e-06 4.026693e-06 4.026693e-06 4.026693e-06 $se Time Series: Start = 49 End = 72 Frequency = 1 [1] 1.378682e-07 2.418708e-07 3.307510e-07 4.071649e-07 4.740089e-07 [6] 5.335850e-07 5.875734e-07 6.371765e-07 6.832594e-07 7.264546e-07 [11] 7.672341e-07 8.059582e-07 8.444248e-07 8.818655e-07 9.180581e-07 [16] 9.529957e-07 9.867475e-07 1.019404e-06 1.051056e-06 1.081786e-06 [21] 1.111668e-06 1.140769e-06 1.169146e-06 1.196850e-06 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 49 End = 72 Frequency = 1 [1] 3.701639e-06 3.518288e-06 3.346585e-06 3.198977e-06 3.074704e-06 [6] 2.961016e-06 2.858381e-06 2.763007e-06 2.680576e-06 2.594753e-06 [11] 2.518966e-06 2.445272e-06 2.370851e-06 2.297897e-06 2.227149e-06 [16] 2.158755e-06 2.092639e-06 2.028648e-06 1.966618e-06 1.906391e-06 [21] 1.847823e-06 1.790786e-06 1.735167e-06 1.680867e-06 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 49 End = 72 Frequency = 1 [1] 4.242082e-06 4.466421e-06 4.643129e-06 4.795063e-06 4.932819e-06 [6] 5.052669e-06 5.161669e-06 5.260739e-06 5.358953e-06 5.442455e-06 [11] 5.526524e-06 5.604628e-06 5.680996e-06 5.754810e-06 5.825937e-06 [16] 5.894498e-06 5.960689e-06 6.024712e-06 6.086756e-06 6.146990e-06 [21] 6.205561e-06 6.262599e-06 6.318218e-06 6.372519e-06 > 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] 2072.650 2020.130 2032.760 2050.310 2128.980 2122.140 2122.890 2091.950 [9] 2002.970 1923.210 1834.440 1819.150 1792.000 1822.400 1900.700 1903.000 [17] 1958.800 1820.500 1719.800 1661.100 1664.400 1703.400 1774.900 1795.000 [25] 1816.300 1867.400 1900.000 1961.100 2065.700 2073.500 2080.800 2118.000 [33] 2099.000 2085.200 1937.700 1749.500 1750.300 1675.600 1697.500 1699.800 [41] 1655.900 1636.000 1614.200 1602.300 1548.700 1556.100 1526.900 1509.200 [49] 1503.358 1498.813 1498.261 1497.784 1496.300 1495.623 1494.925 1494.520 [57] 1492.793 1493.047 1492.143 1491.662 1491.449 1491.356 1491.314 1491.296 [65] 1491.288 1491.285 1491.283 1491.282 1491.282 1491.282 1491.282 1491.282 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 49 End = 72 Frequency = 1 [1] 0.02159048 0.03938326 0.05600763 0.07141832 0.08572402 0.09935445 [7] 0.11242640 0.12515257 0.13732184 0.14972367 0.16173867 0.17379834 [13] 0.18644692 0.19941792 0.21261245 0.22600564 0.23960459 0.25343004 [19] 0.26750850 0.28186906 0.29654215 0.31155926 0.32695299 0.34275727 > postscript(file="/var/www/html/rcomp/tmp/16mvf1262201715.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/2syk71262201715.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/3pwyk1262201715.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/4sodm1262201715.tab") > > try(system("convert tmp/16mvf1262201715.ps tmp/16mvf1262201715.png",intern=TRUE)) character(0) > try(system("convert tmp/2syk71262201715.ps tmp/2syk71262201715.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.658 0.301 0.828