0

Consider the following code:

library(forecast)
library(lubridate)

# Create random walk with growing tendency and decreasing tendency after 182 days
a <- c(rnorm(182, 0, 100), rnorm(204, 0, 100))
b <- c(seq(1000, 3000, length.out = 182), seq(3000, 1000, length.out = 204))
y <- a + b
date <- seq(as.Date('2019-01-01'), as.Date('2020-01-21'), by='day')
data <- data.frame(date = date, y = y)

# Plot data
ggplot()+
  geom_line(data = data, aes(x = date, y = y))

# I want to consider yearly and weekly seasonal periods
datats <- msts(data$y, seasonal.periods = c(365.25, 7), start = decimal_date(as.Date(date[1])))

# Create arima model with seasonal differences
model <- auto.arima(datats, max.d = 1, D = 1, seasonal.test = 'ch')

# Plot forecast
plot(forecast(model, 100))

The prediction of this model is really bad. I would like a prediction which decreases as the recent days, but at the same time it takes into account the anual seasonality. I don't know how to do this, because it seems that the model don't keep the tendency. Obviously, this artificial data has an exaggerated peak. But what happens if I have a data that has a growing tendency, and then it decreases? Will I be able to keep the recent tendency and consider the year seasonality as well?

Thank you very much.

kjetil b halvorsen
  • 63,378
  • 26
  • 142
  • 467
Robert Sun
  • 21
  • 2
  • 1
    You might want to check out the prophet package (https://cran.r-project.org/web/packages/prophet/index.html). It allows forecasting with seasonal or once-a-year holiday effects. – Kevin Troy Mar 20 '20 at 15:36
  • 1
    also see https://stats.stackexchange.com/questions/417144/is-prophet-from-facebook-any-different-from-a-linear-regression/417156#417156 for a discussion of prophet assumptions – IrishStat Mar 20 '20 at 23:55
  • 1
    You can't estimate yearly seasonality with only one year of data unless you make some very strong assumptions. – Rob Hyndman Mar 21 '20 at 07:28

0 Answers0