Forecasting weekly data using tbats

so this is my data data data starts on 26/07/2016 and ends on 10/03/2017 So 2 questions: is this correct? using tbats? for weekly seasonality? I also want the predicted data to look like the original data, but as shown which is none of my business, how can I do this? this is what i have and here's the code too

enter image description here

i ran these commands to finally get this using tbts prediction

      data.raw=read.csv(file=file.choose(),header=TRUE,sep=";",row.names=NULL)%>%
      mutate(date.re = as.POSIXct(date, format = "%d/%m/%Y"))
      complete.dates <- range(data.raw$date.re)
      dates.seq <- seq(complete.dates[1], complete.dates[2], by = "week")
      series <- data.frame(sale.week = week(dates.seq),sale.month =    month(dates.seq), sale.year = year(dates.seq))

      data.post <- data.raw %>%
      mutate(sale.week = week(date.re),sale.month = month(date.re),  sale.year = year(date.re)) %>%
      select(Quantite, sale.week,sale.month, sale.year) %>%
      group_by(sale.week,sale.month, sale.year) %>%
       summarize_all(funs(sum(.))) %>%
      right_join(series) %>%
      replace_na(list(Quantite = 0))

      data2=data.post[,4]
      sensor <- ts(data2,frequency=52)
      fit <- tbats(sensor)
      fc <- forecast(fit)
      plot(fc)

      

early

+3


source to share


1 answer


Do you correctly predict correctly and correctly. However, you are misrepresenting seasonality.

To get this in weekly seasonality, you most likely want to use

sensor <- ts(data2,frequency=7)

      

To understand this, you could read about it here. But it basically comes down to how many observations you have before it drops again that day. Therefore, if you have 7 days of data in each week of data, your frequency should be 7. If you only have 5 days of data for each week, your frequency should be 5.

One of the advantages of tbats is that you can have two seasons. You can specify both weekly and yearly seasonality by trying this:



library(forecast)
sensor <- msts(data2, seasonal.periods=c(7,365.25))

      

Another option is to use ARIMA. You can only use one seasonal period with ARIMA. You would like to use weekly. Using ARIMA will also allow you to include metrics such as holidays, where you expect to see unusually large or small sales. You can also use indicators a few days before the holidays if you expect them to differ from the usual trend.

I did a weekly seasonality and had best luck using ARIMA, mainly because you can include other covariates.

Other things you might want to consider is outlier validation. You can do this with the help tsoutliers()

which is also in the package forecast

. And sometimes you can get better results by transforming your data. So study this too.

You can read a little time series for more details. This is a great book with many examples in R.

0


source







All Articles