次のように、頻度 = 7 の時系列データがあります。
combo_1_daily_mini <- read.table(header=TRUE, text="
region_1 region_2 region_3 date incidents
USA CA San Francisco 1/1/15 37
USA CA San Francisco 1/2/15 30
USA CA San Francisco 1/3/15 31
USA CA San Francisco 1/4/15 33
USA CA San Francisco 1/5/15 28
USA CA San Francisco 1/6/15 33
USA CA San Francisco 1/7/15 39
USA PA Pittsburg 1/1/15 38
USA PA Pittsburg 1/2/15 35
USA PA Pittsburg 1/3/15 37
USA PA Pittsburg 1/4/15 33
USA PA Pittsburg 1/5/15 30
USA PA Pittsburg 1/6/15 33
USA PA Pittsburg 1/7/15 25
Greece Macedonia Skopje 1/1/15 29
Greece Macedonia Skopje 1/2/15 37
Greece Macedonia Skopje 1/3/15 28
Greece Macedonia Skopje 1/4/15 38
Greece Macedonia Skopje 1/5/15 27
Greece Macedonia Skopje 1/6/15 38
Greece Macedonia Skopje 1/7/15 39
Italy Trentino Trento 1/1/15 35
Italy Trentino Trento 1/2/15 31
Italy Trentino Trento 1/3/15 34
Italy Trentino Trento 1/4/15 34
Italy Trentino Trento 1/5/15 26
Italy Trentino Trento 1/6/15 33
Italy Trentino Trento 1/7/15 27
", sep = "\t")
dput(trst, control = "all")
structure(list(region_1 = structure(c(3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Greece", "Italy", "USA"), class = "factor"),
region_2 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L,
4L, 4L, 4L, 4L), .Label = c("CA", "Macedonia", "PA", "Trentino"
), class = "factor"), region_3 = structure(c(2L, 2L, 2L,
2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("Pittsburg",
"San Francisco", "Skopje", "Trento"), class = "factor"),
date = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L,
5L, 6L, 7L), .Label = c("1/1/15", "1/2/15", "1/3/15", "1/4/15",
"1/5/15", "1/6/15", "1/7/15"), class = "factor"), incidents = c(37L,
30L, 31L, 33L, 28L, 33L, 39L, 38L, 35L, 37L, 33L, 30L, 33L,
25L, 29L, 37L, 28L, 38L, 27L, 38L, 39L, 35L, 31L, 34L, 34L,
26L, 33L, 27L)), .Names = c("region_1", "region_2", "region_3",
"date", "incidents"), class = "data.frame", row.names = c(NA,
-28L))
region_1、region_2、region_3 の各グループには、独自の季節性と傾向があります。
履歴データに基づいて、今後 1 週間のインシデント数を予測しようとしています。32 か国の 2015 年 1 月 1 日から 2015 年 6 月 30 日までの 6 か月分の履歴データがあります。そして、各国には多くの region_2 と region_3 があります。合計 32,356 個の一意の region_1、region_2、region_3 時系列があります。
2 つの質問/問題があります。
- 問題 - 私が直面している問題は、ホルト ウィンターズを by() 関数に適用すると、警告が表示され、それらを理解できないことです。それらを理解するための助けは非常に役に立ちます
以下は私のコードです:
ts_fun <- function(x){
ts_y <- ts(x, frequency = 7)
}
hw_fun <- function(x){
ts_y <- ts_fun(x)
ts_h <- HoltWinters(ts_y)
}
combo_1_daily_mini$region_1 <- as.factor(combo_1_daily_mini$region_1)
combo_1_daily_mini$region_2 <- as.factor(combo_1_daily_mini$region_2)
combo_1_daily_mini$region_3 <- as.factor(combo_1_daily_mini$region_3)
combo_1_ts <- by(combo_1_daily_mini,list(combo_1_daily_mini$region_1,
combo_1_daily_mini$region_2,
combo_1_daily_mini$region_3
),ts_fun)
combo_1_hw <- by(combo_1_daily_mini,list(combo_1_daily_mini$region_1,
combo_1_daily_mini$region_2,
combo_1_daily_mini$region_3
),hw_fun)
警告メッセージ:
1: In HoltWinters(ts_y) :
optimization difficulties: ERROR: ABNORMAL_TERMINATION_IN_LNSRCH
2: In HoltWinters(ts_y) :
optimization difficulties: ERROR: ABNORMAL_TERMINATION_IN_LNSRCH
3: In HoltWinters(ts_y) :
optimization difficulties: ERROR: ABNORMAL_TERMINATION_IN_LNSRCH
4: In HoltWinters(ts_y) :
optimization difficulties: ERROR: ABNORMAL_TERMINATION_IN_LNSRCH
質問 - 複数の列で関数を適用する方法は正しいですか? より良い方法はありますか?私は基本的に、地域 1、地域 2、地域 3 ごとに来週の予測数を取得しようとしています。次のコードを使用する予定です。
nw_forecast <- 予測(combo_1_hw,7)
region_1、region_2、region_3 の組み合わせごとに時系列データを作成すると、Holt Winters 関数を適用して予測することもできます。私のデータセットには 32,356 の一意の組み合わせがあるため、この方法は実行できません。
どんな助けでも大歓迎ですありがとう