R version 2.8.0 (2008-10-20) Copyright (C) 2008 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(15.59,13.17,11.20,13.30,10.78,11.60,15.18,15.87,12.58,11.43,10.30,11.17,11.26,11.20,9.99,11.17,10.29,10.47,14.36,16.06,14.47,13.24,13.03,14.43,13.98,13.62,12.20,12.24,12.07,12.30,16.12,18.38,14.59,12.96,14.14,13.92,14.24,14.10,12.91,13.69,14.11,13.99,17.93,21.37,16.25,14.53,15.36,14.95,15.95,15.25,12.67,13.86,14.65,12.41,17.46,18.95,15.33,15.31,14.84,14.75,15.83,14.83,13.00,13.92,13.94,12.54,18.12,17.83,14.41,15.18,12.99,13.06,12.81,12.95,10.48,13.23,11.80,11.69,15.33,14.89,12.92,11.27,10.68,11.55) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '0' > par6 = '3' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '1' > par1 = '20' > #'GNU S' R Code compiled by R2WASP v. 1.0.44 () > #Author: Prof. Dr. P. Wessa > #To cite this work: AUTHOR(S), (YEAR), YOUR SOFTWARE TITLE (vNUMBER) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_YOURPAGE.wasp/ > #Source of accompanying publication: Office for Research, Development, and Education > #Technical description: Write here your technical program description (don't use hard returns!) > 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 ar3 -0.2983 -0.0235 0.3516 s.e. 0.1388 0.1467 0.1376 sigma^2 estimated as 0.8206: log likelihood = -67.59, aic = 143.18 > (forecast <- predict(arima.out,fx)) $pred Time Series: Start = 65 End = 84 Frequency = 1 [1] 14.66745 12.71021 17.58191 19.10350 15.57769 15.46616 15.03236 14.96683 [9] 16.00649 15.03068 13.20302 14.10757 14.86808 12.90813 17.77490 19.30262 [17] 15.77414 15.66152 15.23027 15.16307 $se Time Series: Start = 65 End = 84 Frequency = 1 [1] 0.9058466 1.1065993 1.3067286 1.6467572 1.8369911 2.0385562 2.2599169 [8] 2.4253372 2.5979272 2.7663187 2.9121590 3.0599463 3.5727584 3.8982690 [15] 4.2266934 4.6490995 4.9654734 5.2886320 5.6224789 5.9075199 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 65 End = 84 Frequency = 1 [1] 12.891991 10.541275 15.020725 15.875860 11.977191 11.470587 10.602925 [8] 10.213170 10.914556 9.608699 7.495187 8.110075 7.865474 5.267520 [15] 9.490582 10.190383 6.041814 5.295805 4.210210 3.584328 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 65 End = 84 Frequency = 1 [1] 16.44291 14.87914 20.14310 22.33115 19.17820 19.46173 19.46180 19.72049 [9] 21.09843 20.45267 18.91085 20.10506 21.87069 20.54873 26.05922 28.41485 [17] 25.50647 26.02724 26.25033 26.74181 > 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] 15.59000 13.17000 11.20000 13.30000 10.78000 11.60000 15.18000 15.87000 [9] 12.58000 11.43000 10.30000 11.17000 11.26000 11.20000 9.99000 11.17000 [17] 10.29000 10.47000 14.36000 16.06000 14.47000 13.24000 13.03000 14.43000 [25] 13.98000 13.62000 12.20000 12.24000 12.07000 12.30000 16.12000 18.38000 [33] 14.59000 12.96000 14.14000 13.92000 14.24000 14.10000 12.91000 13.69000 [41] 14.11000 13.99000 17.93000 21.37000 16.25000 14.53000 15.36000 14.95000 [49] 15.95000 15.25000 12.67000 13.86000 14.65000 12.41000 17.46000 18.95000 [57] 15.33000 15.31000 14.84000 14.75000 15.83000 14.83000 13.00000 13.92000 [65] 14.66745 12.71021 17.58191 19.10350 15.57769 15.46616 15.03236 14.96683 [73] 16.00649 15.03068 13.20302 14.10757 14.86808 12.90813 17.77490 19.30262 [81] 15.77414 15.66152 15.23027 15.16307 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 65 End = 84 Frequency = 1 [1] 0.06175897 0.08706381 0.07432232 0.08620184 0.11792446 0.13180754 [7] 0.15033678 0.16204748 0.16230458 0.18404477 0.22056767 0.21690102 [13] 0.24029723 0.30200113 0.23778998 0.24085332 0.31478564 0.33768310 [19] 0.36916480 0.38959927 > postscript(file="/var/www/html/rcomp/tmp/1lzop1229555202.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.se <- array(0, dim=fx) > perf.mse <- 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.mape[i] = perf.mape[i] + abs(perf.pe[i]) + perf.se[i] = (x[nx+i] - forecast$pred[i])^2 + perf.mse[i] = perf.mse[i] + perf.se[i] + 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 = perf.mape / fx > perf.mse = perf.mse / fx > perf.rmse = sqrt(perf.mse) > postscript(file="/var/www/html/rcomp/tmp/2svz31229555202.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:12] <- x[(nx+1):lx] Warning message: In NextMethod("[<-") : number of items to replace is not a multiple of replacement length > 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/3ei191229555203.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.mape[i],4)) + a<-table.element(a,round(perf.se[i],4)) + a<-table.element(a,round(perf.mse[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/4qnot1229555203.tab") > > system("convert tmp/1lzop1229555202.ps tmp/1lzop1229555202.png") > system("convert tmp/2svz31229555202.ps tmp/2svz31229555202.png") > > > proc.time() user system elapsed 0.623 0.315 0.792