【问题标题】:How to forecast seasonal sales amount in R如何在R中预测季节性销售额
【发布时间】:2016-11-14 16:29:56
【问题描述】:

我想在季节性背景下预测销售额。在阅读了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

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

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

谢谢!

【问题讨论】:

  • Stack Overflow 是一个针对独立的具体编码问题的问答网站。你需要的是学习时间序列分析和预测。这并不是 SO 的真正用途,& 在这个框架内太大而无法做到。

标签: r forecasting


【解决方案1】:

添加库

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

【讨论】:

  • 我只是更正了错别字。我会听从你的建议。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-03
相关资源
最近更新 更多