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(2648.9,2669.6,3042.3,2604.2,2732.1,2621.7,2483.7,2479.3,2684.6,2834.7,2566.1,2251.2,2350,2299.8,2542.8,2530.2,2508.1,2616.8,2534.1,2181.8,2578.9,2841.9,2529.9,2103.2,2326.2,2452.6,2782.1,2727.3,2648.2,2760.7,2613,2225.4,2713.9,2923.3,2707,2473.9,2521,2531.8,3068.8,2826.9,2674.2,2966.6,2798.8,2629.6,3124.6,3115.7,3083,2863.9,2728.7,2789.4,3225.7,3148.2,2836.5,3153.5,2656.9,2834.7,3172.5,2998.8,3103.1,2735.6,2818.1,2874.4,3438.5,2949.1,3306.8,3530,3003.8,3206.4,3514.6,3522.6,3525.5,2996.2,3231.1,3030,3541.7,3113.2,3390.8,3424.2,3079.8,3123.4,3317.1,3579.9,3317.9,2668.1) > par10 = 'FALSE' > par9 = '1' > par8 = '1' > par7 = '1' > par6 = '0' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '0.0' > 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: ma1 sar1 sma1 -0.5719 0.4993 -0.9998 s.e. 0.0962 0.1817 0.2796 sigma^2 estimated as 0.002453: log likelihood = 87.58, aic = -167.16 > (forecast <- predict(arima.out,fx)) $pred Time Series: Start = 73 End = 84 Frequency = 1 [1] 8.052681 8.069613 8.233183 8.109642 8.174725 8.228747 8.101359 8.122618 [9] 8.230629 8.245886 8.223334 8.075662 $se Time Series: Start = 73 End = 84 Frequency = 1 [1] 0.05280373 0.05739138 0.06163852 0.06561131 0.06935691 0.07291034 [7] 0.07629845 0.07954238 0.08265910 0.08566250 0.08856410 0.09137361 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 73 End = 84 Frequency = 1 [1] 7.949185 7.957126 8.112371 7.981044 8.038786 8.085843 7.951814 7.966715 [9] 8.068617 8.077988 8.049748 7.896570 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 73 End = 84 Frequency = 1 [1] 8.156176 8.182100 8.353994 8.238240 8.310665 8.371652 8.250904 8.278521 [9] 8.392640 8.413785 8.396920 8.254755 > 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] 2648.900 2669.600 3042.300 2604.200 2732.100 2621.700 2483.700 2479.300 [9] 2684.600 2834.700 2566.100 2251.200 2350.000 2299.800 2542.800 2530.200 [17] 2508.100 2616.800 2534.100 2181.800 2578.900 2841.900 2529.900 2103.200 [25] 2326.200 2452.600 2782.100 2727.300 2648.200 2760.700 2613.000 2225.400 [33] 2713.900 2923.300 2707.000 2473.900 2521.000 2531.800 3068.800 2826.900 [41] 2674.200 2966.600 2798.800 2629.600 3124.600 3115.700 3083.000 2863.900 [49] 2728.700 2789.400 3225.700 3148.200 2836.500 3153.500 2656.900 2834.700 [57] 3172.500 2998.800 3103.100 2735.600 2818.100 2874.400 3438.500 2949.100 [65] 3306.800 3530.000 3003.800 3206.400 3514.600 3522.600 3525.500 2996.200 [73] 3142.207 3195.866 3763.793 3326.386 3550.079 3747.137 3298.949 3369.831 [81] 3754.193 3811.912 3726.907 3215.257 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 73 End = 84 Frequency = 1 [1] 0.05563296 0.06074379 0.06551642 0.07001686 0.07429216 0.07837722 [7] 0.08229882 0.08607801 0.08973171 0.09327374 0.09671559 0.10006689 > postscript(file="/var/www/html/rcomp/tmp/1r5iv1229450590.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/2ttj41229450591.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/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/3yap61229450591.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/458e41229450591.tab") > > system("convert tmp/1r5iv1229450590.ps tmp/1r5iv1229450590.png") > system("convert tmp/2ttj41229450591.ps tmp/2ttj41229450591.png") > > > proc.time() user system elapsed 0.803 0.353 5.203