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(115.65 + ,116.00 + ,115.92 + ,116.10 + ,116.44 + ,116.65 + ,117.45 + ,117.58 + ,117.43 + ,117.24 + ,117.25 + ,117.29 + ,117.83 + ,118.22 + ,118.11 + ,118.23 + ,118.15 + ,118.23 + ,119.03 + ,119.38 + ,118.97 + ,118.78 + ,118.97 + ,118.94 + ,119.86 + ,120.09 + ,120.13 + ,120.15 + ,119.90 + ,120.00 + ,120.84 + ,121.17 + ,120.81 + ,121.00 + ,121.12 + ,121.29 + ,122.09 + ,121.88 + ,121.31 + ,121.33 + ,121.45 + ,121.67 + ,122.78 + ,122.84 + ,122.34 + ,122.37 + ,122.72 + ,122.68 + ,122.78 + ,123.08 + ,122.92 + ,123.51 + ,124.18 + ,124.05 + ,124.36 + ,123.87 + ,123.84 + ,123.85 + ,123.83 + ,123.84 + ,124.27 + ,124.56 + ,124.57 + ,124.87 + ,125.08 + ,124.86 + ,124.89 + ,124.58 + ,124.83 + ,124.97 + ,125.19 + ,125.42 + ,125.74 + ,126.07 + ,126.35 + ,126.69 + ,126.85 + ,127.12 + ,127.43 + ,127.49 + ,128.05 + ,127.85 + ,128.35 + ,128.29 + ,128.38 + ,128.80 + ,129.18 + ,130.14 + ,130.77 + ,131.19 + ,131.32 + ,131.41 + ,131.61 + ,131.69 + ,131.94 + ,131.70 + ,132.54 + ,132.74 + ,133.02 + ,132.76 + ,133.05 + ,132.74 + ,133.16 + ,133.10 + ,133.37 + ,133.15 + ,133.18 + ,133.29 + ,133.76 + ,134.51 + ,134.82 + ,134.71 + ,134.52 + ,134.86 + ,135.11 + ,135.28 + ,135.61 + ,135.22 + ,135.47 + ,135.42 + ,135.85 + ,136.27 + ,136.30 + ,136.85 + ,137.05 + ,137.03 + ,137.45 + ,137.49 + ,137.55 + ,138.04 + ,138.03 + ,137.75 + ,138.27 + ,138.99 + ,139.74 + ,139.70 + ,139.97 + ,140.21 + ,140.78 + ,140.80 + ,140.64 + ,140.42 + ,140.85 + ,140.96 + ,141.04 + ,141.71 + ,141.60 + ,142.11 + ,142.59 + ,142.56 + ,143.00 + ,143.18 + ,143.15 + ,143.10 + ,143.45 + ,143.59 + ,143.92 + ,144.66 + ,144.34 + ,144.82 + ,144.49 + ,144.41 + ,144.99 + ,144.95 + ,145.00 + ,145.66 + ,146.68 + ,147.38 + ,147.94 + ,149.12 + ,149.95 + ,150.19 + ,151.16 + ,151.74 + ,152.56 + ,152.09 + ,152.46 + ,152.66 + ,152.38 + ,152.59 + ,152.88 + ,153.29 + ,152.35 + ,152.49 + ,152.20 + ,151.57 + ,151.55 + ,151.79 + ,151.52 + ,151.76 + ,151.92 + ,152.20 + ,152.75 + ,153.49 + ,153.78 + ,154.10 + ,154.62 + ,154.65 + ,154.81 + ,154.92 + ,155.40 + ,155.63 + ,155.76) > par10 = 'FALSE' > par9 = '1' > par8 = '1' > par7 = '1' > par6 = '1' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '0.0' > par1 = '12' > #'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 ma1 sar1 sma1 0.3015 -0.1485 -0.0150 -0.8081 s.e. 0.5321 0.5524 0.1294 0.1237 sigma^2 estimated as 5.773e-06: log likelihood = 814.48, aic = -1618.95 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 192 End = 203 Frequency = 1 [1] 5.024267 5.027128 5.031431 5.031588 5.033484 5.034899 5.035046 5.038162 [9] 5.038136 5.038430 5.039330 5.041066 $se Time Series: Start = 192 End = 203 Frequency = 1 [1] 0.002403334 0.003668127 0.004664714 0.005500706 0.006230157 0.006884020 [7] 0.007481308 0.008034415 0.008551852 0.009039727 0.009502589 0.009943928 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 192 End = 203 Frequency = 1 [1] 5.019556 5.019938 5.022288 5.020807 5.021273 5.021406 5.020383 5.022414 [9] 5.021375 5.020713 5.020705 5.021576 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 192 End = 203 Frequency = 1 [1] 5.028977 5.034318 5.040574 5.042369 5.045695 5.048391 5.049709 5.053909 [9] 5.054898 5.056148 5.057955 5.060556 > 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] 115.6500 116.0000 115.9200 116.1000 116.4400 116.6500 117.4500 117.5800 [9] 117.4300 117.2400 117.2500 117.2900 117.8300 118.2200 118.1100 118.2300 [17] 118.1500 118.2300 119.0300 119.3800 118.9700 118.7800 118.9700 118.9400 [25] 119.8600 120.0900 120.1300 120.1500 119.9000 120.0000 120.8400 121.1700 [33] 120.8100 121.0000 121.1200 121.2900 122.0900 121.8800 121.3100 121.3300 [41] 121.4500 121.6700 122.7800 122.8400 122.3400 122.3700 122.7200 122.6800 [49] 122.7800 123.0800 122.9200 123.5100 124.1800 124.0500 124.3600 123.8700 [57] 123.8400 123.8500 123.8300 123.8400 124.2700 124.5600 124.5700 124.8700 [65] 125.0800 124.8600 124.8900 124.5800 124.8300 124.9700 125.1900 125.4200 [73] 125.7400 126.0700 126.3500 126.6900 126.8500 127.1200 127.4300 127.4900 [81] 128.0500 127.8500 128.3500 128.2900 128.3800 128.8000 129.1800 130.1400 [89] 130.7700 131.1900 131.3200 131.4100 131.6100 131.6900 131.9400 131.7000 [97] 132.5400 132.7400 133.0200 132.7600 133.0500 132.7400 133.1600 133.1000 [105] 133.3700 133.1500 133.1800 133.2900 133.7600 134.5100 134.8200 134.7100 [113] 134.5200 134.8600 135.1100 135.2800 135.6100 135.2200 135.4700 135.4200 [121] 135.8500 136.2700 136.3000 136.8500 137.0500 137.0300 137.4500 137.4900 [129] 137.5500 138.0400 138.0300 137.7500 138.2700 138.9900 139.7400 139.7000 [137] 139.9700 140.2100 140.7800 140.8000 140.6400 140.4200 140.8500 140.9600 [145] 141.0400 141.7100 141.6000 142.1100 142.5900 142.5600 143.0000 143.1800 [153] 143.1500 143.1000 143.4500 143.5900 143.9200 144.6600 144.3400 144.8200 [161] 144.4900 144.4100 144.9900 144.9500 145.0000 145.6600 146.6800 147.3800 [169] 147.9400 149.1200 149.9500 150.1900 151.1600 151.7400 152.5600 152.0900 [177] 152.4600 152.6600 152.3800 152.5900 152.8800 153.2900 152.3500 152.4900 [185] 152.2000 151.5700 151.5500 151.7900 151.5200 151.7600 151.9200 152.0587 [193] 152.4944 153.1521 153.1761 153.4667 153.6840 153.7067 154.1863 154.1824 [201] 154.2278 154.3666 154.6348 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 192 End = 203 Frequency = 1 [1] 0.002409003 0.003681345 0.004686104 0.005530466 0.006268350 0.006930671 [7] 0.007536428 0.008098009 0.008623926 0.009120285 0.009591634 0.010041465 > postscript(file="/var/www/html/rcomp/tmp/12cxk1291468788.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/html/rcomp/tmp/2y4vb1291468788.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/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/3yea81291468788.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/41fqw1291468788.tab") > > try(system("convert tmp/12cxk1291468788.ps tmp/12cxk1291468788.png",intern=TRUE)) character(0) > try(system("convert tmp/2y4vb1291468788.ps tmp/2y4vb1291468788.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.429 0.315 2.925