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(429.75,247.325,395.15,293.905,299.125,211.375,275.25,253.25,250.5,285.8,276,300.75,309.25,309.25,336.25,331.25,331.25,308.75,230.725,330.5,224.5,197.125,306.25,235.125,322.25,280.625,232.25,317.75,317.75,232.25,319.5,265.25,203.5,168.85,295.75,312.2,335.25,261.5,305.75,230,230,247.25,276.25,356.3,320.5,188.5,372.75,296,329.5,376.53,281.5,390,0,203.25,337,214.775,270,280,309.25,347,214.575,213.62,231.75,224.3,278,226.525,360.302,263.25,263.75,269.775,283.25,286.75,230.25,200.5,297.95,329.5,289.75,223.775,281.78,265.8,256.75,89.275,225.5,124.25) > par10 = '0.1' > par9 = '1' > par8 = 'dumresult' > par7 = '' > par6 = '1' > par5 = 'ZZZ' > par4 = 'NA' > par3 = 'NA' > par2 = 'Croston' > par1 = 'Input box' > par10 <- '0.1' > par9 <- '1' > par8 <- 'dumresult' > par7 <- '' > par6 <- '1' > 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 84 236.2511 155.5303 316.9720 112.7992 359.7030 85 236.2511 155.1277 317.3746 112.1835 360.3188 86 236.2511 154.7271 317.7752 111.5708 360.9314 87 236.2511 154.3284 318.1739 110.9611 361.5411 88 236.2511 153.9317 318.5706 110.3544 362.1479 89 236.2511 153.5369 318.9654 109.7506 362.7517 90 236.2511 153.1439 319.3583 109.1496 363.3526 91 236.2511 152.7528 319.7494 108.5515 363.9508 92 236.2511 152.3636 320.1387 107.9562 364.5461 93 236.2511 151.9761 320.5262 107.3636 365.1387 $period Point Forecast Lo 80 Hi 80 Lo 95 Hi 95 84 1.004239 0.8581534 1.150325 0.7808203 1.227658 85 1.004239 0.8574248 1.151053 0.7797060 1.228772 86 1.004239 0.8566998 1.151778 0.7785972 1.229881 87 1.004239 0.8559783 1.152500 0.7774938 1.230984 88 1.004239 0.8552603 1.153218 0.7763957 1.232082 89 1.004239 0.8545458 1.153932 0.7753030 1.233175 90 1.004239 0.8538347 1.154644 0.7742154 1.234263 91 1.004239 0.8531269 1.155351 0.7731329 1.235345 92 1.004239 0.8524224 1.156056 0.7720555 1.236423 93 1.004239 0.8517212 1.156757 0.7709830 1.237495 In-sample error measures: ME RMSE MAE MPE MAPE MASE -23.884478 74.146049 54.816610 -Inf Inf 0.853365 Forecasts: Point Forecast 85 235.2539 86 235.2539 87 235.2539 88 235.2539 89 235.2539 90 235.2539 91 235.2539 92 235.2539 93 235.2539 94 235.2539 > postscript(file="/var/www/html/rcomp/tmp/1itmk1270549863.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/2itmk1270549863.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/3e32b1270549863.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/46c1d1270549863.tab") > try(system("convert tmp/1itmk1270549863.ps tmp/1itmk1270549863.png",intern=TRUE)) character(0) > try(system("convert tmp/2itmk1270549863.ps tmp/2itmk1270549863.png",intern=TRUE)) character(0) > > #-SERVER-wessa.org > > > > proc.time() user system elapsed 3.800 0.374 3.973