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(97.57,97.74,97.92,98.19,98.23,98.41,98.59,98.71,99.14,99.62,100.18,100.66,101.19,101.75,102.2,102.87,98.81,97.6,96.68,95.96,98.89,99.05,99.2,99.11,99.19,99.77,100.70,100.78,100.53,101.01,100.92,101.10,103.11,102.99,102.31,102.61,103.68,104.72,107.66,108.87,108.12,107.61,106.42,105.61,105.71,105.49,105.57,105.18,106.09,106.34,108.47,116.87,121.08,123.27,124.18,125.60,126.57,127.18,128.04,128.55,129.67) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '1' > par6 = '2' > par5 = '12' > par4 = '0' > par3 = '1' > par2 = '-2.0' > 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 ar2 ma1 0.1124 0.0205 0.1207 s.e. NaN NaN NaN sigma^2 estimated as 3.813e-12: log likelihood = 562.88, aic = -1117.77 Warning message: In sqrt(diag(x$var.coef)) : NaNs produced > (forecast <- predict(arima.out,fx)) $pred Time Series: Start = 50 End = 61 Frequency = 1 [1] 8.848348e-05 8.841076e-05 8.839509e-05 8.839184e-05 8.839115e-05 [6] 8.839101e-05 8.839098e-05 8.839097e-05 8.839097e-05 8.839097e-05 [11] 8.839097e-05 8.839097e-05 $se Time Series: Start = 50 End = 61 Frequency = 1 [1] 1.952789e-06 3.100328e-06 3.982256e-06 4.712006e-06 5.344921e-06 [6] 5.910812e-06 6.427139e-06 6.904979e-06 7.351829e-06 7.773034e-06 [11] 8.172559e-06 8.553444e-06 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 50 End = 61 Frequency = 1 [1] 8.465602e-05 8.233412e-05 8.058987e-05 7.915631e-05 7.791511e-05 [6] 7.680582e-05 7.579379e-05 7.485721e-05 7.398139e-05 7.315582e-05 [11] 7.237275e-05 7.162622e-05 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 50 End = 61 Frequency = 1 [1] 9.231095e-05 9.448740e-05 9.620031e-05 9.762737e-05 9.886720e-05 [6] 9.997620e-05 1.009882e-04 1.019247e-04 1.028006e-04 1.036261e-04 [11] 1.044092e-04 1.051557e-04 > 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] 97.5700 97.7400 97.9200 98.1900 98.2300 98.4100 98.5900 98.7100 [9] 99.1400 99.6200 100.1800 100.6600 101.1900 101.7500 102.2000 102.8700 [17] 98.8100 97.6000 96.6800 95.9600 98.8900 99.0500 99.2000 99.1100 [25] 99.1900 99.7700 100.7000 100.7800 100.5300 101.0100 100.9200 101.1000 [33] 103.1100 102.9900 102.3100 102.6100 103.6800 104.7200 107.6600 108.8700 [41] 108.1200 107.6100 106.4200 105.6100 105.7100 105.4900 105.5700 105.1800 [49] 106.0900 106.3087 106.3524 106.3619 106.3638 106.3642 106.3643 106.3643 [57] 106.3643 106.3643 106.3643 106.3643 106.3643 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 50 End = 61 Frequency = 1 [1] 0.01140617 0.01849259 0.02413603 0.02894299 0.03321826 0.03712801 [7] 0.04076991 0.04420592 0.04747795 0.05061583 0.05364169 0.05657245 > postscript(file="/var/www/html/rcomp/tmp/1clyg1229889716.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/2ocx71229889716.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/3gy3q1229889716.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/4vaov1229889716.tab") > > system("convert tmp/1clyg1229889716.ps tmp/1clyg1229889716.png") > system("convert tmp/2ocx71229889716.ps tmp/2ocx71229889716.png") > > > proc.time() user system elapsed 0.584 0.304 0.712