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(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) > par20 = '' > par19 = '' > par18 = '' > par17 = '' > par16 = '' > par15 = '' > par14 = '' > par13 = '' > par12 = '' > par11 = '' > par10 = 'FALSE' > par9 = '1' > par8 = '2' > par7 = '0' > par6 = '0' > par5 = '12' > par4 = '1' > par3 = '1' > par2 = '1' > par1 = '12' > ylab = '' > xlab = '' > main = '' > #'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: sar1 sar2 sma1 0.5277 0.0439 -0.9999 s.e. 0.0749 0.0791 0.0991 sigma^2 estimated as 30.95: log likelihood = -687.71, aic = 1383.41 > (forecast <- predict(arima.out,fx)) $pred Time Series: Start = 230 End = 241 Frequency = 1 [1] 506.0805 508.4387 498.4543 484.0170 476.5947 464.3524 457.2827 511.3028 [9] 524.1810 508.0851 493.5491 477.8996 $se Time Series: Start = 230 End = 241 Frequency = 1 [1] 5.688430 8.044655 9.852650 11.376860 12.719716 13.933751 15.050171 [8] 16.089309 17.065289 17.988394 18.866387 19.705298 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 230 End = 241 Frequency = 1 [1] 494.9312 492.6712 479.1431 461.7183 451.6640 437.0423 427.7843 479.7678 [9] 490.7330 472.8279 456.5710 439.2772 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 230 End = 241 Frequency = 1 [1] 517.2298 524.2062 517.7655 506.3156 501.5253 491.6626 486.7810 542.8378 [9] 557.6289 543.3424 530.5272 516.5220 > 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] 451.0000 450.0000 444.0000 429.0000 421.0000 400.0000 389.0000 384.0000 [9] 432.0000 446.0000 431.0000 423.0000 416.0000 416.0000 413.0000 399.0000 [17] 386.0000 374.0000 365.0000 365.0000 418.0000 428.0000 424.0000 421.0000 [25] 417.0000 423.0000 423.0000 419.0000 406.0000 398.0000 390.0000 391.0000 [33] 444.0000 460.0000 455.0000 456.0000 452.0000 459.0000 461.0000 451.0000 [41] 443.0000 439.0000 430.0000 436.0000 488.0000 506.0000 502.0000 501.0000 [49] 501.0000 515.0000 521.0000 520.0000 512.0000 509.0000 505.0000 511.0000 [57] 570.0000 592.0000 594.0000 586.0000 586.0000 592.0000 594.0000 586.0000 [65] 572.0000 563.0000 555.0000 554.0000 601.0000 622.0000 617.0000 606.0000 [73] 595.0000 599.0000 600.0000 592.0000 575.0000 567.0000 555.0000 555.0000 [81] 608.0000 631.0000 629.0000 624.0000 610.0000 616.0000 621.0000 604.0000 [89] 584.0000 574.0000 555.0000 545.0000 599.0000 620.0000 608.0000 590.0000 [97] 579.0000 580.0000 579.0000 572.0000 560.0000 551.0000 537.0000 541.0000 [105] 588.0000 607.0000 599.0000 578.0000 563.0000 566.0000 561.0000 554.0000 [113] 540.0000 526.0000 512.0000 505.0000 554.0000 584.0000 569.0000 540.0000 [121] 522.0000 526.0000 527.0000 516.0000 503.0000 489.0000 479.0000 475.0000 [129] 524.0000 552.0000 532.0000 511.0000 492.0000 492.0000 493.0000 481.0000 [137] 462.0000 457.0000 442.0000 439.0000 488.0000 521.0000 501.0000 485.0000 [145] 464.0000 460.0000 467.0000 460.0000 448.0000 443.0000 436.0000 431.0000 [153] 484.0000 510.0000 513.0000 503.0000 471.0000 471.0000 476.0000 475.0000 [161] 470.0000 461.0000 455.0000 456.0000 517.0000 525.0000 523.0000 519.0000 [169] 509.0000 512.0000 519.0000 517.0000 510.0000 509.0000 501.0000 507.0000 [177] 569.0000 580.0000 578.0000 565.0000 547.0000 555.0000 562.0000 561.0000 [185] 555.0000 544.0000 537.0000 543.0000 594.0000 611.0000 613.0000 611.0000 [193] 594.0000 595.0000 591.0000 589.0000 584.0000 573.0000 567.0000 569.0000 [201] 621.0000 629.0000 628.0000 612.0000 595.0000 597.0000 593.0000 590.0000 [209] 580.0000 574.0000 573.0000 573.0000 620.0000 626.0000 620.0000 588.0000 [217] 566.0000 557.0000 561.0000 549.0000 532.0000 526.0000 511.0000 499.0000 [225] 555.0000 565.0000 542.0000 527.0000 510.0000 506.0805 508.4387 498.4543 [233] 484.0170 476.5947 464.3524 457.2827 511.3028 524.1810 508.0851 493.5491 [241] 477.8996 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 230 End = 241 Frequency = 1 [1] 0.01124017 0.01582227 0.01976641 0.02350508 0.02668875 0.03000684 [7] 0.03291218 0.03146728 0.03255610 0.03540429 0.03822596 0.04123313 > postscript(file="/var/www/html/rcomp/tmp/1heeu1229960804.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/24nas1229960804.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] > 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/3wmej1229960804.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/4nzs21229960804.tab") > > system("convert tmp/1heeu1229960804.ps tmp/1heeu1229960804.png") > system("convert tmp/24nas1229960804.ps tmp/24nas1229960804.png") > > > proc.time() user system elapsed 1.776 0.336 1.896