3
在你問之前,是的,我需要顯示這麼多的數據。 stl()需要兩個數據週期。在這種情況下,一個週期是24個值,所以stl()需要至少48個值。喂小時動物園時間序列到函數stl()
此外,從STL()的幫助:
「......這應該是類的對象,‘TS’的頻率大於一個......」我升級
一些舊的計算,以便我的數據是動物園格式。到目前爲止,儘管存在stl()速度問題,但我已經升級了每月和每日數據,沒有出現任何明顯的問題。我現在只需要小時數據。
當您運行代碼時,「第一次嘗試」和「第二次嘗試」失敗,而「第三次嘗試」工作。爲什麼?我錯過了什麼真正顯而易見的事情?從「注意接下來會發生什麼」一節中,是否將stl()從動物園系列內部轉換爲導致此問題的ts系列?
library(zoo)
texinp <- "
Date,Demand
2009-01-01 01:00:00,28099.1458685981
2009-01-01 02:00:00,27818.8853634983
2009-01-01 03:00:00,27542.1297303602
2009-01-01 04:00:00,27481.2230897352
2009-01-01 05:00:00,27863.5201611328
2009-01-01 06:00:00,28716.5855560981
2009-01-01 07:00:00,29542.9219102648
2009-01-01 08:00:00,29894.8927398003
2009-01-01 09:00:00,29984.6039306641
2009-01-01 10:00:00,30065.9059781901
2009-01-01 11:00:00,29885.6435823568
2009-01-01 12:00:00,29348.3372466363
2009-01-01 13:00:00,28547.9348426649
2009-01-01 14:00:00,27601.1429031033
2009-01-01 15:00:00,26784.0209678819
2009-01-01 16:00:00,26269.0193386502
2009-01-01 17:00:00,26196.6366764323
2009-01-01 18:00:00,27527.2755148655
2009-01-01 19:00:00,29723.9232834201
2009-01-01 20:00:00,29594.3683930122
2009-01-01 21:00:00,29089.5591764323
2009-01-01 22:00:00,28287.9040272352
2009-01-01 23:00:00,26863.3280593533
2009-01-02 00:00:00,25166.2158816189
2009-01-02 01:00:00,23708.111414388
2009-01-02 02:00:00,22905.427265625
2009-01-02 03:00:00,22517.7926079644
2009-01-02 04:00:00,22519.1570795356
2009-01-02 05:00:00,23065.7224479167
2009-01-02 06:00:00,24452.6789577908
2009-01-02 07:00:00,26450.5363346354
2009-01-02 08:00:00,27815.8465516493
2009-01-02 09:00:00,28402.8746001519
2009-01-02 10:00:00,29007.9232600911
2009-01-02 11:00:00,29333.0119395616
2009-01-02 12:00:00,29378.4373334418
2009-01-02 13:00:00,29145.4215820312
2009-01-02 14:00:00,29069.2706928168
2009-01-02 15:00:00,28900.4390755208
2009-01-02 16:00:00,28724.9172607422
2009-01-02 17:00:00,28523.1717095269
2009-01-02 18:00:00,29480.8798573134
2009-01-02 19:00:00,31168.033992513
2009-01-02 20:00:00,30736.5264789497
2009-01-02 21:00:00,29963.2411859809
2009-01-02 22:00:00,28915.5116943359
2009-01-02 23:00:00,27547.5425157335
2009-01-03 00:00:00,25756.0379166667
2009-01-03 01:00:00,24079.5182259115
2009-01-03 02:00:00,22927.8879052734"
tem <- read.zoo(textConnection(texinp), header = TRUE, sep = ",", tz = "", regular = TRUE)
#First try
frequency(tem)
tem.stl <- stl(tem, s.window = "periodic") #error, not the frequency it was expecting?
#Second try
frequency(tem) <- 24
tem.stl <- stl(tem, s.window = "periodic") #don't worry, it's not hung....
#r calculates for about a minute and comes back with an error
#Third try
temcor <- ts(coredata(tem), freq = 24)
temcor.stl <- stl(temcor, s.window = "periodic") #works fine
plot(temcor.stl)
#Also, notice what happens next
junk <- as.ts(tem) #again, it's not hung, it just takes a while
str(junk)
frequency(junk)
junk #hello
Gro謝謝,它很好。在將這些東西轉換爲動物園之前,我通常使用上面的temcor <-ts(mydata,freq = something)來提供stl()。由於mydata和temcor中沒有任何日期/時間信息,因此我認爲stl()會在以動物園格式輸入數據時忽略日期信息。我認爲它只是使用頻率。我還有一些測試要做,但我想我現在可以得到它。 – 2011-01-29 18:27:16