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(13.92,13.22,13.31,12.91,13.19,12.92,13.43,13.72,13.97,14.91,14.46,14.12,14.23,15.04,14.80,14.49,15.14,14.34,15.12,15.14,14.34,14.36,14.91,15.56,16.50,15.57,15.14,15.19,15.07,14.48,14.27,14.72,14.65,14.38,13.95,14.85,14.87,14.83,15.03,15.47,16.21,16.55,17.04,17.22,17.47,17.75,17.84,18.47,18.38,18.55,18.39,18.88,20.21,19.67,20.09,18.78,19.74,20.64,20.34,21.75,22.10,22.81,22.91,22.46,21.78,25.05,23.70,23.02,24.34,24.15,25.85,26.42,26.54,26.36,26.99,27.52,26.63,26.26,24.86,26.84,26.57,24.67,27.24,27.77,27.61,27.27,28.46,26.97,29.95,29.88,29.67,31.19,30.24,30.03,31.02,30.45,31.70,32.10,32.32,32.18,33.43,33.07,35.32,35.17,35.29,37.89,38.32,37.07,39.77,39.20,40.46,44.95,41.69,41.88,45.86) > par10 = 'FALSE' > par9 = '0' > par8 = '1' > par7 = '0' > par6 = '0' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '-0.3' > par1 = '12' > #'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: sar1 -0.4268 s.e. 0.0986 sigma^2 estimated as 3.526e-05: log likelihood = 332.46, aic = -660.92 > (forecast <- predict(arima.out,fx)) $pred Time Series: Start = 104 End = 115 Frequency = 1 [1] 0.3364534 0.3388405 0.3428631 0.3360841 0.3363125 0.3341180 0.3339423 [8] 0.3315122 0.3343175 0.3271012 0.3278600 0.3242626 $se Time Series: Start = 104 End = 115 Frequency = 1 [1] 0.005938143 0.008397803 0.010285166 0.011876286 0.013278092 0.014545421 [7] 0.015710850 0.016795605 0.017814429 0.018778057 0.019694593 0.020570331 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 104 End = 115 Frequency = 1 [1] 0.3248146 0.3223808 0.3227042 0.3128066 0.3102874 0.3056090 0.3031491 [8] 0.2985928 0.2994012 0.2902962 0.2892586 0.2839448 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 104 End = 115 Frequency = 1 [1] 0.3480921 0.3553002 0.3630221 0.3593616 0.3623375 0.3626270 0.3647356 [8] 0.3644316 0.3692338 0.3639062 0.3664614 0.3645805 > 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] 13.92000 13.22000 13.31000 12.91000 13.19000 12.92000 13.43000 13.72000 [9] 13.97000 14.91000 14.46000 14.12000 14.23000 15.04000 14.80000 14.49000 [17] 15.14000 14.34000 15.12000 15.14000 14.34000 14.36000 14.91000 15.56000 [25] 16.50000 15.57000 15.14000 15.19000 15.07000 14.48000 14.27000 14.72000 [33] 14.65000 14.38000 13.95000 14.85000 14.87000 14.83000 15.03000 15.47000 [41] 16.21000 16.55000 17.04000 17.22000 17.47000 17.75000 17.84000 18.47000 [49] 18.38000 18.55000 18.39000 18.88000 20.21000 19.67000 20.09000 18.78000 [57] 19.74000 20.64000 20.34000 21.75000 22.10000 22.81000 22.91000 22.46000 [65] 21.78000 25.05000 23.70000 23.02000 24.34000 24.15000 25.85000 26.42000 [73] 26.54000 26.36000 26.99000 27.52000 26.63000 26.26000 24.86000 26.84000 [81] 26.57000 24.67000 27.24000 27.77000 27.61000 27.27000 28.46000 26.97000 [89] 29.95000 29.88000 29.67000 31.19000 30.24000 30.03000 31.02000 30.45000 [97] 31.70000 32.10000 32.32000 32.18000 33.43000 33.07000 35.32000 37.75001 [105] 36.87079 35.44846 37.88845 37.80275 38.63673 38.70452 39.65837 38.55995 [113] 41.46927 41.15020 42.69172 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 104 End = 115 Frequency = 1 [1] 0.06352697 0.09212115 0.11419817 0.13790916 0.15712489 0.17663736 [7] 0.19415599 0.21280618 0.22673077 0.24932871 0.26440834 0.28403996 > postscript(file="/var/www/html/freestat/rcomp/tmp/1bhsk1229366990.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/freestat/rcomp/tmp/2u81k1229366990.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] > lines(dum, lty=1) > lines(ub,lty=3) > lines(lb,lty=3) > dev.off() null device 1 > > #Note: the /var/www/html/freestat/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/freestat/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/freestat/rcomp/tmp/3six31229366990.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/freestat/rcomp/tmp/42xyb1229366990.tab") > > system("convert tmp/1bhsk1229366990.ps tmp/1bhsk1229366990.png") > system("convert tmp/2u81k1229366990.ps tmp/2u81k1229366990.png") > > > proc.time() user system elapsed 0.856 0.446 1.186