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(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 + ,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.2495 -0.706 -0.059 -0.7195 0.139 0.4351 s.e. NaN NaN NaN NaN NaN NaN sigma^2 estimated as 106.2: log likelihood = -1238.23, aic = 2490.45 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 = 332 End = 359 Frequency = 1 [1] 284.2960 285.5797 286.5592 287.0835 286.9713 286.4031 285.7415 285.3225 [9] 285.2997 285.6060 286.0296 286.3440 286.4196 286.2672 286.0047 285.7800 [17] 285.6935 285.7595 285.9164 286.0709 286.1493 286.1289 286.0389 285.9363 [25] 285.8728 285.8712 285.9201 285.9861 $se Time Series: Start = 332 End = 359 Frequency = 1 [1] 10.30464 18.83519 25.20416 30.96754 36.08974 40.45148 44.07051 47.11629 [9] 49.82450 52.40851 55.00230 57.63801 60.26284 62.79065 65.15856 67.35611 [17] 69.41927 71.40452 73.36133 75.31429 77.25951 79.17449 81.03478 82.82772 [25] 84.55692 86.23775 87.88842 89.52185 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 332 End = 359 Frequency = 1 [1] 264.0989 248.6627 237.1590 226.3871 216.2354 207.1182 199.3633 192.9746 [9] 187.6436 182.8853 178.2251 173.3735 168.3044 163.1975 158.2940 153.7620 [17] 149.6317 145.8066 142.1282 138.4549 134.7206 130.9469 127.2108 123.5940 [25] 120.1412 116.8452 113.6588 110.5233 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 332 End = 359 Frequency = 1 [1] 304.4931 322.4967 335.9593 347.7798 357.7072 365.6880 372.1197 377.6704 [9] 382.9557 388.3267 393.8341 399.3145 404.5348 409.3368 413.7155 417.7980 [17] 421.7552 425.7124 429.7046 433.6869 437.5779 441.3109 444.8671 448.2787 [25] 451.6044 454.8972 458.1814 461.4489 > 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] 280.2000 299.9000 339.2000 374.2000 393.5000 389.2000 381.7000 375.2000 [9] 369.0000 357.4000 352.1000 346.5000 342.9000 340.3000 328.3000 322.9000 [17] 314.3000 308.9000 294.0000 285.6000 281.2000 280.3000 278.8000 274.5000 [25] 270.4000 263.4000 259.9000 258.0000 262.7000 284.7000 311.3000 322.1000 [33] 327.0000 331.3000 333.3000 321.4000 327.0000 320.0000 314.7000 316.7000 [41] 314.4000 321.3000 318.2000 307.2000 301.3000 287.5000 277.7000 274.4000 [49] 258.8000 253.3000 251.0000 248.4000 249.5000 246.1000 244.5000 243.6000 [57] 244.0000 240.8000 249.8000 248.0000 259.4000 260.5000 260.8000 261.3000 [65] 259.5000 256.6000 257.9000 256.5000 254.2000 253.3000 253.8000 255.5000 [73] 257.1000 257.3000 253.2000 252.8000 252.0000 250.7000 252.2000 250.0000 [81] 251.0000 253.4000 251.2000 255.6000 261.1000 258.9000 259.9000 261.2000 [89] 264.7000 267.1000 266.4000 267.7000 268.6000 267.5000 268.5000 268.5000 [97] 270.5000 270.9000 270.1000 269.3000 269.8000 270.1000 264.9000 263.7000 [105] 264.8000 263.7000 255.9000 276.2000 360.1000 380.5000 373.7000 369.8000 [113] 366.6000 359.3000 345.8000 326.2000 324.5000 328.1000 327.5000 324.4000 [121] 316.5000 310.9000 301.5000 291.7000 290.4000 287.4000 277.7000 281.6000 [129] 288.0000 276.0000 272.9000 283.0000 283.3000 276.8000 284.5000 282.7000 [137] 281.2000 287.4000 283.1000 284.0000 285.5000 289.2000 292.5000 296.4000 [145] 305.2000 303.9000 311.5000 316.3000 316.7000 322.5000 317.1000 309.8000 [153] 303.8000 290.3000 293.7000 291.7000 296.5000 289.1000 288.5000 293.8000 [161] 297.7000 305.4000 302.7000 302.5000 303.0000 294.5000 294.1000 294.5000 [169] 297.1000 289.4000 292.4000 287.9000 286.6000 280.5000 272.4000 269.2000 [177] 270.6000 267.3000 262.5000 266.8000 268.8000 263.1000 261.2000 266.0000 [185] 262.5000 265.2000 261.3000 253.7000 249.2000 239.1000 236.4000 235.2000 [193] 245.2000 246.2000 247.7000 251.4000 253.3000 254.8000 250.0000 249.3000 [201] 241.5000 243.3000 248.0000 253.0000 252.9000 251.5000 251.6000 253.5000 [209] 259.8000 334.1000 448.0000 445.8000 445.0000 448.2000 438.2000 439.8000 [217] 423.4000 410.8000 408.4000 406.7000 405.9000 402.7000 405.1000 399.6000 [225] 386.5000 381.4000 375.2000 357.7000 359.0000 355.0000 352.7000 344.4000 [233] 343.8000 338.0000 339.0000 333.3000 334.4000 328.3000 330.7000 330.0000 [241] 331.6000 351.2000 389.4000 410.9000 442.8000 462.8000 466.9000 461.7000 [249] 439.2000 430.3000 416.1000 402.5000 397.3000 403.3000 395.9000 387.8000 [257] 378.6000 377.1000 370.4000 362.0000 350.3000 348.2000 344.6000 343.5000 [265] 342.8000 347.6000 346.6000 349.5000 342.1000 342.0000 342.8000 339.3000 [273] 348.2000 333.7000 334.7000 354.0000 367.7000 363.3000 358.4000 353.1000 [281] 343.1000 344.6000 344.4000 333.9000 331.7000 324.3000 321.2000 322.4000 [289] 321.7000 320.5000 312.8000 309.7000 315.6000 309.7000 304.6000 302.5000 [297] 301.5000 298.8000 291.3000 293.6000 294.6000 285.9000 297.6000 301.1000 [305] 293.8000 297.7000 292.9000 292.1000 287.2000 288.2000 283.8000 299.9000 [313] 292.4000 293.3000 300.8000 293.7000 293.1000 294.4000 292.1000 291.9000 [321] 282.5000 277.9000 287.5000 289.2000 285.6000 293.2000 290.8000 283.1000 [329] 275.0000 287.8000 287.8000 284.2960 285.5797 286.5592 287.0835 286.9713 [337] 286.4031 285.7415 285.3225 285.2997 285.6060 286.0296 286.3440 286.4196 [345] 286.2672 286.0047 285.7800 285.6935 285.7595 285.9164 286.0709 286.1493 [353] 286.1289 286.0389 285.9363 285.8728 285.8712 285.9201 285.9861 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 332 End = 359 Frequency = 1 [1] 0.03624618 0.06595423 0.08795445 0.10786946 0.12576082 0.14123965 [7] 0.15423211 0.16513344 0.17463919 0.18349933 0.19229584 0.20128943 [13] 0.21040054 0.21934281 0.22782336 0.23569217 0.24298516 0.24987630 [19] 0.25658319 0.26327145 0.26999723 0.27670919 0.28329983 0.28967191 [25] 0.29578511 0.30166645 0.30738805 0.31302869 > postscript(file="/var/www/html/rcomp/tmp/1z2i31260471274.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/2nilb1260471274.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/39uyt1260471274.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/47t2j1260471274.tab") > > system("convert tmp/1z2i31260471274.ps tmp/1z2i31260471274.png") > system("convert tmp/2nilb1260471274.ps tmp/2nilb1260471274.png") > > > proc.time() user system elapsed 1.631 0.338 1.757