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(90.2 + ,90 + ,88.8 + ,85.8 + ,84.2 + ,80 + ,77.8 + ,76.8 + ,86.4 + ,89.2 + ,86.2 + ,84.6 + ,83.2 + ,83.2 + ,82.6 + ,79.8 + ,77.2 + ,74.8 + ,73 + ,73 + ,83.6 + ,85.6 + ,84.8 + ,84.2 + ,83.4 + ,84.6 + ,84.6 + ,83.8 + ,81.2 + ,79.6 + ,78 + ,78.2 + ,88.8 + ,92 + ,91 + ,91.2 + ,90.4 + ,91.8 + ,92.2 + ,90.2 + ,88.6 + ,87.8 + ,86 + ,87.2 + ,97.6 + ,101.2 + ,100.4 + ,100.2 + ,100.2 + ,103 + ,104.2 + ,104 + ,102.4 + ,101.8 + ,101 + ,102.2 + ,114 + ,118.4 + ,118.8 + ,117.2 + ,117.2 + ,118.4 + ,118.8 + ,117.2 + ,114.4 + ,112.6 + ,111 + ,110.8 + ,120.2 + ,124.4 + ,123.4 + ,121.2 + ,119 + ,119.8 + ,120 + ,118.4 + ,115 + ,113.4 + ,111 + ,111 + ,121.6 + ,126.2 + ,125.8 + ,124.8 + ,122 + ,123.2 + ,124.2 + ,120.8 + ,116.8 + ,114.8 + ,111 + ,109 + ,119.8 + ,124 + ,121.6 + ,118 + ,115.8 + ,116 + ,115.8 + ,114.4 + ,112 + ,110.2 + ,107.4 + ,108.2 + ,117.6 + ,121.4 + ,119.8 + ,115.6 + ,112.6 + ,113.2 + ,112.2 + ,110.8 + ,108 + ,105.2 + ,102.4 + ,101 + ,110.8 + ,116.8 + ,113.8 + ,108 + ,104.4 + ,105.2 + ,105.4 + ,103.2 + ,100.6 + ,97.8 + ,95.8 + ,95 + ,104.8 + ,110.4 + ,106.4 + ,102.2 + ,98.4 + ,98.4 + ,98.6 + ,96.2 + ,92.4 + ,91.4 + ,88.4 + ,87.8 + ,97.6 + ,104.2 + ,100.2 + ,97 + ,92.8 + ,92 + ,93.4 + ,92 + ,89.6 + ,88.6 + ,87.2 + ,86.2 + ,96.8 + ,102 + ,102.6 + ,100.6 + ,94.2 + ,94.2 + ,95.2 + ,95 + ,94 + ,92.2 + ,91 + ,91.2 + ,103.4 + ,105 + ,104.6 + ,103.8 + ,101.8 + ,102.4 + ,103.8 + ,103.4 + ,102 + ,101.8 + ,100.2 + ,101.4 + ,113.8 + ,116 + ,115.6 + ,113 + ,109.4 + ,111 + ,112.4 + ,112.2 + ,111 + ,108.8 + ,107.4 + ,108.6 + ,118.8 + ,122.2 + ,122.6 + ,122.2 + ,118.8 + ,119 + ,118.2 + ,117.8 + ,116.8 + ,114.6 + ,113.4 + ,113.8 + ,124.2 + ,125.8 + ,125.6 + ,122.4 + ,119 + ,119.4 + ,118.6 + ,118 + ,116 + ,114.8 + ,114.6 + ,114.6 + ,124 + ,125.2 + ,124 + ,117.6 + ,113.2 + ,111.4 + ,112.2 + ,109.8 + ,106.4 + ,105.2 + ,102.2 + ,99.8 + ,111 + ,113 + ,108.4 + ,105.4 + ,102 + ,102.8 + ,103.4 + ,101.6 + ,98.6 + ,98 + ,93.8 + ,95.6 + ,105.6 + ,106.8 + ,103.6 + ,101.2 + ,100.4 + ,103.2 + ,105.6 + ,106.6 + ,107.2 + ,107.4 + ,104.8 + ,107.2 + ,117.4 + ,119.4 + ,116.2 + ,112.8 + ,111.6) > par10 = 'FALSE' > par9 = '1' > par8 = '1' > par7 = '1' > par6 = '1' > par5 = '6' > par4 = '1' > 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 ma1 sar1 sma1 0.8683 -0.7995 -0.9774 0.1497 s.e. 0.1390 0.1642 0.0120 0.1404 sigma^2 estimated as 1.504: log likelihood = -368.69, aic = 747.38 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 230 End = 253 Frequency = 1 [1] 99.96206 101.33319 99.26586 95.41941 94.70196 91.93441 89.58953 [8] 100.60808 102.55152 97.99929 95.07757 91.71504 89.69028 91.29699 [15] 89.33551 85.48628 84.73042 81.95935 79.63034 90.44359 92.30525 [22] 87.77456 84.90671 81.56181 $se Time Series: Start = 230 End = 253 Frequency = 1 [1] 1.226459 1.795187 2.266899 2.689852 3.081388 3.449817 3.893128 [8] 4.312465 4.712079 5.094783 5.462579 5.816980 6.652578 7.440613 [15] 8.190386 8.907774 9.596820 10.260495 10.982261 11.680038 12.355573 [22] 13.010360 13.645714 14.262815 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 230 End = 253 Frequency = 1 [1] 97.55820 97.81463 94.82274 90.14730 88.66244 85.17277 81.95900 92.15565 [9] 93.31585 88.01351 84.37092 80.31376 76.65123 76.71339 73.28235 68.02704 [17] 65.92066 61.84878 58.10511 67.55072 68.08833 62.27425 58.16111 53.60669 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 230 End = 253 Frequency = 1 [1] 102.36592 104.85176 103.70899 100.69153 100.74148 98.69605 97.22007 [8] 109.06051 111.78720 107.98506 105.78423 103.11632 102.72933 105.88060 [15] 105.38867 102.94551 103.54019 102.06992 101.15557 113.33647 116.52217 [22] 113.27486 111.65231 109.51693 > 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] 90.20000 90.00000 88.80000 85.80000 84.20000 80.00000 77.80000 [8] 76.80000 86.40000 89.20000 86.20000 84.60000 83.20000 83.20000 [15] 82.60000 79.80000 77.20000 74.80000 73.00000 73.00000 83.60000 [22] 85.60000 84.80000 84.20000 83.40000 84.60000 84.60000 83.80000 [29] 81.20000 79.60000 78.00000 78.20000 88.80000 92.00000 91.00000 [36] 91.20000 90.40000 91.80000 92.20000 90.20000 88.60000 87.80000 [43] 86.00000 87.20000 97.60000 101.20000 100.40000 100.20000 100.20000 [50] 103.00000 104.20000 104.00000 102.40000 101.80000 101.00000 102.20000 [57] 114.00000 118.40000 118.80000 117.20000 117.20000 118.40000 118.80000 [64] 117.20000 114.40000 112.60000 111.00000 110.80000 120.20000 124.40000 [71] 123.40000 121.20000 119.00000 119.80000 120.00000 118.40000 115.00000 [78] 113.40000 111.00000 111.00000 121.60000 126.20000 125.80000 124.80000 [85] 122.00000 123.20000 124.20000 120.80000 116.80000 114.80000 111.00000 [92] 109.00000 119.80000 124.00000 121.60000 118.00000 115.80000 116.00000 [99] 115.80000 114.40000 112.00000 110.20000 107.40000 108.20000 117.60000 [106] 121.40000 119.80000 115.60000 112.60000 113.20000 112.20000 110.80000 [113] 108.00000 105.20000 102.40000 101.00000 110.80000 116.80000 113.80000 [120] 108.00000 104.40000 105.20000 105.40000 103.20000 100.60000 97.80000 [127] 95.80000 95.00000 104.80000 110.40000 106.40000 102.20000 98.40000 [134] 98.40000 98.60000 96.20000 92.40000 91.40000 88.40000 87.80000 [141] 97.60000 104.20000 100.20000 97.00000 92.80000 92.00000 93.40000 [148] 92.00000 89.60000 88.60000 87.20000 86.20000 96.80000 102.00000 [155] 102.60000 100.60000 94.20000 94.20000 95.20000 95.00000 94.00000 [162] 92.20000 91.00000 91.20000 103.40000 105.00000 104.60000 103.80000 [169] 101.80000 102.40000 103.80000 103.40000 102.00000 101.80000 100.20000 [176] 101.40000 113.80000 116.00000 115.60000 113.00000 109.40000 111.00000 [183] 112.40000 112.20000 111.00000 108.80000 107.40000 108.60000 118.80000 [190] 122.20000 122.60000 122.20000 118.80000 119.00000 118.20000 117.80000 [197] 116.80000 114.60000 113.40000 113.80000 124.20000 125.80000 125.60000 [204] 122.40000 119.00000 119.40000 118.60000 118.00000 116.00000 114.80000 [211] 114.60000 114.60000 124.00000 125.20000 124.00000 117.60000 113.20000 [218] 111.40000 112.20000 109.80000 106.40000 105.20000 102.20000 99.80000 [225] 111.00000 113.00000 108.40000 105.40000 102.00000 99.96206 101.33319 [232] 99.26586 95.41941 94.70196 91.93441 89.58953 100.60808 102.55152 [239] 97.99929 95.07757 91.71504 89.69028 91.29699 89.33551 85.48628 [246] 84.73042 81.95935 79.63034 90.44359 92.30525 87.77456 84.90671 [253] 81.56181 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 230 End = 253 Frequency = 1 [1] 0.01226925 0.01771568 0.02283664 0.02818978 0.03253774 0.03752477 [7] 0.04345517 0.04286400 0.04594841 0.05198796 0.05745392 0.06342449 [13] 0.07417279 0.08149900 0.09168119 0.10420122 0.11326297 0.12519004 [19] 0.13791553 0.12914169 0.13385558 0.14822473 0.16071420 0.17487125 > postscript(file="/var/www/html/rcomp/tmp/1yrxu1263295849.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/2ekry1263295849.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/3jike1263295849.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/4qjob1263295849.tab") > > try(system("convert tmp/1yrxu1263295849.ps tmp/1yrxu1263295849.png",intern=TRUE)) character(0) > try(system("convert tmp/2ekry1263295849.ps tmp/2ekry1263295849.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.388 0.330 1.532