R time series forecast is always the same











up vote
0
down vote

favorite












I have a lot of time series and i want a forecast for every single one for ten months. For some of them it works, for the most i always get the same forecast for every month.
The time series consists monthly data. For example:



> ts(Menge[Nummer==8 & Jahr>2014 & Index<61 ], frequency=12)
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1 6 225 0 114 21 25 5 256 1 6 1 8
2 13 35 180 215 20 48 20 31 283 130 3 1
3 53 31 0 142 60 76 10 28 298 29 5 14


The output of dput is:



dput(Menge[Nummer==8 & Jahr>2014 & Index<61 ])
c(6, 225, 0, 114, 21, 25, 5, 256, 1, 6, 1, 8, 13, 35, 180, 215,
20, 48, 20, 31, 283, 130, 3, 1, 53, 31, 0, 142, 60, 76, 10, 28,
298, 29, 5, 14)


When i decompose the time series i get seasonality and a trend:



> decompose(ts(Menge[Nummer==8 & Jahr>2014 & Index<61 ], frequency=12))
$x
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1 6 225 0 114 21 25 5 256 1 6 1 8
2 13 35 180 215 20 48 20 31 283 130 3 1
3 53 31 0 142 60 76 10 28 298 29 5 14

$seasonal
Jan Feb Mar Apr May Jun Jul Aug Sep Oct
1 -35.142361 -30.496528 25.065972 106.899306 -32.163194 -10.371528 -57.725694 76.336806 78.878472 4.295139
2 -35.142361 -30.496528 25.065972 106.899306 -32.163194 -10.371528 -57.725694 76.336806 78.878472 4.295139
3 -35.142361 -30.496528 25.065972 106.899306 -32.163194 -10.371528 -57.725694 76.336806 78.878472 4.295139
Nov Dec
1 -63.100694 -62.475694
2 -63.100694 -62.475694
3 -63.100694 -62.475694

$trend
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1 NA NA NA NA NA NA 55.95833 48.33333 47.91667 59.62500 63.79167 64.70833
2 66.29167 57.54167 59.91667 76.83333 82.08333 81.87500 83.25000 84.75000 77.08333 66.54167 65.16667 68.00000
3 68.75000 68.20833 68.70833 65.12500 61.00000 61.62500 NA NA NA NA NA NA

$random
Jan Feb Mar Apr May Jun Jul Aug
1 NA NA NA NA NA NA 6.7673611 131.3298611
2 -18.1493056 7.9548611 95.0173611 31.2673611 -29.9201389 -23.5034722 -5.5243056 -130.0868056
3 19.3923611 -6.7118056 -93.7743056 -30.0243056 31.1631944 24.7465278 NA NA
Sep Oct Nov Dec
1 -125.7951389 -57.9201389 0.3090278 5.7673611
2 127.0381944 59.1631944 0.9340278 -4.5243056
3 NA NA NA NA

$figure
[1] -35.142361 -30.496528 25.065972 106.899306 -32.163194 -10.371528 -57.725694 76.336806 78.878472 4.295139
[11] -63.100694 -62.475694

$type
[1] "additive"

attr(,"class")
[1] "decomposed.ts"


But the forecast is always the same:



     Point Forecast     Lo 80   Hi 80     Lo 95    Hi 95
Jan 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Feb 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Mar 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Apr 4 68.41899 -47.17701 184.015 -108.3698 245.2078
May 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Jun 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Jul 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Aug 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Sep 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Oct 4 68.41899 -47.17701 184.015 -108.3698 245.2078


The data are three years (2015-2017). The forecast should be for the first ten months of 2018 (so that i can prove how good is the fitting in reality).



I did about 1000 forecasts (by changing "number" i get another time series) and very often i just got the same values, sometimes the point forecast is the same, but the Lo and Hi values change a little bit, in some cases i get different values for every month.



I observed the data in some cases but can't find a reason, why in some cases the forecasts are the same and in other cases not. Especially because i get saisonality and trends by decomposing the time series.



The whole code is:



  setwd("Z:/Bestellvorschlag/Lagerdrehung") #workspace festlegen
