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(349 + ,336 + ,331 + ,327 + ,323 + ,322 + ,385 + ,405 + ,412 + ,411 + ,410 + ,415 + ,414 + ,411 + ,408 + ,410 + ,411 + ,416 + ,479 + ,498 + ,502 + ,498 + ,499 + ,506 + ,510 + ,509 + ,502 + ,495 + ,490 + ,490 + ,553 + ,570 + ,573 + ,572 + ,575 + ,580 + ,580 + ,574 + ,563 + ,556 + ,546 + ,545 + ,605 + ,628 + ,631 + ,626 + ,614 + ,606 + ,602 + ,589 + ,574 + ,558 + ,552 + ,546 + ,607 + ,636 + ,631 + ,623 + ,618 + ,605 + ,619 + ,596 + ,570 + ,546 + ,528 + ,506 + ,555 + ,568 + ,564 + ,553 + ,541 + ,542 + ,540 + ,521 + ,505 + ,491 + ,482 + ,478 + ,523 + ,531 + ,532 + ,540 + ,525 + ,533 + ,531 + ,508 + ,495 + ,482 + ,470 + ,466 + ,515 + ,518 + ,516 + ,511 + ,500 + ,498 + ,494 + ,476 + ,458 + ,443 + ,430 + ,424 + ,476 + ,481 + ,470 + ,460 + ,451 + ,450 + ,444 + ,429 + ,421 + ,400 + ,389 + ,384 + ,432 + ,446 + ,431 + ,423 + ,416 + ,416 + ,413 + ,399 + ,386 + ,374 + ,365 + ,365 + ,418 + ,428 + ,424 + ,421 + ,417 + ,423 + ,423 + ,419 + ,406 + ,398 + ,390 + ,391 + ,444 + ,460 + ,455 + ,456 + ,452 + ,459 + ,461 + ,451 + ,443 + ,439 + ,430 + ,436 + ,488 + ,506 + ,502 + ,501 + ,501 + ,515 + ,521 + ,520 + ,512 + ,509 + ,505 + ,511 + ,570 + ,592 + ,594 + ,586 + ,586 + ,592 + ,594 + ,586 + ,572 + ,563 + ,555 + ,554 + ,601 + ,622 + ,617 + ,606 + ,595 + ,599 + ,600 + ,592 + ,575 + ,567 + ,555 + ,555 + ,608 + ,631 + ,629 + ,624 + ,610 + ,616 + ,621 + ,604 + ,584 + ,574 + ,555 + ,545 + ,599 + ,620 + ,608 + ,590 + ,579 + ,580 + ,579 + ,572 + ,560 + ,551 + ,537 + ,541 + ,588 + ,607 + ,599 + ,578 + ,563 + ,566 + ,561 + ,554 + ,540 + ,526 + ,512 + ,505 + ,554 + ,584 + ,569 + ,540 + ,522 + ,526 + ,527 + ,516 + ,503 + ,489 + ,479 + ,475 + ,524 + ,552 + ,532 + ,511 + ,492 + ,492 + ,493 + ,481 + ,462 + ,457 + ,442 + ,439 + ,488 + ,521 + ,501 + ,485 + ,464 + ,460 + ,467 + ,460 + ,448 + ,443 + ,436 + ,431 + ,484 + ,510 + ,513 + ,503 + ,471 + ,471 + ,476 + ,475 + ,470 + ,461 + ,455 + ,456 + ,517 + ,525 + ,523 + ,519 + ,509 + ,512 + ,519 + ,517 + ,510 + ,509 + ,501 + ,507 + ,569 + ,580 + ,578 + ,565 + ,547 + ,555 + ,562 + ,561 + ,555 + ,544 + ,537 + ,543 + ,594 + ,611 + ,613 + ,611 + ,594 + ,595 + ,591 + ,589 + ,584 + ,573 + ,567 + ,569 + ,621 + ,629 + ,628 + ,612 + ,595 + ,597 + ,593 + ,590 + ,580 + ,574 + ,573 + ,573 + ,620 + ,626 + ,620 + ,588 + ,566 + ,557 + ,561 + ,549 + ,532 + ,526 + ,511 + ,499 + ,555 + ,565 + ,542 + ,527 + ,510 + ,514 + ,517 + ,508 + ,493 + ,490 + ,469 + ,478 + ,528 + ,534 + ,518 + ,506 + ,502 + ,516 + ,528 + ,533 + ,536 + ,537 + ,524 + ,536 + ,587 + ,597 + ,581 + ,564 + ,558) > par10 = 'FALSE' > par9 = '1' > par8 = '1' > par7 = '2' > par6 = '3' > par5 = '1' > par4 = '1' > par3 = '1' > par2 = '1' > par1 = '12' > 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 <- 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 sar1 sma1 1.5123 -0.6641 -0.1472 -1.2426 -0.0715 0.5598 -0.1595 -0.9463 s.e. 0.1965 0.3279 0.1834 0.0931 0.1612 0.0857 0.1972 0.0189 sigma^2 estimated as 242.7: log likelihood = -1440.63, aic = 2899.26 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 348 End = 359 Frequency = 1 [1] 489.2535 473.8027 463.5648 458.7874 460.0826 466.0276 474.1903 481.7216 [9] 486.1412 485.9479 480.9380 472.1653 $se Time Series: Start = 348 End = 359 Frequency = 1 [1] 15.58022 23.90804 27.54769 29.70024 30.94252 31.90291 33.02234 34.74752 [9] 37.49201 41.40458 46.20895 51.33137 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 348 End = 359 Frequency = 1 [1] 458.7163 426.9429 409.5713 400.5749 399.4353 403.4979 409.4666 413.6164 [9] 412.6568 404.7949 390.3685 371.5559 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 348 End = 359 Frequency = 1 [1] 519.7908 520.6625 517.5583 516.9999 520.7299 528.5573 538.9141 549.8267 [9] 559.6255 567.1009 571.5076 572.7748 > 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] 349.0000 336.0000 331.0000 327.0000 323.0000 322.0000 385.0000 405.0000 [9] 412.0000 411.0000 410.0000 415.0000 414.0000 411.0000 408.0000 410.0000 [17] 411.0000 416.0000 479.0000 498.0000 502.0000 498.0000 499.0000 506.0000 [25] 510.0000 509.0000 502.0000 495.0000 490.0000 490.0000 553.0000 570.0000 [33] 573.0000 572.0000 575.0000 580.0000 580.0000 574.0000 563.0000 556.0000 [41] 546.0000 545.0000 605.0000 628.0000 631.0000 626.0000 614.0000 606.0000 [49] 602.0000 589.0000 574.0000 558.0000 552.0000 546.0000 607.0000 636.0000 [57] 631.0000 623.0000 618.0000 605.0000 619.0000 596.0000 570.0000 546.0000 [65] 528.0000 506.0000 555.0000 568.0000 564.0000 553.0000 541.0000 542.0000 [73] 540.0000 521.0000 505.0000 491.0000 482.0000 478.0000 523.0000 531.0000 [81] 532.0000 540.0000 525.0000 533.0000 531.0000 508.0000 495.0000 482.0000 [89] 470.0000 466.0000 515.0000 518.0000 516.0000 511.0000 500.0000 498.0000 [97] 494.0000 476.0000 458.0000 443.0000 430.0000 424.0000 476.0000 481.0000 [105] 470.0000 460.0000 451.0000 450.0000 444.0000 429.0000 421.0000 400.0000 [113] 389.0000 384.0000 432.0000 446.0000 431.0000 423.0000 416.0000 416.0000 [121] 413.0000 399.0000 386.0000 374.0000 365.0000 365.0000 418.0000 428.0000 [129] 424.0000 421.0000 417.0000 423.0000 423.0000 419.0000 406.0000 398.0000 [137] 390.0000 391.0000 444.0000 460.0000 455.0000 456.0000 452.0000 459.0000 [145] 461.0000 451.0000 443.0000 439.0000 430.0000 436.0000 488.0000 506.0000 [153] 502.0000 501.0000 501.0000 515.0000 521.0000 520.0000 512.0000 509.0000 [161] 505.0000 511.0000 570.0000 592.0000 594.0000 586.0000 586.0000 592.0000 [169] 594.0000 586.0000 572.0000 563.0000 555.0000 554.0000 601.0000 622.0000 [177] 617.0000 606.0000 595.0000 599.0000 600.0000 592.0000 575.0000 567.0000 [185] 555.0000 555.0000 608.0000 631.0000 629.0000 624.0000 610.0000 616.0000 [193] 621.0000 604.0000 584.0000 574.0000 555.0000 545.0000 599.0000 620.0000 [201] 608.0000 590.0000 579.0000 580.0000 579.0000 572.0000 560.0000 551.0000 [209] 537.0000 541.0000 588.0000 607.0000 599.0000 578.0000 563.0000 566.0000 [217] 561.0000 554.0000 540.0000 526.0000 512.0000 505.0000 554.0000 584.0000 [225] 569.0000 540.0000 522.0000 526.0000 527.0000 516.0000 503.0000 489.0000 [233] 479.0000 475.0000 524.0000 552.0000 532.0000 511.0000 492.0000 492.0000 [241] 493.0000 481.0000 462.0000 457.0000 442.0000 439.0000 488.0000 521.0000 [249] 501.0000 485.0000 464.0000 460.0000 467.0000 460.0000 448.0000 443.0000 [257] 436.0000 431.0000 484.0000 510.0000 513.0000 503.0000 471.0000 471.0000 [265] 476.0000 475.0000 470.0000 461.0000 455.0000 456.0000 517.0000 525.0000 [273] 523.0000 519.0000 509.0000 512.0000 519.0000 517.0000 510.0000 509.0000 [281] 501.0000 507.0000 569.0000 580.0000 578.0000 565.0000 547.0000 555.0000 [289] 562.0000 561.0000 555.0000 544.0000 537.0000 543.0000 594.0000 611.0000 [297] 613.0000 611.0000 594.0000 595.0000 591.0000 589.0000 584.0000 573.0000 [305] 567.0000 569.0000 621.0000 629.0000 628.0000 612.0000 595.0000 597.0000 [313] 593.0000 590.0000 580.0000 574.0000 573.0000 573.0000 620.0000 626.0000 [321] 620.0000 588.0000 566.0000 557.0000 561.0000 549.0000 532.0000 526.0000 [329] 511.0000 499.0000 555.0000 565.0000 542.0000 527.0000 510.0000 514.0000 [337] 517.0000 508.0000 493.0000 490.0000 469.0000 478.0000 528.0000 534.0000 [345] 518.0000 506.0000 502.0000 489.2535 473.8027 463.5648 458.7874 460.0826 [353] 466.0276 474.1903 481.7216 486.1412 485.9479 480.9380 472.1653 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 348 End = 359 Frequency = 1 [1] 0.03184488 0.05045991 0.05942577 0.06473639 0.06725426 0.06845712 [7] 0.06963942 0.07213195 0.07712165 0.08520374 0.09608088 0.10871482 > postscript(file="/var/www/html/rcomp/tmp/1f9ln1260741792.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/2aesd1260741792.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/33e3t1260741792.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/4skbg1260741792.tab") > > try(system("convert tmp/1f9ln1260741792.ps tmp/1f9ln1260741792.png",intern=TRUE)) character(0) > try(system("convert tmp/2aesd1260741792.ps tmp/2aesd1260741792.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.417 0.331 1.593