2015-03-31 173 views
0

我有一個時間序列數據集,其中包含374天的數據點(每天1個數據點)。我奮力瞭解TS功能的頻率參數,所以我把它空:R時間序列頻率

ts_0615391206 <- ts(demand_rev_0615391206$estimated_demand, 
        start=as.Date(min(demand_rev_0615391206$date),format = "d%/m%/Y%"), 
        end=as.Date(max(demand_rev_0615391206$date),format = "d%/m%/Y%"), 
        #frequency = 1 
        ) 

plot.ts(ts_0615391206) enter image description here 然而,當我嘗試使用分解:

ts_0615391206_components <- decompose(ts_0615391206) 

我收到錯誤:

Error in decompose(ts_0615391206) : 
    time series has no or less than 2 periods 

如何確定我的數據中有多少段時間,因此我們的數據段米的「頻率」值應該是?

> dput(head(ts_0615391206)) 
c(2.71, 2.47, 3.86, 3.61, 5.78, 5.59) 
> 
> str(ts_0615391206) 
Time-Series [1:194] from 16125 to 16318: 2.71 2.47 3.86 3.61 5.78 5.59 3.28 3.4 3.34 3.68 ... 

回答

0

每文檔?ts

...one could use a value of 7 for frequency when the data are sampled daily, and the natural time period is a week, or 12 when the data are sampled monthly and the natural time period is a year. Values of 4 and 12 are assumed in (e.g.) print methods to imply a quarterly and monthly series respectively.

嘗試設置frequency = 7

0

decompose()功能從stats R包分解給定的時間序列趨勢,季節性組件和提醒部分。季節分量是嚴格的週期性時間序列,週期長度等於時間序列的frequency。例如,如果您設置了frequency = m,decompose()函數會構建分解哪個季節性組件將具有期間m。如果是整數,> 1,並且時間序列的長度爲大於或等於2 decompose()功能工作。 幫助頁面?decompose指出時間序列應該「覆蓋整個週期的整數」,以便該功能正常工作。所以如果系列長度是m的倍數可能會更好。

您的數據沒有明確的週期性。可能是this discussion將對你有用,因爲它包含Rob Hyndman的R腳本來揭示一系列的週期性。