x= read.csv("Daten Aufbereitet.csv", header=TRUE, sep=";") #read the data
attach(x)
library(forecast)
Zeilenanzahl<-length(x[,1]) #number of rows
AnzahlArtikel<-x[Zeilenanzahl,1] #number of articles
ForecastMatrix<-matrix(0,9*AnzahlArtikel,8) #i want nine forecasts for every article
#with the columns Nummer, Monat,Forecast, lower80, lower 95, upper 80, upper 95, Menge



for (i in 1:AnzahlArtikel) { #do it for all numbers; each number is another product

#extract mean(point forecast), lower und upper bounds
TS<- ts(Menge[Nummer==i & Jahr>2014 & Index<61 ], frequency=12)
mean<-unlist(forecast(TS,9)[2])
upper<-unlist(forecast(TS,9)[5])
lower<-unlist(forecast(TS,9)[6])

#write the data in a matrix
for (j in 1:9) {
ForecastMatrix[9*(i-1)+j,1]<-i
ForecastMatrix[9*(i-1)+j,2]<-j
ForecastMatrix[9*(i-1)+j,3]<-mean[j]
ForecastMatrix[9*(i-1)+j,4]<-lower[j]
ForecastMatrix[9*(i-1)+j,5]<-lower[9+j]
ForecastMatrix[9*(i-1)+j,6]<-upper[j]
ForecastMatrix[9*(i-1)+j,7]<-upper[9+j]
ForecastMatrix[9*(i-1)+j,8]<-Menge[Nummer==i & Jahr==2018 & Monat==j] #the real value
}
}
#write the data in a .csv
write.table(ForecastMatrix, file = "Forecastmatrix.csv", sep= ";")









share|improve this question









New contributor




Flo Geys is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Please, post the output of dput(Menge[Nummer==8 & Jahr>2014 & Index<61 ]) in the question. And also post the code you are running to model and forecast.
    – Rui Barradas
    2 days ago















up vote
0
down vote

favorite












I have a lot of time series and i want a forecast for every single one for ten months. For some of them it works, for the most i always get the same forecast for every month.
The time series consists monthly data. For example:



> ts(Menge[Nummer==8 & Jahr>2014 & Index<61 ], frequency=12)
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1 6 225 0 114 21 25 5 256 1 6 1 8
2 13 35 180 215 20 48 20 31 283 130 3 1
3 53 31 0 142 60 76 10 28 298 29 5 14


The output of dput is:



dput(Menge[Nummer==8 & Jahr>2014 & Index<61 ])
c(6, 225, 0, 114, 21, 25, 5, 256, 1, 6, 1, 8, 13, 35, 180, 215,
20, 48, 20, 31, 283, 130, 3, 1, 53, 31, 0, 142, 60, 76, 10, 28,
298, 29, 5, 14)


When i decompose the time series i get seasonality and a trend:



> decompose(ts(Menge[Nummer==8 & Jahr>2014 & Index<61 ], frequency=12))
$x
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1 6 225 0 114 21 25 5 256 1 6 1 8
2 13 35 180 215 20 48 20 31 283 130 3 1
3 53 31 0 142 60 76 10 28 298 29 5 14

$seasonal
Jan Feb Mar Apr May Jun Jul Aug Sep Oct
1 -35.142361 -30.496528 25.065972 106.899306 -32.163194 -10.371528 -57.725694 76.336806 78.878472 4.295139
2 -35.142361 -30.496528 25.065972 106.899306 -32.163194 -10.371528 -57.725694 76.336806 78.878472 4.295139
3 -35.142361 -30.496528 25.065972 106.899306 -32.163194 -10.371528 -57.725694 76.336806 78.878472 4.295139
Nov Dec
1 -63.100694 -62.475694
2 -63.100694 -62.475694
3 -63.100694 -62.475694

$trend
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1 NA NA NA NA NA NA 55.95833 48.33333 47.91667 59.62500 63.79167 64.70833
2 66.29167 57.54167 59.91667 76.83333 82.08333 81.87500 83.25000 84.75000 77.08333 66.54167 65.16667 68.00000
3 68.75000 68.20833 68.70833 65.12500 61.00000 61.62500 NA NA NA NA NA NA

