R version 2.13.0 (2011-04-13) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i486-pc-linux-gnu (32-bit) 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(24.90 + ,25.06 + ,25.10 + ,24.92 + ,25.46 + ,25.89 + ,25.39 + ,25.38 + ,25.25 + ,24.88 + ,25.00 + ,25.00 + ,24.07 + ,23.60 + ,23.18 + ,23.25 + ,23.04 + ,22.77 + ,22.25 + ,22.41 + ,22.50 + ,22.91 + ,22.88 + ,21.69 + ,21.19 + ,21.56 + ,22.00 + ,22.13 + ,22.27 + ,22.30 + ,21.94 + ,22.40 + ,22.77 + ,22.90 + ,23.03 + ,23.05 + ,22.41 + ,22.26 + ,21.90 + ,22.01 + ,22.62 + ,22.76 + ,23.40 + ,23.63 + ,24.05 + ,23.82 + ,23.71 + ,23.95 + ,23.61 + ,23.98 + ,23.56 + ,23.99 + ,24.33 + ,24.48 + ,24.31 + ,24.38 + ,24.63 + ,25.54 + ,25.75 + ,25.73 + ,25.85 + ,25.78 + ,25.86 + ,26.86 + ,27.36 + ,27.38 + ,26.58 + ,27.65 + ,27.73 + ,27.18 + ,27.32 + ,27.30 + ,26.90 + ,26.70 + ,26.75 + ,26.41 + ,26.29 + ,27.51 + ,27.91 + ,27.70 + ,27.28 + ,28.25 + ,27.62 + ,27.30 + ,25.94 + ,24.99 + ,25.50 + ,24.42 + ,26.58 + ,25.84 + ,26.76 + ,26.74 + ,26.68 + ,25.55 + ,26.40 + ,25.19 + ,23.94 + ,24.20 + ,24.20 + ,23.07 + ,24.07 + ,25.02 + ,24.65 + ,24.68 + ,24.63 + ,24.49 + ,25.05 + ,24.31 + ,23.90 + ,23.68 + ,24.50 + ,25.22 + ,25.48 + ,26.00 + ,26.07 + ,26.06 + ,26.22 + ,26.70 + ,27.20 + ,26.77 + ,26.11 + ,25.43 + ,24.99 + ,25.51 + ,24.00 + ,23.86 + ,22.96 + ,23.41 + ,23.17 + ,24.12 + ,23.87 + ,24.27 + ,24.40 + ,24.16 + ,25.15 + ,25.09 + ,24.60 + ,24.33 + ,24.14 + ,24.36 + ,25.40 + ,26.15 + ,26.77 + ,26.94 + ,26.33 + ,26.24 + ,26.23 + ,25.88 + ,27.00 + ,26.91 + ,27.15 + ,27.78 + ,28.73 + ,28.83 + ,28.68 + ,27.56 + ,27.15 + ,27.41 + ,27.47 + ,28.76 + ,28.47 + ,27.94 + ,27.23 + ,27.01 + ,26.15 + ,26.11 + ,27.20 + ,27.36 + ,27.33 + ,27.43 + ,28.92 + ,29.45 + ,29.01 + ,29.25 + ,29.14 + ,29.64 + ,30.40 + ,30.62 + ,31.25 + ,31.75 + ,31.30 + ,30.70 + ,31.03 + ,31.46 + ,31.28 + ,31.03 + ,30.95 + ,31.17 + ,31.29 + ,31.91 + ,32.10 + ,31.71 + ,31.90 + ,32.02 + ,32.65 + ,33.77 + ,33.51 + ,34.26 + ,34.21 + ,34.13 + ,34.73 + ,34.73 + ,34.57 + ,34.80 + ,33.98 + ,34.40 + ,34.21 + ,34.61 + ,35.25 + ,35.23 + ,35.00 + ,34.52 + ,33.82 + ,34.35 + ,34.81 + ,34.96 + ,36.69 + ,36.42 + ,36.44 + ,37.41 + ,36.40 + ,36.15 + ,35.78 + ,36.95 + ,36.14 + ,36.36 + ,37.31 + ,37.58 + ,38.00 + ,37.23 + ,37.00 + ,37.87 + ,37.70 + ,36.17 + ,36.56 + ,37.70 + ,38.77 + ,39.02 + ,39.88 + ,39.56 + ,38.52 + ,37.20 + ,38.58 + ,39.41 + ,39.08 + ,38.81 + ,38.73 + ,38.70 + ,39.23 + ,39.82 + ,39.97 + ,40.37 + ,39.54 + ,39.21 + ,39.07 + ,39.78 + ,39.40 + ,38.92) > par10 = 'FALSE' > par9 = '0' > par8 = '1' > par7 = '0' > par6 = '2' > par5 = '12' > par4 = '0' > par3 = '1' > par2 = '0.0' > par1 = '12' > 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 sar1 -0.0150 0.0217 0.1194 s.e. 0.0646 0.0638 0.0654 sigma^2 estimated as 0.0004615: log likelihood = 593.2, aic = -1178.41 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 247 End = 258 Frequency = 1 [1] 3.659817 3.663441 3.666780 3.667546 3.670148 3.669187 3.666006 3.661844 [9] 3.666192 3.668733 3.667729 3.666902 $se Time Series: Start = 247 End = 258 Frequency = 1 [1] 0.02148209 0.03015381 0.03711068 0.04294818 0.04808681 0.05272681 [7] 0.05699037 0.06095644 0.06467977 0.06820013 0.07154748 0.07474509 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 247 End = 258 Frequency = 1 [1] 3.617712 3.604340 3.594043 3.583368 3.575898 3.565842 3.554305 3.542369 [9] 3.539420 3.535061 3.527496 3.520401 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 247 End = 258 Frequency = 1 [1] 3.701922 3.722543 3.739517 3.751725 3.764399 3.772531 3.777708 3.781319 [9] 3.792965 3.802405 3.807963 3.813402 > 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] 24.90000 25.06000 25.10000 24.92000 25.46000 25.89000 25.39000 25.38000 [9] 25.25000 24.88000 25.00000 25.00000 24.07000 23.60000 23.18000 23.25000 [17] 23.04000 22.77000 22.25000 22.41000 22.50000 22.91000 22.88000 21.69000 [25] 21.19000 21.56000 22.00000 22.13000 22.27000 22.30000 21.94000 22.40000 [33] 22.77000 22.90000 23.03000 23.05000 22.41000 22.26000 21.90000 22.01000 [41] 22.62000 22.76000 23.40000 23.63000 24.05000 23.82000 23.71000 23.95000 [49] 23.61000 23.98000 23.56000 23.99000 24.33000 24.48000 24.31000 24.38000 [57] 24.63000 25.54000 25.75000 25.73000 25.85000 25.78000 25.86000 26.86000 [65] 27.36000 27.38000 26.58000 27.65000 27.73000 27.18000 27.32000 27.30000 [73] 26.90000 26.70000 26.75000 26.41000 26.29000 27.51000 27.91000 27.70000 [81] 27.28000 28.25000 27.62000 27.30000 25.94000 24.99000 25.50000 24.42000 [89] 26.58000 25.84000 26.76000 26.74000 26.68000 25.55000 26.40000 25.19000 [97] 23.94000 24.20000 24.20000 23.07000 24.07000 25.02000 24.65000 24.68000 [105] 24.63000 24.49000 25.05000 24.31000 23.90000 23.68000 24.50000 25.22000 [113] 25.48000 26.00000 26.07000 26.06000 26.22000 26.70000 27.20000 26.77000 [121] 26.11000 25.43000 24.99000 25.51000 24.00000 23.86000 22.96000 23.41000 [129] 23.17000 24.12000 23.87000 24.27000 24.40000 24.16000 25.15000 25.09000 [137] 24.60000 24.33000 24.14000 24.36000 25.40000 26.15000 26.77000 26.94000 [145] 26.33000 26.24000 26.23000 25.88000 27.00000 26.91000 27.15000 27.78000 [153] 28.73000 28.83000 28.68000 27.56000 27.15000 27.41000 27.47000 28.76000 [161] 28.47000 27.94000 27.23000 27.01000 26.15000 26.11000 27.20000 27.36000 [169] 27.33000 27.43000 28.92000 29.45000 29.01000 29.25000 29.14000 29.64000 [177] 30.40000 30.62000 31.25000 31.75000 31.30000 30.70000 31.03000 31.46000 [185] 31.28000 31.03000 30.95000 31.17000 31.29000 31.91000 32.10000 31.71000 [193] 31.90000 32.02000 32.65000 33.77000 33.51000 34.26000 34.21000 34.13000 [201] 34.73000 34.73000 34.57000 34.80000 33.98000 34.40000 34.21000 34.61000 [209] 35.25000 35.23000 35.00000 34.52000 33.82000 34.35000 34.81000 34.96000 [217] 36.69000 36.42000 36.44000 37.41000 36.40000 36.15000 35.78000 36.95000 [225] 36.14000 36.36000 37.31000 37.58000 38.00000 37.23000 37.00000 37.87000 [233] 37.70000 36.17000 36.56000 37.70000 38.77000 39.02000 39.88000 39.56000 [241] 38.52000 37.20000 38.58000 39.41000 39.08000 38.81000 38.85423 38.99530 [249] 39.12570 39.15570 39.25773 39.22000 39.09547 38.93307 39.10273 39.20221 [257] 39.16288 39.13049 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 247 End = 258 Frequency = 1 [1] 0.02194075 0.03106269 0.03849367 0.04480764 0.05042581 0.05554766 [7] 0.06029521 0.06474726 0.06895845 0.07296844 0.07680710 0.08049763 > postscript(file="/var/wessaorg/rcomp/tmp/1df8k1324649394.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/wessaorg/rcomp/tmp/2zseh1324649394.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/wessaorg/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/wessaorg/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/wessaorg/rcomp/tmp/33n591324649395.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/wessaorg/rcomp/tmp/4oe6i1324649395.tab") > > try(system("convert tmp/1df8k1324649394.ps tmp/1df8k1324649394.png",intern=TRUE)) character(0) > try(system("convert tmp/2zseh1324649394.ps tmp/2zseh1324649394.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 0.774 0.142 0.912