2016-11-14 107 views
-1

我想在季節性環境中預測銷售額。在閱讀Quick-R的一些網頁後,我試圖預測我有的銷售額數據,但我不明白一些名詞(例如,滯後)。如何預測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

[SO]是一個Q&A自包含的,具體的*編碼*問題的網站。你需要的是學習時間序列分析和預測。這並不是真正的目標,在這個框架內實在太大了。 – gung

回答

0

通過探索季節性plot(stl(sales_ts, s.window = 12))庫添加

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

開始。我認爲季節性不強。

我其實得到一個單位根...?

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

也嘗試使用霍爾特溫特斯該款機型季節性?HoltWinters

又讀this

+0

我只是糾正了錯別字。我會按照你的建議。謝謝。 –