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(0.42,0.74,1.02,1.51,1.86,1.59,1.03,0.44,0.82,0.86,0.57,0.59,0.95,0.98,1.23,1.17,0.84,0.74,0.65,0.91,1.19,1.3,1.53,1.94,1.79,1.95,2.26,2.04,2.16,2.75,2.79,2.88,3.36,2.97,3.1,2.49,2.2,2.25,2.09,2.79,3.14,2.93,2.65,2.67,2.26,2.35,2.13,2.18,2.9,2.63,2.67,1.81,1.33,0.88,1.28,1.26,1.26,1.29,1.1,1.37,1.21,1.74,1.76,1.48,1.04,1.62,1.49,1.79,1.8,1.58,1.86,1.74,1.59,1.26,1.13,1.92,2.61,2.26,2.41,2.26,2.03,2.86,2.55,2.27,2.26,2.57,3.07,2.76,2.51,2.87,3.14,3.11,3.16,2.47,2.57,2.89,2.63,2.38,1.69,1.96,2.19,1.87,1.6,1.63,1.22,1.21,1.49,1.64,1.66,1.77,1.82,1.78,1.28,1.29,1.37,1.12,1.51,2.24,2.94,3.09) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '1' > par6 = '2' > par5 = '12' > par4 = '0' > par3 = '1' > par2 = '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 ar2 ma1 sma1 0.6517 -0.2479 -0.5215 -0.9996 s.e. 0.2308 0.0984 0.2221 0.5146 sigma^2 estimated as 0.05986: log likelihood = -14.98, aic = 39.97 > (forecast <- predict(arima.out,fx)) $pred Time Series: Start = 109 End = 120 Frequency = 1 [1] 1.874903 1.768299 1.917496 1.707385 1.576406 1.654606 1.629610 1.532894 [9] 1.941724 2.095270 1.948006 1.785274 $se Time Series: Start = 109 End = 120 Frequency = 1 [1] 0.2577615 0.3880043 0.4606189 0.5073345 0.5452593 0.5808694 0.6155564 [8] 0.6490597 0.6810812 0.7116564 0.7410041 0.7692888 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 109 End = 120 Frequency = 1 [1] 1.3696903 1.0078104 1.0146826 0.7130092 0.5076978 0.5161021 0.4231194 [8] 0.2607371 0.6068044 0.7004231 0.4956375 0.2774682 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 109 End = 120 Frequency = 1 [1] 2.380115 2.528787 2.820309 2.701761 2.645114 2.793110 2.836100 2.805051 [9] 3.276643 3.490116 3.400374 3.293080 > 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] 0.420000 0.740000 1.020000 1.510000 1.860000 1.590000 1.030000 0.440000 [9] 0.820000 0.860000 0.570000 0.590000 0.950000 0.980000 1.230000 1.170000 [17] 0.840000 0.740000 0.650000 0.910000 1.190000 1.300000 1.530000 1.940000 [25] 1.790000 1.950000 2.260000 2.040000 2.160000 2.750000 2.790000 2.880000 [33] 3.360000 2.970000 3.100000 2.490000 2.200000 2.250000 2.090000 2.790000 [41] 3.140000 2.930000 2.650000 2.670000 2.260000 2.350000 2.130000 2.180000 [49] 2.900000 2.630000 2.670000 1.810000 1.330000 0.880000 1.280000 1.260000 [57] 1.260000 1.290000 1.100000 1.370000 1.210000 1.740000 1.760000 1.480000 [65] 1.040000 1.620000 1.490000 1.790000 1.800000 1.580000 1.860000 1.740000 [73] 1.590000 1.260000 1.130000 1.920000 2.610000 2.260000 2.410000 2.260000 [81] 2.030000 2.860000 2.550000 2.270000 2.260000 2.570000 3.070000 2.760000 [89] 2.510000 2.870000 3.140000 3.110000 3.160000 2.470000 2.570000 2.890000 [97] 2.630000 2.380000 1.690000 1.960000 2.190000 1.870000 1.600000 1.630000 [105] 1.220000 1.210000 1.490000 1.640000 1.874903 1.768299 1.917496 1.707385 [113] 1.576406 1.654606 1.629610 1.532894 1.941724 2.095270 1.948006 1.785274 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 109 End = 120 Frequency = 1 [1] 0.1374799 0.2194223 0.2402190 0.2971413 0.3458876 0.3510620 0.3777324 [8] 0.4234211 0.3507612 0.3396491 0.3803912 0.4309079 > postscript(file="/var/www/html/rcomp/tmp/1ac3k1229616099.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/2xyt41229616099.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/3ykm91229616099.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/4g3sg1229616100.tab") > > system("convert tmp/1ac3k1229616099.ps tmp/1ac3k1229616099.png") > system("convert tmp/2xyt41229616099.ps tmp/2xyt41229616099.png") > > > proc.time() user system elapsed 0.848 0.323 0.972