R version 2.7.0 (2008-04-22) 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(267.850 + ,255.468 + ,246.717 + ,238.276 + ,229.336 + ,231.047 + ,264.440 + ,261.308 + ,257.844 + ,253.687 + ,248.286 + ,248.641 + ,243.753 + ,233.495 + ,222.356 + ,211.333 + ,202.478 + ,202.746 + ,238.802 + ,235.385 + ,224.820 + ,219.386 + ,213.106 + ,213.166 + ,208.201 + ,197.775 + ,189.191 + ,178.543 + ,171.809 + ,172.365 + ,204.140 + ,205.467 + ,193.079 + ,190.224 + ,185.553 + ,185.184 + ,183.059 + ,175.496 + ,168.120 + ,160.374 + ,155.290 + ,156.152 + ,189.784 + ,192.250 + ,184.896 + ,184.835 + ,180.172 + ,181.875 + ,182.412 + ,180.627 + ,174.303 + ,169.431 + ,163.902 + ,166.114 + ,198.414 + ,205.626 + ,199.333 + ,199.588 + ,196.569 + ,200.880 + ,201.579 + ,195.483 + ,190.617 + ,187.576 + ,183.968 + ,186.998 + ,216.617 + ,224.692 + ,222.476 + ,223.247 + ,225.618 + ,232.758 + ,235.868 + ,232.863 + ,227.564 + ,226.822 + ,223.864 + ,227.155 + ,260.300 + ,273.944 + ,270.779 + ,268.104 + ,268.703 + ,273.413 + ,275.597 + ,270.111 + ,262.272 + ,255.823 + ,250.753 + ,250.512 + ,277.888 + ,289.694 + ,281.310 + ,275.425 + ,271.287 + ,274.059 + ,274.113 + ,267.546 + ,257.622 + ,250.612 + ,243.829 + ,243.180 + ,275.362 + ,287.027 + ,279.175 + ,282.416 + ,275.424 + ,277.862 + ,284.998 + ,272.182 + ,258.613 + ,253.046 + ,243.315 + ,234.312 + ,265.912 + ,279.384 + ,262.547 + ,256.102 + ,251.133 + ,249.598 + ,251.592 + ,244.976 + ,237.527 + ,232.790 + ,224.726 + ,223.918 + ,252.637 + ,263.736 + ,251.143 + ,239.530 + ,232.401 + ,233.749 + ,232.055 + ,224.473 + ,215.866 + ,207.808 + ,199.440 + ,193.330 + ,222.787 + ,241.434 + ,221.263 + ,207.448 + ,200.241 + ,205.009 + ,206.230 + ,198.253 + ,194.660 + ,185.847 + ,180.314 + ,176.282 + ,203.541 + ,222.042 + ,197.519 + ,185.142 + ,176.355 + ,180.448 + ,180.143 + ,173.666 + ,165.687 + ,162.719 + ,157.079 + ,153.730 + ,182.698 + ,200.765 + ,176.512 + ,166.618 + ,158.644 + ,159.585 + ,163.095 + ,159.044 + ,155.511 + ,153.745 + ,150.569 + ,150.605 + ,179.612 + ,194.690 + ,189.917 + ,184.128 + ,175.335 + ,179.566 + ,181.140 + ,177.876 + ,175.041 + ,169.292 + ,166.070 + ,166.972 + ,206.348 + ,215.706 + ,202.108 + ,195.411 + ,193.111 + ,195.198 + ,198.770 + ,194.163 + ,190.420 + ,189.733 + ,186.029 + ,191.531 + ,232.571 + ,243.477 + ,227.247 + ,217.859 + ,208.679 + ,213.188 + ,216.234 + ,213.587 + ,209.465 + ,204.045 + ,200.237 + ,203.666 + ,241.476 + ,260.307 + ,243.324 + ,244.460 + ,233.575 + ,237.217 + ,235.243 + ,230.354 + ,227.184 + ,221.678 + ,217.142 + ,219.452 + ,256.446 + ,265.845 + ,248.624 + ,241.114 + ,229.245 + ,231.805 + ,219.277 + ,219.313 + ,212.610 + ,214.771 + ,211.142 + ,211.457 + ,240.048 + ,240.636 + ,230.580 + ,208.795 + ,197.922 + ,194.596 + ,194.581 + ,185.686 + ,178.106 + ,172.608 + ,167.302 + ,168.053 + ,202.300 + ,202.388 + ,182.516 + ,173.476 + ,166.444 + ,171.297) > par10 = 'FALSE' > par9 = '1' > par8 = '0' > par7 = '1' > par6 = '2' > par5 = '12' > par4 = '1' > 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.7751 0.1694 -0.8123 -0.4240 s.e. 0.0936 0.0728 0.0726 0.0809 sigma^2 estimated as 14.03: log likelihood = -623.09, aic = 1256.19 > (forecast <- predict(arima.out,fx)) $pred Time Series: Start = 241 End = 252 Frequency = 1 [1] 184.8127 179.9258 171.7290 168.1534 161.6763 160.5340 190.5196 193.7268 [9] 178.6876 161.7325 148.9339 146.4460 $se Time Series: Start = 241 End = 252 Frequency = 1 [1] 3.746102 5.200350 6.643154 8.034193 9.413643 10.789120 12.165296 [8] 13.543665 14.924450 16.307170 17.691006 19.074983 > (lb <- forecast$pred - 1.96 * forecast$se) Time Series: Start = 241 End = 252 Frequency = 1 [1] 177.4703 169.7331 158.7084 152.4064 143.2256 139.3873 166.6757 167.1812 [9] 149.4356 129.7704 114.2595 109.0591 > (ub <- forecast$pred + 1.96 * forecast$se) Time Series: Start = 241 End = 252 Frequency = 1 [1] 192.1551 190.1185 184.7496 183.9005 180.1271 181.6806 214.3636 220.2724 [9] 207.9395 193.6945 183.6082 183.8330 > 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] 267.8500 255.4680 246.7170 238.2760 229.3360 231.0470 264.4400 261.3080 [9] 257.8440 253.6870 248.2860 248.6410 243.7530 233.4950 222.3560 211.3330 [17] 202.4780 202.7460 238.8020 235.3850 224.8200 219.3860 213.1060 213.1660 [25] 208.2010 197.7750 189.1910 178.5430 171.8090 172.3650 204.1400 205.4670 [33] 193.0790 190.2240 185.5530 185.1840 183.0590 175.4960 168.1200 160.3740 [41] 155.2900 156.1520 189.7840 192.2500 184.8960 184.8350 180.1720 181.8750 [49] 182.4120 180.6270 174.3030 169.4310 163.9020 166.1140 198.4140 205.6260 [57] 199.3330 199.5880 196.5690 200.8800 201.5790 195.4830 190.6170 187.5760 [65] 183.9680 186.9980 216.6170 224.6920 222.4760 223.2470 225.6180 232.7580 [73] 235.8680 232.8630 227.5640 226.8220 223.8640 227.1550 260.3000 273.9440 [81] 270.7790 268.1040 268.7030 273.4130 275.5970 270.1110 262.2720 255.8230 [89] 250.7530 250.5120 277.8880 289.6940 281.3100 275.4250 271.2870 274.0590 [97] 274.1130 267.5460 257.6220 250.6120 243.8290 243.1800 275.3620 287.0270 [105] 279.1750 282.4160 275.4240 277.8620 284.9980 272.1820 258.6130 253.0460 [113] 243.3150 234.3120 265.9120 279.3840 262.5470 256.1020 251.1330 249.5980 [121] 251.5920 244.9760 237.5270 232.7900 224.7260 223.9180 252.6370 263.7360 [129] 251.1430 239.5300 232.4010 233.7490 232.0550 224.4730 215.8660 207.8080 [137] 199.4400 193.3300 222.7870 241.4340 221.2630 207.4480 200.2410 205.0090 [145] 206.2300 198.2530 194.6600 185.8470 180.3140 176.2820 203.5410 222.0420 [153] 197.5190 185.1420 176.3550 180.4480 180.1430 173.6660 165.6870 162.7190 [161] 157.0790 153.7300 182.6980 200.7650 176.5120 166.6180 158.6440 159.5850 [169] 163.0950 159.0440 155.5110 153.7450 150.5690 150.6050 179.6120 194.6900 [177] 189.9170 184.1280 175.3350 179.5660 181.1400 177.8760 175.0410 169.2920 [185] 166.0700 166.9720 206.3480 215.7060 202.1080 195.4110 193.1110 195.1980 [193] 198.7700 194.1630 190.4200 189.7330 186.0290 191.5310 232.5710 243.4770 [201] 227.2470 217.8590 208.6790 213.1880 216.2340 213.5870 209.4650 204.0450 [209] 200.2370 203.6660 241.4760 260.3070 243.3240 244.4600 233.5750 237.2170 [217] 235.2430 230.3540 227.1840 221.6780 217.1420 219.4520 256.4460 265.8450 [225] 248.6240 241.1140 229.2450 231.8050 219.2770 219.3130 212.6100 214.7710 [233] 211.1420 211.4570 240.0480 240.6360 230.5800 208.7950 197.9220 194.5960 [241] 184.8127 179.9258 171.7290 168.1534 161.6763 160.5340 190.5196 193.7268 [249] 178.6876 161.7325 148.9339 146.4460 > (perc.se <- (ub-forecast$pred)/1.96/forecast$pred) Time Series: Start = 241 End = 252 Frequency = 1 [1] 0.02026972 0.02890275 0.03868394 0.04777894 0.05822524 0.06720771 [7] 0.06385324 0.06991117 0.08352260 0.10082804 0.11878432 0.13025265 > postscript(file="/var/www/html/rcomp/tmp/14rg71228849995.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/25ag11228849995.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/3dq8w1228849995.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/4k6d61228849995.tab") > > system("convert tmp/14rg71228849995.ps tmp/14rg71228849995.png") > system("convert tmp/25ag11228849995.ps tmp/25ag11228849995.png") > > > proc.time() user system elapsed 4.174 0.555 4.304