0
我對R完全陌生,剛開始使用它。我有三年的每週數據。我想將此時間序列數據分解爲趨勢,季節和其他組件。我有以下疑惑:每週數據的時間序列分解
- 哪些功能我應該使用 -
ts()
或decompose()
- 如何處理閏年的情況。
請糾正我,如果我錯了,頻率爲提前52
感謝。我非常感謝任何幫助。
我對R完全陌生,剛開始使用它。我有三年的每週數據。我想將此時間序列數據分解爲趨勢,季節和其他組件。我有以下疑惑:每週數據的時間序列分解
ts()
或decompose()
請糾正我,如果我錯了,頻率爲提前52
感謝。我非常感謝任何幫助。
歡迎來到R!
是,頻率爲52
如果數據尚未歸類爲時間序列,則需要兩個ts()
和decompose()
。要找到數據集的類別,請使用class(data)
。如果它返回"ts"
,則就R而言,您的數據已經是時間序列。如果它返回其他內容,如"data.frame"
,則需要將其更改爲時間序列。指定一個變量爲ts(data)
並再次檢查課程以確保。
有一個每月的時間序列數據集sunspot.month
已經加載到R,你可以練習。這是一個例子。您也可以通過寫?decompose
class(sunspot.month)
[1] "ts"
> decomp <- decompose(sunspot.month)
> summary(decomp)
Length Class Mode
x 2988 ts numeric
seasonal 2988 ts numeric
trend 2988 ts numeric
random 2988 ts numeric
figure 12 -none- numeric
type 1 -none- character
> names(decomp)
[1] "x" "seasonal" "trend" "random" "figure" "type"
> plot(decomp) # to see the plot of the decomposed time-series
到names
呼叫表示您還可以訪問各個組件數據讀取decompose
的幫助文件。這可以通過$
運營商完成。例如,如果您只想查看季節性組件,請使用decomp$seasonal
。
感謝您的回覆。我有一個疑問,而不是分解,我可以使用'stl()'將每週數據分解成這些組件嗎?兩者會給我不同的結果嗎? – Arushi
根據'decompose'幫助文件 - 「函數stl'提供了更復雜的分解。」看看這兩個幫助文件。除了其他差異之外,'stl'使用Loess方法,'decompose'使用經典的自動迴歸和移動平均模型。他們不會產生相同的結果。 –