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(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 + ,311.3) > 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.2492 -0.7097 -0.0581 -0.7196 0.1421 0.4363 s.e. NaN NaN NaN NaN NaN NaN sigma^2 estimated as 106.5: log likelihood = -1234.96, aic = 2483.92 Warning messages: 1: In arima(x[1:nx], order = c(par6, par3, par7), seasonal = list(order = c(par8, : possible convergence problem: optim gave code=1 2: In sqrt(diag(x$var.coef)) : NaNs produced > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 331 End = 358 Frequency = 1 [1] 284.2825 285.5554 286.5343 287.0582 286.9438 286.3724 285.7092 285.2930 [9] 285.2770 285.5908 286.0185 286.3308 286.3993 286.2383 285.9705 285.7461 [17] 285.6654 285.7392 285.9019 286.0573 286.1317 286.1050 286.0097 285.9053 [25] 285.8441 285.8473 285.9007 285.9688 $se Time Series: Start = 331 End = 358 Frequency = 1 [1] 10.31980 18.85888 25.22560 30.98185 36.09728 40.45402 44.07018 47.11543 [9] 49.82562 52.41391 55.01332 57.65424 60.28211 62.81003 65.17582 67.37066 [17] 69.43224 71.41800 73.37731 75.33376 77.28206 79.19862 81.05879 82.85055 [25] 84.57856 86.25907 87.91061 89.54581 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 331 End = 358 Frequency = 1 [1] 264.0557 248.5920 237.0922 226.3338 216.1932 207.0825 199.3316 192.9468 [9] 187.6187 182.8596 178.1923 173.3285 168.2464 163.1307 158.2259 153.6996 [17] 149.5782 145.7600 142.0823 138.4031 134.6589 130.8757 127.1345 123.5182 [25] 120.0701 116.7795 113.5959 110.4590 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 331 End = 358 Frequency = 1 [1] 304.5093 322.5188 335.9765 347.7826 357.6945 365.6623 372.0868 377.6392 [9] 382.9352 388.3221 393.8446 399.3332 404.5523 409.3460 413.7151 417.7926 [17] 421.7526 425.7185 429.7214 433.7115 437.6046 441.3343 444.8849 448.2924 [25] 451.6181 454.9151 458.2055 461.4786 > 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] 299.9000 339.2000 374.2000 393.5000 389.2000 381.7000 375.2000 369.0000 [9] 357.4000 352.1000 346.5000 342.9000 340.3000 328.3000 322.9000 314.3000 [17] 308.9000 294.0000 285.6000 281.2000 280.3000 278.8000 274.5000 270.4000 [25] 263.4000 259.9000 258.0000 262.7000 284.7000 311.3000 322.1000 327.0000 [33] 331.3000 333.3000 321.4000 327.0000 320.0000 314.7000 316.7000 314.4000 [41] 321.3000 318.2000 307.2000 301.3000 287.5000 277.7000 274.4000 258.8000 [49] 253.3000 251.0000 248.4000 249.5000 246.1000 244.5000 243.6000 244.0000 [57] 240.8000 249.8000 248.0000 259.4000 260.5000 260.8000 261.3000 259.5000 [65] 256.6000 257.9000 256.5000 254.2000 253.3000 253.8000 255.5000 257.1000 [73] 257.3000 253.2000 252.8000 252.0000 250.7000 252.2000 250.0000 251.0000 [81] 253.4000 251.2000 255.6000 261.1000 258.9000 259.9000 261.2000 264.7000 [89] 267.1000 266.4000 267.7000 268.6000 267.5000 268.5000 268.5000 270.5000 [97] 270.9000 270.1000 269.3000 269.8000 270.1000 264.9000 263.7000 264.8000 [105] 263.7000 255.9000 276.2000 360.1000 380.5000 373.7000 369.8000 366.6000 [113] 359.3000 345.8000 326.2000 324.5000 328.1000 327.5000 324.4000 316.5000 [121] 310.9000 301.5000 291.7000 290.4000 287.4000 277.7000 281.6000 288.0000 [129] 276.0000 272.9000 283.0000 283.3000 276.8000 284.5000 282.7000 281.2000 [137] 287.4000 283.1000 284.0000 285.5000 289.2000 292.5000 296.4000 305.2000 [145] 303.9000 311.5000 316.3000 316.7000 322.5000 317.1000 309.8000 303.8000 [153] 290.3000 293.7000 291.7000 296.5000 289.1000 288.5000 293.8000 297.7000 [161] 305.4000 302.7000 302.5000 303.0000 294.5000 294.1000 294.5000 297.1000 [169] 289.4000 292.4000 287.9000 286.6000 280.5000 272.4000 269.2000 270.6000 [177] 267.3000 262.5000 266.8000 268.8000 263.1000 261.2000 266.0000 262.5000 [185] 265.2000 261.3000 253.7000 249.2000 239.1000 236.4000 235.2000 245.2000 [193] 246.2000 247.7000 251.4000 253.3000 254.8000 250.0000 249.3000 241.5000 [201] 243.3000 248.0000 253.0000 252.9000 251.5000 251.6000 253.5000 259.8000 [209] 334.1000 448.0000 445.8000 445.0000 448.2000 438.2000 439.8000 423.4000 [217] 410.8000 408.4000 406.7000 405.9000 402.7000 405.1000 399.6000 386.5000 [225] 381.4000 375.2000 357.7000 359.0000 355.0000 352.7000 344.4000 343.8000 [233] 338.0000 339.0000 333.3000 334.4000 328.3000 330.7000 330.0000 331.6000 [241] 351.2000 389.4000 410.9000 442.8000 462.8000 466.9000 461.7000 439.2000 [249] 430.3000 416.1000 402.5000 397.3000 403.3000 395.9000 387.8000 378.6000 [257] 377.1000 370.4000 362.0000 350.3000 348.2000 344.6000 343.5000 342.8000 [265] 347.6000 346.6000 349.5000 342.1000 342.0000 342.8000 339.3000 348.2000 [273] 333.7000 334.7000 354.0000 367.7000 363.3000 358.4000 353.1000 343.1000 [281] 344.6000 344.4000 333.9000 331.7000 324.3000 321.2000 322.4000 321.7000 [289] 320.5000 312.8000 309.7000 315.6000 309.7000 304.6000 302.5000 301.5000 [297] 298.8000 291.3000 293.6000 294.6000 285.9000 297.6000 301.1000 293.8000 [305] 297.7000 292.9000 292.1000 287.2000 288.2000 283.8000 299.9000 292.4000 [313] 293.3000 300.8000 293.7000 293.1000 294.4000 292.1000 291.9000 282.5000 [321] 277.9000 287.5000 289.2000 285.6000 293.2000 290.8000 283.1000 275.0000 [329] 287.8000 287.8000 284.2825 285.5554 286.5343 287.0582 286.9438 286.3724 [337] 285.7092 285.2930 285.2770 285.5908 286.0185 286.3308 286.3993 286.2383 [345] 285.9705 285.7461 285.6654 285.7392 285.9019 286.0573 286.1317 286.1050 [353] 286.0097 285.9053 285.8441 285.8473 285.9007 285.9688 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 331 End = 358 Frequency = 1 [1] 0.03630121 0.06604281 0.08803692 0.10792881 0.12579912 0.14126371 [7] 0.15424839 0.16514750 0.17465701 0.18352800 0.19234185 0.20135534 [13] 0.21048273 0.21943263 0.22791101 0.23577103 0.24305446 0.24994116 [19] 0.25665208 0.26335200 0.27009256 0.27681664 0.28341275 0.28978318 [25] 0.29589052 0.30176628 0.30748647 0.31313137 > postscript(file="/var/www/html/rcomp/tmp/1kzgs1260474470.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/2s0ju1260474470.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/3k81j1260474470.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/43uie1260474470.tab") > > system("convert tmp/1kzgs1260474470.ps tmp/1kzgs1260474470.png") > system("convert tmp/2s0ju1260474470.ps tmp/2s0ju1260474470.png") > > > proc.time() user system elapsed 1.656 0.331 1.773