$random
Jan Feb Mar Apr May Jun Jul Aug
1 NA NA NA NA NA NA 6.7673611 131.3298611
2 -18.1493056 7.9548611 95.0173611 31.2673611 -29.9201389 -23.5034722 -5.5243056 -130.0868056
3 19.3923611 -6.7118056 -93.7743056 -30.0243056 31.1631944 24.7465278 NA NA
Sep Oct Nov Dec
1 -125.7951389 -57.9201389 0.3090278 5.7673611
2 127.0381944 59.1631944 0.9340278 -4.5243056
3 NA NA NA NA

$figure
[1] -35.142361 -30.496528 25.065972 106.899306 -32.163194 -10.371528 -57.725694 76.336806 78.878472 4.295139
[11] -63.100694 -62.475694

$type
[1] "additive"

attr(,"class")
[1] "decomposed.ts"


But the forecast is always the same:



     Point Forecast     Lo 80   Hi 80     Lo 95    Hi 95
Jan 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Feb 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Mar 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Apr 4 68.41899 -47.17701 184.015 -108.3698 245.2078
May 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Jun 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Jul 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Aug 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Sep 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Oct 4 68.41899 -47.17701 184.015 -108.3698 245.2078


The data are three years (2015-2017). The forecast should be for the first ten months of 2018 (so that i can prove how good is the fitting in reality).



I did about 1000 forecasts (by changing "number" i get another time series) and very often i just got the same values, sometimes the point forecast is the same, but the Lo and Hi values change a little bit, in some cases i get different values for every month.



I observed the data in some cases but can't find a reason, why in some cases the forecasts are the same and in other cases not. Especially because i get saisonality and trends by decomposing the time series.



The whole code is:



  setwd("Z:/Bestellvorschlag/Lagerdrehung") #workspace festlegen
x= read.csv("Daten Aufbereitet.csv", header=TRUE, sep=";") #read the data
attach(x)
library(forecast)
Zeilenanzahl<-length(x[,1]) #number of rows
AnzahlArtikel<-x[Zeilenanzahl,1] #number of articles
ForecastMatrix<-matrix(0,9*AnzahlArtikel,8) #i want nine forecasts for every article
#with the columns Nummer, Monat,Forecast, lower80, lower 95, upper 80, upper 95, Menge



for (i in 1:AnzahlArtikel) { #do it for all numbers; each number is another product

#extract mean(point forecast), lower und upper bounds
TS<- ts(Menge[Nummer==i & Jahr>2014 & Index<61 ], frequency=12)
mean<-unlist(forecast(TS,9)[2])
upper<-unlist(forecast(TS,9)[5])
lower<-unlist(forecast(TS,9)[6])

#write the data in a matrix
for (j in 1:9) {
ForecastMatrix[9*(i-1)+j,1]<-i
ForecastMatrix[9*(i-1)+j,2]<-j
ForecastMatrix[9*(i-1)+j,3]<-mean[j]
ForecastMatrix[9*(i-1)+j,4]<-lower[j]
ForecastMatrix[9*(i-1)+j,5]<-lower[9+j]
ForecastMatrix[9*(i-1)+j,6]<-upper[j]
ForecastMatrix[9*(i-1)+j,7]<-upper[9+j]
ForecastMatrix[9*(i-1)+j,8]<-Menge[Nummer==i & Jahr==2018 & Monat==j] #the real value
}
}
#write the data in a .csv
write.table(ForecastMatrix, file = "Forecastmatrix.csv", sep= ";")









share|improve this question









New contributor




Flo Geys is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Please, post the output of dput(Menge[Nummer==8 & Jahr>2014 & Index<61 ]) in the question. And also post the code you are running to model and forecast.
    – Rui Barradas
    2 days ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a lot of time series and i want a forecast for every single one for ten months. For some of them it works, for the most i always get the same forecast for every month.
The time series consists monthly data. For example:



> ts(Menge[Nummer==8 & Jahr>2014 & Index<61 ], frequency=12)
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1 6 225 0 114 21 25 5 256 1 6 1 8
2 13 35 180 215 20 48 20 31 283 130 3 1
3 53 31 0 142 60 76 10 28 298 29 5 14


The output of dput is:



