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) 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) } bitmap(file='test1.png') 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() bitmap(file='pic2.png') 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() load(file='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='mytable.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('https://automated.biganalytics.eu/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('https://automated.biganalytics.eu/Patrick.Wessa/rwasp_demand_forecasting_croston.wasp#output',sep=''),'Generate Forecasts','',target='')) a<-table.row.end(a) a<-table.row.start(a) a<-table.element(a,hyperlink(paste('https://automated.biganalytics.eu/Patrick.Wessa/rwasp_demand_forecasting_analysis.wasp',sep=''),'Forecast Analysis','',target='')) a<-table.row.end(a) a<-table.end(a) table.save(a,file='mytable0.tab') -SERVER-wessa.org
|