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(180144,173666,165688,161570,156145,153730,182698,200765,176512,166618,158644,159585,163095,159044,155511,153745,150569,150605,179612,194690,189917,184128,175335,179566,181140,177876,175041,169292,166070,166972,206348,215706,202108,195411,193111,195198,198770,194163,190420,189733,186029,191531,232571,243477,227247,217859,208679,213188,216234,213586,209465,204045,200237,203666,241476,260307,243324,244460,233575,237217,235243,230354,227184,221678,217142,219452,256446,265845,248624,241114,229245,231805,219277,219313,212610,214771,211142,211457,240048,240636,230580,208795,197922,194596) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '0' > par6 = '1' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '1' > par1 = '36' > #'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 0.0295 s.e. 0.1677 sigma^2 estimated as 24901166: log likelihood = -347.7, aic = 699.39 > (forecast <- predict(arima.out,fx)) $pred Time Series: Start = 49 End = 84 Frequency = 1 [1] 216831.5 212226.6 208483.7 207796.7 204092.7 209594.7 250634.7 261540.7 [9] 245310.7 235922.7 226742.7 231251.7 234895.2 230290.4 226547.4 225860.4 [17] 222156.4 227658.4 268698.4 279604.4 263374.4 253986.4 244806.4 249315.4 [25] 252958.9 248354.1 244611.1 243924.1 240220.1 245722.1 286762.1 297668.1 [33] 281438.1 272050.1 262870.1 267379.1 $se Time Series: Start = 49 End = 84 Frequency = 1 [1] 4990.107 7162.047 8816.656 10206.529 11428.609 12532.078 13545.953 [8] 14489.054 15374.412 16211.490 17007.418 17767.727 20453.634 22891.447 [15] 25095.320 27120.738 29005.067 30774.232 32447.077 34037.806 35557.442 [22] 37014.742 38416.801 39769.461 42601.720 45307.030 47861.066 50285.587 [29] 52598.470 54813.847 56943.099 58995.553 60978.964 62899.864 64763.814 [36] 66575.599 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 49 End = 84 Frequency = 1 [1] 207050.9 198189.0 191203.1 187791.9 181692.6 185031.8 224084.6 233142.2 [9] 215176.9 204148.2 193408.2 196427.0 194806.1 185423.1 177360.6 172703.8 [17] 165306.5 167340.9 205102.1 212890.3 193681.8 181437.5 169509.5 171367.3 [25] 169459.6 159552.3 150803.4 145364.4 137127.1 138287.0 175153.7 182036.8 [33] 161919.4 148766.4 135933.1 136891.0 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 49 End = 84 Frequency = 1 [1] 226612.1 226264.3 225764.4 227801.5 226492.8 234157.6 277184.8 289939.3 [9] 275444.6 267697.2 260077.2 266076.5 274984.4 275157.6 275734.2 279017.1 [17] 279006.3 287975.9 332294.7 346318.5 333067.0 326535.3 320103.3 327263.6 [25] 336458.3 337155.8 338418.8 342483.9 343313.1 353157.3 398370.6 413299.4 [33] 400956.9 395333.9 389807.2 397867.3 > 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] 180144.0 173666.0 165688.0 161570.0 156145.0 153730.0 182698.0 200765.0 [9] 176512.0 166618.0 158644.0 159585.0 163095.0 159044.0 155511.0 153745.0 [17] 150569.0 150605.0 179612.0 194690.0 189917.0 184128.0 175335.0 179566.0 [25] 181140.0 177876.0 175041.0 169292.0 166070.0 166972.0 206348.0 215706.0 [33] 202108.0 195411.0 193111.0 195198.0 198770.0 194163.0 190420.0 189733.0 [41] 186029.0 191531.0 232571.0 243477.0 227247.0 217859.0 208679.0 213188.0 [49] 216831.5 212226.6 208483.7 207796.7 204092.7 209594.7 250634.7 261540.7 [57] 245310.7 235922.7 226742.7 231251.7 234895.2 230290.4 226547.4 225860.4 [65] 222156.4 227658.4 268698.4 279604.4 263374.4 253986.4 244806.4 249315.4 [73] 252958.9 248354.1 244611.1 243924.1 240220.1 245722.1 286762.1 297668.1 [81] 281438.1 272050.1 262870.1 267379.1 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 49 End = 84 Frequency = 1 [1] 0.02301375 0.03374716 0.04228942 0.04911786 0.05599715 0.05979196 [7] 0.05404659 0.05539885 0.06267322 0.06871526 0.07500756 0.07683285 [13] 0.08707556 0.09940254 0.11077292 0.12007743 0.13056146 0.13517722 [19] 0.12075649 0.12173558 0.13500720 0.14573512 0.15692726 0.15951465 [25] 0.16841357 0.18242919 0.19566185 0.20615258 0.21895946 0.22307249 [31] 0.19857259 0.19819238 0.21666917 0.23120689 0.24637191 0.24899325 > postscript(file="/var/www/html/rcomp/tmp/1ew9z1229277731.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/240xg1229277731.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/328uu1229277731.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/4svq61229277731.tab") > > system("convert tmp/1ew9z1229277731.ps tmp/1ew9z1229277731.png") > system("convert tmp/240xg1229277731.ps tmp/240xg1229277731.png") > > > proc.time() user system elapsed 0.695 0.354 0.850