dput(Menge[Nummer==8 & Jahr>2014 & Index<61 ])
c(6, 225, 0, 114, 21, 25, 5, 256, 1, 6, 1, 8, 13, 35, 180, 215,
20, 48, 20, 31, 283, 130, 3, 1, 53, 31, 0, 142, 60, 76, 10, 28,
298, 29, 5, 14)


When i decompose the time series i get seasonality and a trend:



> decompose(ts(Menge[Nummer==8 & Jahr>2014 & Index<61 ], frequency=12))
$x
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1 6 225 0 114 21 25 5 256 1 6 1 8
2 13 35 180 215 20 48 20 31 283 130 3 1
3 53 31 0 142 60 76 10 28 298 29 5 14

$seasonal
Jan Feb Mar Apr May Jun Jul Aug Sep Oct
1 -35.142361 -30.496528 25.065972 106.899306 -32.163194 -10.371528 -57.725694 76.336806 78.878472 4.295139
2 -35.142361 -30.496528 25.065972 106.899306 -32.163194 -10.371528 -57.725694 76.336806 78.878472 4.295139
3 -35.142361 -30.496528 25.065972 106.899306 -32.163194 -10.371528 -57.725694 76.336806 78.878472 4.295139
Nov Dec
1 -63.100694 -62.475694
2 -63.100694 -62.475694
3 -63.100694 -62.475694

$trend
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1 NA NA NA NA NA NA 55.95833 48.33333 47.91667 59.62500 63.79167 64.70833
2 66.29167 57.54167 59.91667 76.83333 82.08333 81.87500 83.25000 84.75000 77.08333 66.54167 65.16667 68.00000
3 68.75000 68.20833 68.70833 65.12500 61.00000 61.62500 NA NA NA NA NA NA

$random
Jan Feb Mar Apr May Jun Jul Aug
1 NA NA NA NA NA NA 6.7673611 131.3298611
2 -18.1493056 7.9548611 95.0173611 31.2673611 -29.9201389 -23.5034722 -5.5243056 -130.0868056
3 19.3923611 -6.7118056 -93.7743056 -30.0243056 31.1631944 24.7465278 NA NA
Sep Oct Nov Dec
1 -125.7951389 -57.9201389 0.3090278 5.7673611
2 127.0381944 59.1631944 0.9340278 -4.5243056
3 NA NA NA NA

$figure
[1] -35.142361 -30.496528 25.065972 106.899306 -32.163194 -10.371528 -57.725694 76.336806 78.878472 4.295139
[11] -63.100694 -62.475694

$type
[1] "additive"

attr(,"class")
[1] "decomposed.ts"


But the forecast is always the same:



     Point Forecast     Lo 80   Hi 80     Lo 95    Hi 95
Jan 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Feb 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Mar 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Apr 4 68.41899 -47.17701 184.015 -108.3698 245.2078
May 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Jun 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Jul 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Aug 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Sep 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Oct 4 68.41899 -47.17701 184.015 -108.3698 245.2078


The data are three years (2015-2017). The forecast should be for the first ten months of 2018 (so that i can prove how good is the fitting in reality).



I did about 1000 forecasts (by changing "number" i get another time series) and very often i just got the same values, sometimes the point forecast is the same, but the Lo and Hi values change a little bit, in some cases i get different values for every month.



I observed the data in some cases but can't find a reason, why in some cases the forecasts are the same and in other cases not. Especially because i get saisonality and trends by decomposing the time series.



The whole code is:



  setwd("Z:/Bestellvorschlag/Lagerdrehung") #workspace festlegen
x= read.csv("Daten Aufbereitet.csv", header=TRUE, sep=";") #read the data
attach(x)
library(forecast)
Zeilenanzahl<-length(x[,1]) #number of rows
AnzahlArtikel<-x[Zeilenanzahl,1] #number of articles
ForecastMatrix<-matrix(0,9*AnzahlArtikel,8) #i want nine forecasts for every article
#with the columns Nummer, Monat,Forecast, lower80, lower 95, upper 80, upper 95, Menge



