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(67.8,66.9,71.5,75.9,71.9,70.7,73.5,76.1,82.5,87.1,83.2,86.1,85.9,77.4,74.4,69.9,73.8,69.2,69.7,71,71.2,75.8,73,66.4,58.6,55.5,52.6,54.9,54.6,51.2,50.9,49.6,53.4,52,47.5,42.1,44.5,43.2,51.4,59.4,60.3,61.4,68.8,73.6,81.8,79.6,85.8,88.1,89.1,95,96.2,84.2,96.9,103.1,99.3,103.5,112.4,111.1,113.7,92,93,98.4,92.6,94.6,99.5,97.6,91.3,93.6,93.1,78.4,70.2,69.3,71.1,73.5,85.9,91.5,91.8,88.3,91.3,94,99.3,96.7,88,96.7,106.8,114.3,105.7,90.1,91.6,97.7,100.8,104.6,95.9,102.7,104,107.9,113.8,113.8,123.1,125.1,137.6,134,140.3,152.1,150.6,167.3,153.2,142,154.4,158.5,180.9,181.3,172.4,192,199.3,215.4,214.3,201.5,190.5,196,215.7,209.4,214.1,237.8,239,237.8,251.5,248.8,215.4,201.2,203.1,214.2,188.9,203,213.3,228.5,228.2,240.9,258.8,248.5,269.2,289.6,323.4,317.2,322.8,340.9,368.2,388.5,441.2,474.3,483.9,417.9,365.9,263,199.4) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '1' > par6 = '1' > par5 = '12' > par4 = '0' > par3 = '2' > par2 = '-0.1' > par1 = '12' > #'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: ar1 ma1 0.1442 -0.9986 s.e. 0.0847 0.1614 sigma^2 estimated as 1.939e-05: log likelihood = 562.67, aic = -1119.35 > (forecast <- predict(arima.out,fx)) $pred Time Series: Start = 144 End = 155 Frequency = 1 [1] 0.5596047 0.5588132 0.5581205 0.5574421 0.5567657 0.5560897 0.5554136 [8] 0.5547376 0.5540616 0.5533856 0.5527096 0.5520335 $se Time Series: Start = 144 End = 155 Frequency = 1 [1] 0.004415816 0.006733888 0.008514783 0.010008587 0.011324273 0.012517452 [7] 0.013620273 0.014653142 0.015629935 0.016560581 0.017452467 0.018311261 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 144 End = 155 Frequency = 1 [1] 0.5509497 0.5456148 0.5414316 0.5378253 0.5345702 0.5315555 0.5287179 [8] 0.5260175 0.5234269 0.5209268 0.5185027 0.5161435 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 144 End = 155 Frequency = 1 [1] 0.5682597 0.5720116 0.5748095 0.5770589 0.5789613 0.5806239 0.5821094 [8] 0.5834578 0.5846963 0.5858443 0.5869164 0.5879236 > 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] 67.8000 66.9000 71.5000 75.9000 71.9000 70.7000 73.5000 76.1000 [9] 82.5000 87.1000 83.2000 86.1000 85.9000 77.4000 74.4000 69.9000 [17] 73.8000 69.2000 69.7000 71.0000 71.2000 75.8000 73.0000 66.4000 [25] 58.6000 55.5000 52.6000 54.9000 54.6000 51.2000 50.9000 49.6000 [33] 53.4000 52.0000 47.5000 42.1000 44.5000 43.2000 51.4000 59.4000 [41] 60.3000 61.4000 68.8000 73.6000 81.8000 79.6000 85.8000 88.1000 [49] 89.1000 95.0000 96.2000 84.2000 96.9000 103.1000 99.3000 103.5000 [57] 112.4000 111.1000 113.7000 92.0000 93.0000 98.4000 92.6000 94.6000 [65] 99.5000 97.6000 91.3000 93.6000 93.1000 78.4000 70.2000 69.3000 [73] 71.1000 73.5000 85.9000 91.5000 91.8000 88.3000 91.3000 94.0000 [81] 99.3000 96.7000 88.0000 96.7000 106.8000 114.3000 105.7000 90.1000 [89] 91.6000 97.7000 100.8000 104.6000 95.9000 102.7000 104.0000 107.9000 [97] 113.8000 113.8000 123.1000 125.1000 137.6000 134.0000 140.3000 152.1000 [105] 150.6000 167.3000 153.2000 142.0000 154.4000 158.5000 180.9000 181.3000 [113] 172.4000 192.0000 199.3000 215.4000 214.3000 201.5000 190.5000 196.0000 [121] 215.7000 209.4000 214.1000 237.8000 239.0000 237.8000 251.5000 248.8000 [129] 215.4000 201.2000 203.1000 214.2000 188.9000 203.0000 213.3000 228.5000 [137] 228.2000 240.9000 258.8000 248.5000 269.2000 289.6000 323.4000 332.0367 [145] 336.7699 340.9730 345.1455 349.3614 353.6321 357.9600 362.3463 366.7917 [153] 371.2972 375.8636 380.4919 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 144 End = 155 Frequency = 1 [1] 0.08605904 0.13775746 0.18097133 0.21980716 0.25613645 0.29093209 [7] 0.32476262 0.35799336 0.39087694 0.42359827 0.45629906 0.48909208 > postscript(file="/var/www/html/rcomp/tmp/1ky8i1229889918.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/2w8je1229889919.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/3przg1229889919.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/485iq1229889919.tab") > > system("convert tmp/1ky8i1229889918.ps tmp/1ky8i1229889918.png") > system("convert tmp/2w8je1229889919.ps tmp/2w8je1229889919.png") > > > proc.time() user system elapsed 0.618 0.338 0.726