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(77.7,78.89,90.2,77.26,80.76,84.93,66.08,71.56,80.78,83.31,85.3,73.94,78.7,81.32,86.8,80.76,84.46,84.21,73.64,70.85,83.78,89.12,78.93,80.54,81.67,82.53,88.2,89.17,83.7,89.79,77.58,70.11,88.07,92.49,83.33,90.05,82.91,88.52,96.42,90.87,86.4,97.47,85.67,79.91,95.73,94.6,91.92,90.38,82.31,87.82,101.29,89.58,87.83,99.95,82.67,84.65,97.83,97.47,97.66,99.14,90.02,100.97,112.48,91.44,108.46,98.41,89.35,92.8,100.43,104.85,108.36,101.54,105.26,101.8,112.36,99.5,104.65,101.13,89.8,87.84,96.41,103.26,100.31,92.33,96.19,96.37,103.06,101.5,101.88,100.85,95.56,87.6,101.18,110.8,101.1,104.42,103.27,100.87,107.8,104.99,100.76,104.46,100.62,87.84,107.31,115.61,103.43,109.93,104.43,106.69,123.1,109.42,101.46,124.48,101.49,100.46,115.51,113.37,115.4,118.2,106.82,110.17,119.91,112.31,110.62,120.37,97.94,103.02,116.36,108.51,122.54,121.32,112.25,109.89,129.58,107.2,118.68,118.25,102.67,104.19,117.74,123.3,122.2,112.71,118.53,115.32,127.36,110.45,122.22,123.39,116.2,109.22,116.98,132.89,125.24,115.68) > par10 = 'FALSE' > par9 = '1' > par8 = '2' > par7 = '0' > par6 = '3' > par5 = '12' > par4 = '1' > par3 = '0' > 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: ar1 ar2 ar3 sar1 sar2 sma1 0.0246 0.3819 0.5904 0.2059 -0.2454 -0.8951 s.e. 0.0788 0.0632 0.0771 0.1315 0.1049 0.2235 sigma^2 estimated as 0.001915: log likelihood = 214.89, aic = -415.78 > (forecast <- predict(arima.out,fx)) $pred Time Series: Start = 145 End = 156 Frequency = 1 [1] 4.180124 4.151943 4.283700 4.168417 4.187357 4.222348 4.088699 4.035749 [9] 4.210776 4.282797 4.209449 4.178876 $se Time Series: Start = 145 End = 156 Frequency = 1 [1] 0.04417201 0.04418137 0.04728668 0.05435919 0.05490224 0.05855215 [7] 0.06163282 0.06294248 0.06593402 0.06801268 0.06974289 0.07209858 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 145 End = 156 Frequency = 1 [1] 4.093547 4.065348 4.191018 4.061873 4.079748 4.107585 3.967898 3.912382 [9] 4.081545 4.149492 4.072753 4.037563 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 145 End = 156 Frequency = 1 [1] 4.266701 4.238539 4.376381 4.274961 4.294965 4.337110 4.209499 4.159116 [9] 4.340007 4.416102 4.346145 4.320189 > 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] 77.7000 78.8900 90.2000 77.2600 80.7600 84.9300 66.0800 71.5600 [9] 80.7800 83.3100 85.3000 73.9400 78.7000 81.3200 86.8000 80.7600 [17] 84.4600 84.2100 73.6400 70.8500 83.7800 89.1200 78.9300 80.5400 [25] 81.6700 82.5300 88.2000 89.1700 83.7000 89.7900 77.5800 70.1100 [33] 88.0700 92.4900 83.3300 90.0500 82.9100 88.5200 96.4200 90.8700 [41] 86.4000 97.4700 85.6700 79.9100 95.7300 94.6000 91.9200 90.3800 [49] 82.3100 87.8200 101.2900 89.5800 87.8300 99.9500 82.6700 84.6500 [57] 97.8300 97.4700 97.6600 99.1400 90.0200 100.9700 112.4800 91.4400 [65] 108.4600 98.4100 89.3500 92.8000 100.4300 104.8500 108.3600 101.5400 [73] 105.2600 101.8000 112.3600 99.5000 104.6500 101.1300 89.8000 87.8400 [81] 96.4100 103.2600 100.3100 92.3300 96.1900 96.3700 103.0600 101.5000 [89] 101.8800 100.8500 95.5600 87.6000 101.1800 110.8000 101.1000 104.4200 [97] 103.2700 100.8700 107.8000 104.9900 100.7600 104.4600 100.6200 87.8400 [105] 107.3100 115.6100 103.4300 109.9300 104.4300 106.6900 123.1000 109.4200 [113] 101.4600 124.4800 101.4900 100.4600 115.5100 113.3700 115.4000 118.2000 [121] 106.8200 110.1700 119.9100 112.3100 110.6200 120.3700 97.9400 103.0200 [129] 116.3600 108.5100 122.5400 121.3200 112.2500 109.8900 129.5800 107.2000 [137] 118.6800 118.2500 102.6700 104.1900 117.7400 123.3000 122.2000 112.7100 [145] 117.6604 115.0371 127.6625 116.5656 118.3404 121.6690 109.2992 104.6519 [153] 120.5611 127.5729 120.4345 117.5434 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 145 End = 156 Frequency = 1 [1] 0.03608282 0.03634154 0.03773358 0.04478009 0.04503010 0.04770750 [7] 0.05200124 0.05386675 0.05408908 0.05488368 0.05734987 0.05981345 > postscript(file="/var/www/html/rcomp/tmp/1tva81229251634.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/2jq5l1229251634.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/3lx2y1229251634.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/4r3af1229251634.tab") > > system("convert tmp/1tva81229251634.ps tmp/1tva81229251634.png") > system("convert tmp/2jq5l1229251634.ps tmp/2jq5l1229251634.png") > > > proc.time() user system elapsed 3.337 0.418 4.291