for (i in 1:AnzahlArtikel) { #do it for all numbers; each number is another product

#extract mean(point forecast), lower und upper bounds
TS<- ts(Menge[Nummer==i & Jahr>2014 & Index<61 ], frequency=12)
mean<-unlist(forecast(TS,9)[2])
upper<-unlist(forecast(TS,9)[5])
lower<-unlist(forecast(TS,9)[6])

#write the data in a matrix
for (j in 1:9) {
ForecastMatrix[9*(i-1)+j,1]<-i
ForecastMatrix[9*(i-1)+j,2]<-j
ForecastMatrix[9*(i-1)+j,3]<-mean[j]
ForecastMatrix[9*(i-1)+j,4]<-lower[j]
ForecastMatrix[9*(i-1)+j,5]<-lower[9+j]
ForecastMatrix[9*(i-1)+j,6]<-upper[j]
ForecastMatrix[9*(i-1)+j,7]<-upper[9+j]
ForecastMatrix[9*(i-1)+j,8]<-Menge[Nummer==i & Jahr==2018 & Monat==j] #the real value
}
}
#write the data in a .csv
write.table(ForecastMatrix, file = "Forecastmatrix.csv", sep= ";")









share|improve this question









New contributor




Flo Geys is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have a lot of time series and i want a forecast for every single one for ten months. For some of them it works, for the most i always get the same forecast for every month.
The time series consists monthly data. For example:



> ts(Menge[Nummer==8 & Jahr>2014 & Index<61 ], frequency=12)
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1 6 225 0 114 21 25 5 256 1 6 1 8
2 13 35 180 215 20 48 20 31 283 130 3 1
3 53 31 0 142 60 76 10 28 298 29 5 14


The output of dput is:



dput(Menge[Nummer==8 & Jahr>2014 & Index<61 ])
c(6, 225, 0, 114, 21, 25, 5, 256, 1, 6, 1, 8, 13, 35, 180, 215,
20, 48, 20, 31, 283, 130, 3, 1, 53, 31, 0, 142, 60, 76, 10, 28,
298, 29, 5, 14)


When i decompose the time series i get seasonality and a trend:



> decompose(ts(Menge[Nummer==8 & Jahr>2014 & Index<61 ], frequency=12))
$x
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1 6 225 0 114 21 25 5 256 1 6 1 8
2 13 35 180 215 20 48 20 31 283 130 3 1
3 53 31 0 142 60 76 10 28 298 29 5 14

$seasonal
Jan Feb Mar Apr May Jun Jul Aug Sep Oct
1 -35.142361 -30.496528 25.065972 106.899306 -32.163194 -10.371528 -57.725694 76.336806 78.878472 4.295139
2 -35.142361 -30.496528 25.065972 106.899306 -32.163194 -10.371528 -57.725694 76.336806 78.878472 4.295139
3 -35.142361 -30.496528 25.065972 106.899306 -32.163194 -10.371528 -57.725694 76.336806 78.878472 4.295139
Nov Dec
1 -63.100694 -62.475694
2 -63.100694 -62.475694
3 -63.100694 -62.475694

$trend
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1 NA NA NA NA NA NA 55.95833 48.33333 47.91667 59.62500 63.79167 64.70833
2 66.29167 57.54167 59.91667 76.83333 82.08333 81.87500 83.25000 84.75000 77.08333 66.54167 65.16667 68.00000
3 68.75000 68.20833 68.70833 65.12500 61.00000 61.62500 NA NA NA NA NA NA

$random
Jan Feb Mar Apr May Jun Jul Aug
1 NA NA NA NA NA NA 6.7673611 131.3298611
2 -18.1493056 7.9548611 95.0173611 31.2673611 -29.9201389 -23.5034722 -5.5243056 -130.0868056
3 19.3923611 -6.7118056 -93.7743056 -30.0243056 31.1631944 24.7465278 NA NA
Sep Oct Nov Dec
1 -125.7951389 -57.9201389 0.3090278 5.7673611
2 127.0381944 59.1631944 0.9340278 -4.5243056
3 NA NA NA NA

$figure
[1] -35.142361 -30.496528 25.065972 106.899306 -32.163194 -10.371528 -57.725694 76.336806 78.878472 4.295139
[11] -63.100694 -62.475694

$type
[1] "additive"

attr(,"class")
[1] "decomposed.ts"


