2014-01-08 88 views
5

我想從一個TS剔除季節性。這個特定的ts是每天的,並且具有每年和每週的季節性週期(頻率365和7)。雙季節週期對象

爲了去除兩者,我曾嘗試進行與頻率的TS設定爲365 STL(),提取趨勢和剩餘物,和新的TS的頻率設定爲7之前,並重復。

這似乎並不奏效非常好,我想知道它是否是我的方法,或固有的,這是造成我的問題TS東西。任何人都可以批評我的方法論,也許可以推薦一種替代方法嗎?

回答

0

檢查,如果這是有用的:
Start and End Values depends on your Data - Change the Frequency values accordingly

splot <- ts(Data1, start=c(2010, 2), end=c(2013, 9), frequency=12) 

additive trend, seasonal, and irregular components can be decomposed using the stl() Function

fit <- stl(splot, s.window="period") 
monthplot(splot) 
library(forecast) 
vi <-seasonplot(splot) 

應給予單獨的值的季節性指數

還要檢查以下之一:

splot.stl <- stl(splot,s.window="periodic",na.action=na.contiguous) 
    trend <- splot.stl$time.series[,2] 
    season <- splot.stl$time.series[,1] 
    remainder <- splot - trend - season 
1

不僅可以處理季節性組件(週期性重現事件),而且可以處理趨勢(規範中緩慢移動)的方法令人欽佩地是stl(),具體由Rob J Hyndman實施。

decomp功能海德門給出有(下面再現)是非常有益的用於檢查seasonality然後decomposing時間序列進季節(如果有的話),trend,和residual組件。

decomp <- function(x,transform=TRUE) 
{ 
    #decomposes time series into seasonal and trend components 
    #from http://robjhyndman.com/researchtips/tscharacteristics/ 
    require(forecast) 
    # Transform series 
    if(transform & min(x,na.rm=TRUE) >= 0) 
    { 
    lambda <- BoxCox.lambda(na.contiguous(x)) 
    x <- BoxCox(x,lambda) 
    } 
    else 
    { 
    lambda <- NULL 
    transform <- FALSE 
    } 
    # Seasonal data 
    if(frequency(x)>1) 
    { 
    x.stl <- stl(x,s.window="periodic",na.action=na.contiguous) 
    trend <- x.stl$time.series[,2] 
    season <- x.stl$time.series[,1] 
    remainder <- x - trend - season 
    } 
    else #Nonseasonal data 
    { 
    require(mgcv) 
    tt <- 1:length(x) 
    trend <- rep(NA,length(x)) 
    trend[!is.na(x)] <- fitted(gam(x ~ s(tt))) 
    season <- NULL 
    remainder <- x - trend 
    } 
    return(list(x=x,trend=trend,season=season,remainder=remainder, 
    transform=transform,lambda=lambda)) 
} 

正如你可以看到它使用stl()(使用loess)是否存在季節性和處罰迴歸樣條,如果沒有季節性。

6

使用forecast軟件包中實現的TBATS模型有一種非常簡單的方法。下面是一個例子假設你的數據被存儲爲x:模型的

library(forecast) 
x2 <- msts(x, seasonal.periods=c(7,365)) 
fit <- tbats(x2) 
x.sa <- seasadj(fit) 

詳細情況De Livera, Hyndman and Snyder (JASA, 2011)描述。

+0

非常感謝您的回覆,羅布。你的預測套餐是最好的,看起來好像我只是抓住了表面。在你的答案的seasadj(FIT)線返回,我很努力解釋錯誤,或許你能幫忙嗎? 「[.default'(comp,,」season「):下標越界出現錯誤」 –

+0

你能給我發一個最小的例子來複制錯誤嗎?此功能相對較新,且未經過充分測試。它在我嘗試的例子上工作。將錯誤報告發送到https://github.com/robjhyndman/forecast/issues?state=open –