R version 2.9.0 (2009-04-17) Copyright (C) 2009 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(22.6,44.6,45.2,69,66,47,67.8,22.6,22.6,44.5,44.6,47,45.2,40.5,66,24.4,2.3,0,0,48,0,0,0,0,8,6,0,0,0,0.02,2,0,22,46.5,66,44,66,44,66,66,66,76,34,66,66,66,66,66,44,44,66,87.5,66.000,66,66,65.5,65.5,88,42,88,88,64,88,88,88,63,110,85,88,108,88.023,88,66,44.5,88.5,88,108,66,85,66,66,110,83,66,83,44,83,105) > par10 = '0.1' > par9 = '3' > par8 = 'B511crostonm' > par7 = 'dum' > par6 = '12' > par5 = 'ZZZ' > par4 = 'NA' > par3 = 'NA' > par2 = 'Croston' > par1 = 'Input box' > par10 <- '0.1' > par9 <- '3' > par8 <- 'B511crostonm' > par7 <- 'dum' > par6 <- '12' > par5 <- 'ZZZ' > par4 <- 'NA' > par3 <- 'NA' > par2 <- 'Croston' > par1 <- 'Input box' > #'GNU S' R Code compiled by R2WASP v. 1.0.44 () > #Author: Dr. Ian E. Holliday > #To cite this work: Ian E. Holliday, 2009, 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: > #Technical description: > if(par3!='NA') par3 <- as.numeric(par3) else par3 <- NA > if(par4!='NA') par4 <- as.numeric(par4) else par4 <- NA > par6 <- as.numeric(par6) #Seasonal Period > par9 <- as.numeric(par9) #Forecast Horizon > par10 <- as.numeric(par10) #Alpha > library(forecast) Loading required package: tseries Loading required package: quadprog Loading required package: zoo Attaching package: 'zoo' The following object(s) are masked from package:base : as.Date.numeric This is forecast 2.03 > if (par1 == 'CSV') { + xarr <- read.csv(file=paste('tmp/',par7,'.csv',sep=''),header=T) + numseries <- length(xarr[1,])-1 + n <- length(xarr[,1]) + nmh <- n - par9 + nmhp1 <- nmh + 1 + rarr <- array(NA,dim=c(n,numseries)) + farr <- array(NA,dim=c(n,numseries)) + parr <- array(NA,dim=c(numseries,8)) + colnames(parr) = list('ME','RMSE','MAE','MPE','MAPE','MASE','ACF1','TheilU') + for(i in 1:numseries) { + sindex <- i+1 + x <- xarr[,sindex] + if(par2=='Croston') { + if (i==1) m <- croston(x,alpha=par10) + if (i==1) mydemand <- m$model$demand[] + fit <- croston(x[1:nmh],h=par9,alpha=par10) + } + if(par2=='ARIMA') { + m <- auto.arima(ts(x,freq=par6),d=par3,D=par4) + mydemand <- forecast(m) + fit <- auto.arima(ts(x[1:nmh],freq=par6),d=par3,D=par4) + } + if(par2=='ETS') { + m <- ets(ts(x,freq=par6),model=par5) + mydemand <- forecast(m) + fit <- ets(ts(x[1:nmh],freq=par6),model=par5) + } + try(rarr[,i] <- mydemand$resid,silent=T) + try(farr[,i] <- mydemand$mean,silent=T) + if (par2!='Croston') parr[i,] <- accuracy(forecast(fit,par9),x[nmhp1:n]) + if (par2=='Croston') parr[i,] <- accuracy(fit,x[nmhp1:n]) + } + write.csv(farr,file=paste('tmp/',par8,'_f.csv',sep='')) + write.csv(rarr,file=paste('tmp/',par8,'_r.csv',sep='')) + write.csv(parr,file=paste('tmp/',par8,'_p.csv',sep='')) + } > if (par1 == 'Input box') { + numseries <- 1 + n <- length(x) + if(par2=='Croston') { + m <- croston(x) + mydemand <- m$model$demand[] + } + if(par2=='ARIMA') { + m <- auto.arima(ts(x,freq=par6),d=par3,D=par4) + mydemand <- forecast(m) + } + if(par2=='ETS') { + m <- ets(ts(x,freq=par6),model=par5) + mydemand <- forecast(m) + } + summary(m) + } Forecast method: Croston's method Model Information: $demand Point Forecast Lo 80 Hi 80 Lo 95 Hi 95 79 79.90736 54.26971 105.5450 40.69795 119.1168 80 79.90736 54.14184 105.6729 40.50239 119.3123 81 79.90736 54.01460 105.8001 40.30780 119.5069 82 79.90736 53.88798 105.9267 40.11415 119.7006 83 79.90736 53.76198 106.0527 39.92145 119.8933 84 79.90736 53.63658 106.1781 39.72967 120.0851 85 79.90736 53.51178 106.3029 39.53880 120.2759 86 79.90736 53.38756 106.4272 39.34883 120.4659 87 79.90736 53.26393 106.5508 39.15975 120.6550 88 79.90736 53.14086 106.6739 38.97153 120.8432 $period Point Forecast Lo 80 Hi 80 Lo 95 Hi 95 79 1.002202 0.2193573 1.785046 -0.1950556 2.199459 80 1.002202 0.2154528 1.788951 -0.2010270 2.205431 81 1.002202 0.2115676 1.792836 -0.2069689 2.211373 82 1.002202 0.2077014 1.796702 -0.2128817 2.217286 83 1.002202 0.2038539 1.800550 -0.2187659 2.223170 84 1.002202 0.2000249 1.804379 -0.2246219 2.229026 85 1.002202 0.1962141 1.808190 -0.2304501 2.234854 86 1.002202 0.1924212 1.811983 -0.2362508 2.240655 87 1.002202 0.1886460 1.815758 -0.2420246 2.246428 88 1.002202 0.1848882 1.819516 -0.2477716 2.252175 In-sample error measures: ME RMSE MAE MPE MAPE MASE 6.737944 23.984765 20.873665 -Inf Inf 1.302919 Forecasts: Point Forecast 89 79.7318 90 79.7318 91 79.7318 92 79.7318 93 79.7318 94 79.7318 95 79.7318 96 79.7318 97 79.7318 98 79.7318 > postscript(file="/var/www/html/rcomp/tmp/11sdc1272288435.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > op <- par(mfrow=c(2,1)) > if (par2=='Croston') plot(m) > if ((par2=='ARIMA') | par2=='ETS') plot(forecast(m)) > plot(mydemand$resid,type='l',main='Residuals', ylab='residual value', xlab='time') > par(op) > dev.off() null device 1 > postscript(file="/var/www/html/rcomp/tmp/2c1cf1272288435.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556) > op <- par(mfrow=c(2,2)) > acf(mydemand$resid, lag.max=n/3, main='Residual ACF', ylab='autocorrelation', xlab='time lag') > pacf(mydemand$resid,lag.max=n/3, main='Residual PACF', ylab='partial autocorrelation', xlab='time lag') > cpgram(mydemand$resid, main='Cumulative Periodogram of Residuals') > qqnorm(mydemand$resid); qqline(mydemand$resid, col=2) > par(op) > 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,'Demand Forecast',6,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'Point',header=TRUE) > a<-table.element(a,'Forecast',header=TRUE) > a<-table.element(a,'95% LB',header=TRUE) > a<-table.element(a,'80% LB',header=TRUE) > a<-table.element(a,'80% UB',header=TRUE) > a<-table.element(a,'95% UB',header=TRUE) > a<-table.row.end(a) > for (i in 1:length(mydemand$mean)) { + a<-table.row.start(a) + a<-table.element(a,i+n,header=TRUE) + a<-table.element(a,as.numeric(mydemand$mean[i])) + a<-table.element(a,as.numeric(mydemand$lower[i,2])) + a<-table.element(a,as.numeric(mydemand$lower[i,1])) + a<-table.element(a,as.numeric(mydemand$upper[i,1])) + a<-table.element(a,as.numeric(mydemand$upper[i,2])) + a<-table.row.end(a) + } > a<-table.end(a) > table.save(a,file="/var/www/html/rcomp/tmp/38tso1272288435.tab") > a<-table.start() > a<-table.row.start(a) > a<-table.element(a,'Actuals and Interpolation',3,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,'Time',header=TRUE) > a<-table.element(a,'Actual',header=TRUE) > a<-table.element(a,'Forecast',header=TRUE) > a<-table.row.end(a) > for (i in 1:n) { + a<-table.row.start(a) + a<-table.element(a,i,header=TRUE) + a<-table.element(a,x[i]) + a<-table.element(a,x[i] - as.numeric(m$resid[i])) + a<-table.row.end(a) + } > a<-table.end(a) > table.save(a,file="/var/www/html/rcomp/tmp/41kr91272288435.tab") > a<-table.start() > a<-table.row.start(a) > a<-table.element(a,'What is next?',1,TRUE) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,hyperlink(paste('http://www.wessa.net/Patrick.Wessa/rwasp_demand_forecasting_simulate.wasp',sep=''),'Simulate Time Series','',target='')) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,hyperlink(paste('http://www.wessa.net/Patrick.Wessa/rwasp_demand_forecasting_croston.wasp',sep=''),'Generate Forecasts','',target='')) > a<-table.row.end(a) > a<-table.row.start(a) > a<-table.element(a,hyperlink(paste('http://www.wessa.net/Patrick.Wessa/rwasp_demand_forecasting_analysis.wasp',sep=''),'Forecast Analysis','',target='')) > a<-table.row.end(a) > a<-table.end(a) > table.save(a,file="/var/www/html/rcomp/tmp/5m38f1272288435.tab") > try(system("convert tmp/11sdc1272288435.ps tmp/11sdc1272288435.png",intern=TRUE)) character(0) > try(system("convert tmp/2c1cf1272288435.ps tmp/2c1cf1272288435.png",intern=TRUE)) character(0) > > #-SERVER-wessa.org > > > > proc.time() user system elapsed 4.011 0.346 5.596