如何预测R中的季节性销售额

时间:2016-11-14 16:29:57

标签: r forecasting

我想在季节性环境中预测销售额。在阅读了Quick-R的一些网页后,我试图预测我的销售额数据,但我不理解某些名词(例如滞后)。

以下是一些代码:

# load library
library(dplyr)
library(lubridate)
library(forecast)

# fake data

set.seed(4)
amount_2014 <- c(sample(3000:3500, 6), sample(4000:5000, 6))
set.seed(5)
amount_2015 <- c(sample(3000:3500, 6), sample(4000:5000, 6))
set.seed(6)
amount_2016 <- c(sample(3000:3500, 6), sample(4000:5000, 4))

sales <- data.frame(year = c(rep(2014, 12), rep(2014, 12), rep(2016, 10)),
                    month = c(1:12, 1:12, 1:10),
                    amount = c(amount_2014, amount_2015, amount_2016))

sales <- sales %>% mutate(Month = ymd(paste(year, month), truncated =2)) %>%
  arrange(Month)

sales_ts <- ts(sales$amount, start = c(sales$year[1], sales$month[1]),
               frequency = 12)

# first try
sales_ts_fc_1 <- forecast(sales_ts, h = 13)
sales_ts_fc_1  # the forecast for every month is same


# then try
auto.arima(sales_ts)
sales_ts_arima <- arima(sales_ts, order = c(0, 1, 0))
sales_ts_fc_2 <- forecast.Arima(sales_ts_arima, h = 13)
sales_ts_fc_2 # the forecst for evey month is very close

两次尝试都失败了,因为预测的销售额不是季节性的。

如何预测这样的季节性数据?

谢谢!

1 个答案:

答案 0 :(得分:0)

添加库

library(dplyr)
library(lubridate)
library(forecast)

首先探索季节性plot(stl(sales_ts, s.window = 12))。我认为季节性不强。

我实际上得到了一个单位根...?

> auto.arima(sales_ts)
Series: sales_ts 
ARIMA(0,1,0)  

还尝试使用Holt Winters来模拟季节性?HoltWinters

另请阅读this