R version 2.9.0 (2009-04-17) Copyright (C) 2009 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(255 + ,280.2 + ,299.9 + ,339.2 + ,374.2 + ,393.5 + ,389.2 + ,381.7 + ,375.2 + ,369 + ,357.4 + ,352.1 + ,346.5 + ,342.9 + ,340.3 + ,328.3 + ,322.9 + ,314.3 + ,308.9 + ,294 + ,285.6 + ,281.2 + ,280.3 + ,278.8 + ,274.5 + ,270.4 + ,263.4 + ,259.9 + ,258 + ,262.7 + ,284.7 + ,311.3 + ,322.1 + ,327 + ,331.3 + ,333.3 + ,321.4 + ,327 + ,320 + ,314.7 + ,316.7 + ,314.4 + ,321.3 + ,318.2 + ,307.2 + ,301.3 + ,287.5 + ,277.7 + ,274.4 + ,258.8 + ,253.3 + ,251 + ,248.4 + ,249.5 + ,246.1 + ,244.5 + ,243.6 + ,244 + ,240.8 + ,249.8 + ,248 + ,259.4 + ,260.5 + ,260.8 + ,261.3 + ,259.5 + ,256.6 + ,257.9 + ,256.5 + ,254.2 + ,253.3 + ,253.8 + ,255.5 + ,257.1 + ,257.3 + ,253.2 + ,252.8 + ,252 + ,250.7 + ,252.2 + ,250 + ,251 + ,253.4 + ,251.2 + ,255.6 + ,261.1 + ,258.9 + ,259.9 + ,261.2 + ,264.7 + ,267.1 + ,266.4 + ,267.7 + ,268.6 + ,267.5 + ,268.5 + ,268.5 + ,270.5 + ,270.9 + ,270.1 + ,269.3 + ,269.8 + ,270.1 + ,264.9 + ,263.7 + ,264.8 + ,263.7 + ,255.9 + ,276.2 + ,360.1 + ,380.5 + ,373.7 + ,369.8 + ,366.6 + ,359.3 + ,345.8 + ,326.2 + ,324.5 + ,328.1 + ,327.5 + ,324.4 + ,316.5 + ,310.9 + ,301.5 + ,291.7 + ,290.4 + ,287.4 + ,277.7 + ,281.6 + ,288 + ,276 + ,272.9 + ,283 + ,283.3 + ,276.8 + ,284.5 + ,282.7 + ,281.2 + ,287.4 + ,283.1 + ,284 + ,285.5 + ,289.2 + ,292.5 + ,296.4 + ,305.2 + ,303.9 + ,311.5 + ,316.3 + ,316.7 + ,322.5 + ,317.1 + ,309.8 + ,303.8 + ,290.3 + ,293.7 + ,291.7 + ,296.5 + ,289.1 + ,288.5 + ,293.8 + ,297.7 + ,305.4 + ,302.7 + ,302.5 + ,303 + ,294.5 + ,294.1 + ,294.5 + ,297.1 + ,289.4 + ,292.4 + ,287.9 + ,286.6 + ,280.5 + ,272.4 + ,269.2 + ,270.6 + ,267.3 + ,262.5 + ,266.8 + ,268.8 + ,263.1 + ,261.2 + ,266 + ,262.5 + ,265.2 + ,261.3 + ,253.7 + ,249.2 + ,239.1 + ,236.4 + ,235.2 + ,245.2 + ,246.2 + ,247.7 + ,251.4 + ,253.3 + ,254.8 + ,250 + ,249.3 + ,241.5 + ,243.3 + ,248 + ,253 + ,252.9 + ,251.5 + ,251.6 + ,253.5 + ,259.8 + ,334.1 + ,448 + ,445.8 + ,445 + ,448.2 + ,438.2 + ,439.8 + ,423.4 + ,410.8 + ,408.4 + ,406.7 + ,405.9 + ,402.7 + ,405.1 + ,399.6 + ,386.5 + ,381.4 + ,375.2 + ,357.7 + ,359 + ,355 + ,352.7 + ,344.4 + ,343.8 + ,338 + ,339 + ,333.3 + ,334.4 + ,328.3 + ,330.7 + ,330 + ,331.6 + ,351.2 + ,389.4 + ,410.9 + ,442.8 + ,462.8 + ,466.9 + ,461.7 + ,439.2 + ,430.3 + ,416.1 + ,402.5 + ,397.3 + ,403.3 + ,395.9 + ,387.8 + ,378.6 + ,377.1 + ,370.4 + ,362 + ,350.3 + ,348.2 + ,344.6 + ,343.5 + ,342.8 + ,347.6 + ,346.6 + ,349.5 + ,342.1 + ,342 + ,342.8 + ,339.3 + ,348.2 + ,333.7 + ,334.7 + ,354 + ,367.7 + ,363.3 + ,358.4 + ,353.1 + ,343.1 + ,344.6 + ,344.4 + ,333.9 + ,331.7 + ,324.3 + ,321.2 + ,322.4 + ,321.7 + ,320.5 + ,312.8 + ,309.7 + ,315.6 + ,309.7 + ,304.6 + ,302.5 + ,301.5 + ,298.8 + ,291.3 + ,293.6 + ,294.6 + ,285.9 + ,297.6 + ,301.1 + ,293.8 + ,297.7 + ,292.9 + ,292.1 + ,287.2 + ,288.2 + ,283.8 + ,299.9 + ,292.4 + ,293.3 + ,300.8 + ,293.7 + ,293.1 + ,294.4 + ,292.1 + ,291.9 + ,282.5 + ,277.9 + ,287.5 + ,289.2 + ,285.6 + ,293.2 + ,290.8 + ,283.1 + ,275 + ,287.8 + ,287.8 + ,287.4 + ,284 + ,277.8 + ,277.6 + ,304.9 + ,294 + ,300.9 + ,324 + ,332.9 + ,341.6 + ,333.4 + ,348.2 + ,344.7 + ,344.7 + ,329.3 + ,323.5 + ,323.2 + ,317.4 + ,330.1 + ,329.2 + ,334.9 + ,315.8 + ,315.4 + ,319.6 + ,317.3 + ,313.8 + ,315.8) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '0' > par6 = '0' > par5 = '12' > par4 = '0' > par3 = '1' > par2 = '1' > par1 = '24' > par1 <- as.numeric(par1) #cut off periods > par1 <- 28 > 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 > par6 <- 3 > par7 <- as.numeric(par7) #q > par7 <- 3 > 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 ma1 ma2 ma3 1.1805 -0.5621 -0.0924 -0.6451 0.0466 0.4014 s.e. 0.2742 0.4960 0.1833 0.2695 0.3594 0.1216 sigma^2 estimated as 107.0: log likelihood = -1239.42, aic = 2492.85 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 332 End = 359 Frequency = 1 [1] 294.9056 295.4533 297.8645 299.7465 300.5624 300.2448 299.2374 298.1514 [9] 297.4648 297.3579 297.7180 298.2665 298.7216 298.9172 298.8416 298.6004 [17] 298.3401 298.1753 298.1495 298.2356 298.3670 298.4761 298.5231 298.5051 [25] 298.4474 298.3850 298.3454 298.3392 $se Time Series: Start = 332 End = 359 Frequency = 1 [1] 10.34244 18.95060 25.51509 31.56992 36.93993 41.50250 45.29284 48.48786 [9] 51.31424 53.97113 56.58768 59.21108 61.82125 64.36546 66.79604 69.09323 [17] 71.26754 73.34815 75.36743 77.34921 79.30367 81.22895 83.11695 84.95991 [25] 86.75468 88.50363 90.21293 91.88967 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 332 End = 359 Frequency = 1 [1] 274.6344 258.3102 247.8549 237.8695 228.1601 218.8999 210.4635 203.1152 [9] 196.8889 191.5745 186.8061 182.2128 177.5520 172.7609 167.9214 163.1777 [17] 158.6557 154.4130 150.4293 146.6311 142.9318 139.2674 135.6139 131.9837 [25] 128.4082 124.9179 121.5281 118.2354 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 332 End = 359 Frequency = 1 [1] 315.1767 332.5965 347.8741 361.6236 372.9646 381.5897 388.0114 393.1876 [9] 398.0407 403.1414 408.6298 414.3203 419.8913 425.0735 429.7619 434.0232 [17] 438.0245 441.9377 445.8696 449.8400 453.8022 457.6849 461.4324 465.0266 [25] 468.4866 471.8521 475.1628 478.4429 > 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] 255.0000 280.2000 299.9000 339.2000 374.2000 393.5000 389.2000 381.7000 [9] 375.2000 369.0000 357.4000 352.1000 346.5000 342.9000 340.3000 328.3000 [17] 322.9000 314.3000 308.9000 294.0000 285.6000 281.2000 280.3000 278.8000 [25] 274.5000 270.4000 263.4000 259.9000 258.0000 262.7000 284.7000 311.3000 [33] 322.1000 327.0000 331.3000 333.3000 321.4000 327.0000 320.0000 314.7000 [41] 316.7000 314.4000 321.3000 318.2000 307.2000 301.3000 287.5000 277.7000 [49] 274.4000 258.8000 253.3000 251.0000 248.4000 249.5000 246.1000 244.5000 [57] 243.6000 244.0000 240.8000 249.8000 248.0000 259.4000 260.5000 260.8000 [65] 261.3000 259.5000 256.6000 257.9000 256.5000 254.2000 253.3000 253.8000 [73] 255.5000 257.1000 257.3000 253.2000 252.8000 252.0000 250.7000 252.2000 [81] 250.0000 251.0000 253.4000 251.2000 255.6000 261.1000 258.9000 259.9000 [89] 261.2000 264.7000 267.1000 266.4000 267.7000 268.6000 267.5000 268.5000 [97] 268.5000 270.5000 270.9000 270.1000 269.3000 269.8000 270.1000 264.9000 [105] 263.7000 264.8000 263.7000 255.9000 276.2000 360.1000 380.5000 373.7000 [113] 369.8000 366.6000 359.3000 345.8000 326.2000 324.5000 328.1000 327.5000 [121] 324.4000 316.5000 310.9000 301.5000 291.7000 290.4000 287.4000 277.7000 [129] 281.6000 288.0000 276.0000 272.9000 283.0000 283.3000 276.8000 284.5000 [137] 282.7000 281.2000 287.4000 283.1000 284.0000 285.5000 289.2000 292.5000 [145] 296.4000 305.2000 303.9000 311.5000 316.3000 316.7000 322.5000 317.1000 [153] 309.8000 303.8000 290.3000 293.7000 291.7000 296.5000 289.1000 288.5000 [161] 293.8000 297.7000 305.4000 302.7000 302.5000 303.0000 294.5000 294.1000 [169] 294.5000 297.1000 289.4000 292.4000 287.9000 286.6000 280.5000 272.4000 [177] 269.2000 270.6000 267.3000 262.5000 266.8000 268.8000 263.1000 261.2000 [185] 266.0000 262.5000 265.2000 261.3000 253.7000 249.2000 239.1000 236.4000 [193] 235.2000 245.2000 246.2000 247.7000 251.4000 253.3000 254.8000 250.0000 [201] 249.3000 241.5000 243.3000 248.0000 253.0000 252.9000 251.5000 251.6000 [209] 253.5000 259.8000 334.1000 448.0000 445.8000 445.0000 448.2000 438.2000 [217] 439.8000 423.4000 410.8000 408.4000 406.7000 405.9000 402.7000 405.1000 [225] 399.6000 386.5000 381.4000 375.2000 357.7000 359.0000 355.0000 352.7000 [233] 344.4000 343.8000 338.0000 339.0000 333.3000 334.4000 328.3000 330.7000 [241] 330.0000 331.6000 351.2000 389.4000 410.9000 442.8000 462.8000 466.9000 [249] 461.7000 439.2000 430.3000 416.1000 402.5000 397.3000 403.3000 395.9000 [257] 387.8000 378.6000 377.1000 370.4000 362.0000 350.3000 348.2000 344.6000 [265] 343.5000 342.8000 347.6000 346.6000 349.5000 342.1000 342.0000 342.8000 [273] 339.3000 348.2000 333.7000 334.7000 354.0000 367.7000 363.3000 358.4000 [281] 353.1000 343.1000 344.6000 344.4000 333.9000 331.7000 324.3000 321.2000 [289] 322.4000 321.7000 320.5000 312.8000 309.7000 315.6000 309.7000 304.6000 [297] 302.5000 301.5000 298.8000 291.3000 293.6000 294.6000 285.9000 297.6000 [305] 301.1000 293.8000 297.7000 292.9000 292.1000 287.2000 288.2000 283.8000 [313] 299.9000 292.4000 293.3000 300.8000 293.7000 293.1000 294.4000 292.1000 [321] 291.9000 282.5000 277.9000 287.5000 289.2000 285.6000 293.2000 290.8000 [329] 283.1000 275.0000 287.8000 294.9056 295.4533 297.8645 299.7465 300.5624 [337] 300.2448 299.2374 298.1514 297.4648 297.3579 297.7180 298.2665 298.7216 [345] 298.9172 298.8416 298.6004 298.3401 298.1753 298.1495 298.2356 298.3670 [353] 298.4761 298.5231 298.5051 298.4474 298.3850 298.3454 298.3392 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 332 End = 359 Frequency = 1 [1] 0.03507035 0.06414076 0.08566006 0.10532204 0.12290272 0.13822887 [7] 0.15136088 0.16262834 0.17250523 0.18150223 0.19007142 0.19851734 [13] 0.20695270 0.21532871 0.22351651 0.23139025 0.23888020 0.24598998 [19] 0.25278406 0.25935608 0.26579236 0.27214553 0.27842717 0.28461792 [25] 0.29068666 0.29660885 0.30237745 0.30800402 > postscript(file="/var/www/html/rcomp/tmp/1irx31260468034.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.mape1 <- array(0, dim=fx) > perf.se <- array(0, dim=fx) > perf.mse <- array(0, dim=fx) > perf.mse1 <- 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.se[i] = (x[nx+i] - forecast$pred[i])^2 + 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[1] = abs(perf.pe[1]) > perf.mse[1] = abs(perf.se[1]) > for (i in 2:fx) { + perf.mape[i] = perf.mape[i-1] + abs(perf.pe[i]) + perf.mape1[i] = perf.mape[i] / i + perf.mse[i] = perf.mse[i-1] + perf.se[i] + perf.mse1[i] = perf.mse[i] / i + } > perf.rmse = sqrt(perf.mse1) > postscript(file="/var/www/html/rcomp/tmp/2zcjh1260468034.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:par1] <- 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/3kf9d1260468034.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.mape1[i],4)) + a<-table.element(a,round(perf.se[i],4)) + a<-table.element(a,round(perf.mse1[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/4ptgy1260468034.tab") > > system("convert tmp/1irx31260468034.ps tmp/1irx31260468034.png") > system("convert tmp/2zcjh1260468034.ps tmp/2zcjh1260468034.png") > > > proc.time() user system elapsed 1.212 0.332 1.350