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(25.22,27.63,27.47,22.54,27.4,29.68,28.51,29.89,32.62,30.93,32.52,25.28,25.64,27.41,24.4,25.55,28.45,27.72,24.54,25.67,25.54,20.48,18.94,18.6,19.49,20.29,23.69,25.65,25.43,24.13,25.77,26.63,28.34,27.55,24.5,28.52,31.29,32.65,30.34,25.02,25.81,27.55,28.4,29.83,27.1,29.59,28.77,29.88,31.18,30.87,33.8,33.36,37.92,35.19,38.37,43.03,43.38,49.77,43.05,39.65,44.28,45.56,53.08,51.86,48.67,54.31,57.58,64.09,62.98,58.52,55.54,56.75,63.57,59.92,62.25,70.44,70.19,68.86,73.9,73.61,62.77,58.38,58.48,62.31,54.3,57.76,62.14,67.4,67.48,71.32,77.2,70.8,77.13,83.04,92.53,91.45,91.92,94.82,103.28,110.44,123.94,133.05,133.9,113.85,99.06,72.84,53.24,41.58,44.86,43.24,46.84,50.85,57.94,68.59,64.92,72.5,67.69,73.19,77.04,74.67) > par10 = 'FALSE' > par9 = '1' > par8 = '1' > par7 = '1' > par6 = '1' > par5 = '12' > par4 = '0' > par3 = '1' > par2 = '-0.5' > 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.6056 -0.6950 -0.8285 1.0000 s.e. 0.4365 0.3917 0.1087 0.1891 sigma^2 estimated as 5.496e-05: log likelihood = 327.78, aic = -645.56 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 97 End = 120 Frequency = 1 [1] 0.1061216 0.1054087 0.1073981 0.1085432 0.1101028 0.1079832 0.1089746 [8] 0.1095075 0.1096597 0.1103966 0.1093020 0.1087742 0.1080969 0.1090559 [15] 0.1076306 0.1068169 0.1056066 0.1074122 0.1066208 0.1061975 0.1060824 [22] 0.1054785 0.1063894 0.1068292 $se Time Series: Start = 97 End = 120 Frequency = 1 [1] 0.007620435 0.010299936 0.012188833 0.013706087 0.015009143 0.016173441 [7] 0.017240074 0.018233448 0.019169063 0.020057328 0.020905567 0.021719115 [13] 0.022754146 0.023724727 0.024643393 0.025521036 0.026364821 0.027179694 [19] 0.027969235 0.028736151 0.029482575 0.030210248 0.030920624 0.031614952 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 97 End = 120 Frequency = 1 [1] 0.09118559 0.08522081 0.08350799 0.08167926 0.08068488 0.07628329 [7] 0.07518408 0.07376996 0.07208832 0.07108428 0.06832712 0.06620470 [13] 0.06349879 0.06255542 0.05932958 0.05679572 0.05393152 0.05414000 [19] 0.05180111 0.04987460 0.04829654 0.04626638 0.04578498 0.04486389 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 97 End = 120 Frequency = 1 [1] 0.1210577 0.1255966 0.1312882 0.1354071 0.1395207 0.1396832 0.1427652 [8] 0.1452451 0.1472311 0.1497090 0.1502769 0.1513436 0.1526950 0.1555563 [15] 0.1559317 0.1568382 0.1572816 0.1606844 0.1614405 0.1625203 0.1638682 [22] 0.1646905 0.1669938 0.1687945 > 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] 25.22000 27.63000 27.47000 22.54000 27.40000 29.68000 28.51000 29.89000 [9] 32.62000 30.93000 32.52000 25.28000 25.64000 27.41000 24.40000 25.55000 [17] 28.45000 27.72000 24.54000 25.67000 25.54000 20.48000 18.94000 18.60000 [25] 19.49000 20.29000 23.69000 25.65000 25.43000 24.13000 25.77000 26.63000 [33] 28.34000 27.55000 24.50000 28.52000 31.29000 32.65000 30.34000 25.02000 [41] 25.81000 27.55000 28.40000 29.83000 27.10000 29.59000 28.77000 29.88000 [49] 31.18000 30.87000 33.80000 33.36000 37.92000 35.19000 38.37000 43.03000 [57] 43.38000 49.77000 43.05000 39.65000 44.28000 45.56000 53.08000 51.86000 [65] 48.67000 54.31000 57.58000 64.09000 62.98000 58.52000 55.54000 56.75000 [73] 63.57000 59.92000 62.25000 70.44000 70.19000 68.86000 73.90000 73.61000 [81] 62.77000 58.38000 58.48000 62.31000 54.30000 57.76000 62.14000 67.40000 [89] 67.48000 71.32000 77.20000 70.80000 77.13000 83.04000 92.53000 91.45000 [97] 88.79572 90.00097 86.69755 84.87793 82.49037 85.76050 84.20720 83.38964 [105] 83.15837 82.05183 83.70348 84.51785 85.58022 84.08176 86.32334 87.64349 [113] 89.66401 86.67479 87.96625 88.66899 88.86146 89.88194 88.34933 87.62340 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 97 End = 120 Frequency = 1 [1] 0.1808299 0.2703543 0.3336767 0.3907974 0.4398675 0.5121416 0.5616679 [8] 0.6140712 0.6704103 0.7203722 0.7954080 0.8670618 0.9683583 1.0404405 [15] 1.1688828 1.2944463 1.4461186 1.4980315 1.6512687 1.8029965 1.9512883 [22] 2.1415944 2.2446247 2.3826732 > postscript(file="/var/www/html/rcomp/tmp/1t6q71293310165.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/2pxog1293310165.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/3wh391293310165.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/4hz1x1293310165.tab") > > try(system("convert tmp/1t6q71293310165.ps tmp/1t6q71293310165.png",intern=TRUE)) character(0) > try(system("convert tmp/2pxog1293310165.ps tmp/2pxog1293310165.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.890 0.337 1.847