I perform forecast and need get any plots
Here my code
dput()
timeseries=structure(list(date = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("01.01.2018",
"02.01.2018", "03.01.2018"), class = "factor"), racket = c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 0L), shuttlecock = c(2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 2L, 5L, 5L, 2L, 2L, 5L, 2L, 5L, 5L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 5L,
2L, 2L, 2L, 2L, 5L, 2L, 2L, 2L, 2L, 5L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 10L), price = c(14.88, 14.88, 14.88,
14.88, 14.88, 14.88, 14.88, 14.88, 14.88, 14.88, 12.9, 12.9,
12.9, 12.9, 12.9, 12.9, 12.9, 12.9, 12.9, 12.9, 12.9, 12.9, 12.9,
14.88, 17.85, 17.85, 14.88, 14.88, 17.85, 14.88, 17.85, 17.85,
14.88, 14.88, 14.88, 14.88, 14.88, 14.88, 14.88, 14.88, 14.88,
14.88, 14.88, 14.88, 14.88, 14.88, 14.88, 14.88, 14.88, 14.88,
14.88, 14.88, 12.9, 12.9, 12.9, 12.9, 12.9, 12.9, 12.9, 12.9,
12.9, 12.9, 17.85, 14.88, 14.88, 14.88, 14.88, 17.85, 14.88,
14.88, 14.88, 14.88, 17.85, 14.88, 14.88, 14.88, 14.88, 14.88,
14.88, 14.88, 14.88, 14.88, 14.88, 14.88, 14.88, 12.9)), .Names = c("date",
"racket", "shuttlecock", "price"), class = "data.frame", row.names = c(NA,
-86L))
and my script
#split analysis on groups
group_list <- split(timeseries, list(timeseries$racket, timeseries$shuttlecock))
group_list <- group_list[sapply(group_list, function(x) nrow(x) != 0)]
#create forecast
fun_msts <- function(timeseries){
msts(timeseries$price, seasonal.periods = c(7,365.25), start = decimal_date(as.Date("2018-01-01")))
}
'#forecast
fun_sp <- function(m){
tbats <- tbats(m)
predict(tbats, h=14) #14 days forecast
}'
msts_list <- lapply(group_list, fun_msts)
#sp_list <- lapply(msts_list, fun_sp)
listed_arima <- lapply(msts_list,function(x) auto.arima(x,allowmean = F ))
#Now the forecast for each arima:
listed_forecast <- lapply(listed_arima,function(x) forecast(x,5) )
listed_forecast
#If you need to flat it down to a data.frame, do.call and rbind help:
do.call(rbind,listed_forecast)
#get initial values
lapply(listed_arima, fitted)
How can i get three plots?
The first :
red line it is number when buy 1 racket and 10 shuttlecocks
green line when buy 1 racket and 5 shuttlecocks
blue when buy just buy only 10 shuttlecocks
example (every day during one year)
The second plot
total price for
red line it is for 1 racket and 10 shuttlecocks
green line for 1 racket and 5 shuttlecocks
blue for 10 shuttlecocks
example (every day during one year)
the third plot it is forecast.
I get initial value for january
here string for it
#get initial values
lapply(listed_arima, fitted)
where
for each group, the forecast lines for January simultaneously coincide with the real values for January.
Can anybody help me please