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. Natural language support but running in an English locale 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(1.64,1.65,1.65,1.65,1.66,1.66,1.67,1.67,1.68,1.68,1.68,1.68,1.69,1.69,1.7,1.7,1.71,1.71,1.71,1.71,1.72,1.72,1.72,1.73,1.73,1.73,1.74,1.75,1.75,1.76,1.76,1.77,1.77,1.78,1.79,1.8,1.8,1.81,1.81,1.81,1.81,1.82,1.82,1.82,1.83,1.83,1.83,1.84,1.84,1.85,1.85,1.86,1.86,1.86,1.86,1.86) > par10 = 'FALSE' > par9 = '0' > par8 = '0' > par7 = '1' > par6 = '1' > par5 = '12' > par4 = '0' > par3 = '2' > 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 -0.6085 0.1859 -0.0412 -1.1543 -0.5615 0.7174 s.e. 0.5385 0.8314 0.4675 1.8511 0.6528 1.4912 sigma^2 estimated as 1.478e-05: log likelihood = 103.44, aic = -192.88 > (forecast <- predict(arima.out,par1)) $pred Time Series: Start = 29 End = 56 Frequency = 1 [1] 1.749101 1.751816 1.755027 1.759057 1.762532 1.766477 1.769999 1.773889 [9] 1.777456 1.781306 1.784909 1.788727 1.792357 1.796152 1.799803 1.803580 [17] 1.807246 1.811009 1.814688 1.818440 1.822128 1.825873 1.829568 1.833306 [25] 1.837006 1.840740 1.844444 1.848174 $se Time Series: Start = 29 End = 56 Frequency = 1 [1] 0.003997293 0.004180135 0.004300188 0.004318225 0.004411831 0.004442156 [7] 0.004534020 0.004573944 0.004663582 0.004712005 0.004800502 0.004856504 [13] 0.004944642 0.005007309 0.005095647 0.005164134 0.005253069 0.005326621 [19] 0.005416431 0.005494389 0.005585260 0.005667057 0.005759108 0.005844257 [25] 0.005937555 0.006025644 0.006120218 0.006210895 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 29 End = 56 Frequency = 1 [1] 1.741267 1.743623 1.746599 1.750593 1.753885 1.757770 1.761113 1.764924 [9] 1.768316 1.772070 1.775500 1.779209 1.782666 1.786338 1.789816 1.793458 [17] 1.796950 1.800569 1.804072 1.807671 1.811181 1.814765 1.818280 1.821851 [25] 1.825368 1.828929 1.832448 1.836000 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 29 End = 56 Frequency = 1 [1] 1.756936 1.760009 1.763455 1.767521 1.771180 1.775184 1.778886 1.782853 [9] 1.786597 1.790541 1.794318 1.798246 1.802049 1.805967 1.809790 1.813702 [17] 1.817542 1.821450 1.825304 1.829209 1.833075 1.836980 1.840855 1.844760 [25] 1.848644 1.852550 1.856440 1.860347 > 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] 1.640000 1.650000 1.650000 1.650000 1.660000 1.660000 1.670000 1.670000 [9] 1.680000 1.680000 1.680000 1.680000 1.690000 1.690000 1.700000 1.700000 [17] 1.710000 1.710000 1.710000 1.710000 1.720000 1.720000 1.720000 1.730000 [25] 1.730000 1.730000 1.740000 1.750000 1.749101 1.751816 1.755027 1.759057 [33] 1.762532 1.766477 1.769999 1.773889 1.777456 1.781306 1.784909 1.788727 [41] 1.792357 1.796152 1.799803 1.803580 1.807246 1.811009 1.814688 1.818440 [49] 1.822128 1.825873 1.829568 1.833306 1.837006 1.840740 1.844444 1.848174 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 29 End = 56 Frequency = 1 [1] 0.002285341 0.002386173 0.002450212 0.002454852 0.002503120 0.002514698 [7] 0.002561595 0.002578484 0.002623739 0.002645253 0.002689494 0.002715061 [13] 0.002758737 0.002787798 0.002831225 0.002863269 0.002906670 0.002941244 [19] 0.002984773 0.003021484 0.003065240 0.003103752 0.003147797 0.003187824 [25] 0.003232191 0.003273491 0.003318191 0.003360558 > postscript(file="/var/www/html/freestat/rcomp/tmp/1xt0z1293188159.ps",horizontal=F,onefile=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/freestat/rcomp/tmp/2b3g71293188159.ps",horizontal=F,onefile=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/freestat/rcomp/createtable file can be downloaded at http://www.wessa.net/cretab > load(file="/var/www/html/freestat/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/freestat/rcomp/tmp/3awxe1293188160.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/freestat/rcomp/tmp/4eeek1293188160.tab") > > try(system("convert tmp/1xt0z1293188159.ps tmp/1xt0z1293188159.png",intern=TRUE)) character(0) > try(system("convert tmp/2b3g71293188159.ps tmp/2b3g71293188159.png",intern=TRUE)) character(0) > > > proc.time() user system elapsed 1.088 0.451 1.957