But the forecast is always the same:



     Point Forecast     Lo 80   Hi 80     Lo 95    Hi 95
Jan 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Feb 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Mar 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Apr 4 68.41899 -47.17701 184.015 -108.3698 245.2078
May 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Jun 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Jul 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Aug 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Sep 4 68.41899 -47.17701 184.015 -108.3698 245.2078
Oct 4 68.41899 -47.17701 184.015 -108.3698 245.2078


The data are three years (2015-2017). The forecast should be for the first ten months of 2018 (so that i can prove how good is the fitting in reality).



I did about 1000 forecasts (by changing "number" i get another time series) and very often i just got the same values, sometimes the point forecast is the same, but the Lo and Hi values change a little bit, in some cases i get different values for every month.



I observed the data in some cases but can't find a reason, why in some cases the forecasts are the same and in other cases not. Especially because i get saisonality and trends by decomposing the time series.



The whole code is:



  setwd("Z:/Bestellvorschlag/Lagerdrehung") #workspace festlegen
x= read.csv("Daten Aufbereitet.csv", header=TRUE, sep=";") #read the data
attach(x)
library(forecast)
Zeilenanzahl<-length(x[,1]) #number of rows
AnzahlArtikel<-x[Zeilenanzahl,1] #number of articles
ForecastMatrix<-matrix(0,9*AnzahlArtikel,8) #i want nine forecasts for every article
#with the columns Nummer, Monat,Forecast, lower80, lower 95, upper 80, upper 95, Menge



for (i in 1:AnzahlArtikel) { #do it for all numbers; each number is another product

#extract mean(point forecast), lower und upper bounds
TS<- ts(Menge[Nummer==i & Jahr>2014 & Index<61 ], frequency=12)
mean<-unlist(forecast(TS,9)[2])
upper<-unlist(forecast(TS,9)[5])
lower<-unlist(forecast(TS,9)[6])

#write the data in a matrix
for (j in 1:9) {
ForecastMatrix[9*(i-1)+j,1]<-i
ForecastMatrix[9*(i-1)+j,2]<-j
ForecastMatrix[9*(i-1)+j,3]<-mean[j]
ForecastMatrix[9*(i-1)+j,4]<-lower[j]
ForecastMatrix[9*(i-1)+j,5]<-lower[9+j]
ForecastMatrix[9*(i-1)+j,6]<-upper[j]
ForecastMatrix[9*(i-1)+j,7]<-upper[9+j]
ForecastMatrix[9*(i-1)+j,8]<-Menge[Nummer==i & Jahr==2018 & Monat==j] #the real value
}
}
#write the data in a .csv
write.table(ForecastMatrix, file = "Forecastmatrix.csv", sep= ";")






r forecasting






share|improve this question









New contributor




Flo Geys is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Flo Geys is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago





















New contributor




Flo Geys is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Flo Geys

11




11




New contributor




Flo Geys is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Flo Geys is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Flo Geys is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Please, post the output of dput(Menge[Nummer==8 & Jahr>2014 & Index<61 ]) in the question. And also post the code you are running to model and forecast.
    – Rui Barradas
    2 days ago


















  • Please, post the output of dput(Menge[Nummer==8 & Jahr>2014 & Index<61 ]) in the question. And also post the code you are running to model and forecast.
    – Rui Barradas
    2 days ago
















Please, post the output of dput(Menge[Nummer==8 & Jahr>2014 & Index<61 ]) in the question. And also post the code you are running to model and forecast.
– Rui Barradas
2 days ago




Please, post the output of dput(Menge[Nummer==8 & Jahr>2014 & Index<61 ]) in the question. And also post the code you are running to model and forecast.
– Rui Barradas
2 days ago

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Flo Geys is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372881%2fr-time-series-forecast-is-always-the-same%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








Flo Geys is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Flo Geys is a new contributor. Be nice, and check out our Code of Conduct.













Flo Geys is a new contributor. Be nice, and check out our Code of Conduct.












Flo Geys is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372881%2fr-time-series-forecast-is-always-the-same%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

ts Property 'filter' does not exist on type '{}'

mat-slide-toggle shouldn't change it's state when I click cancel in confirmation window