2014-01-08 3 views
5

t에서 시즌을 제거하고 싶습니다. 이 특정 TS는 매일 발생하며 매년 및 매주 계절별주기가 있습니다 (빈도 365 및 7).ts 오브젝트의 이중 계절주기

두 가지를 모두 제거하려면 트렌드 및 나머지를 추출하고 새 TS의 빈도를 7로 설정하고 반복하기 전에 주파수를 365로 설정하여 TS에서 stl()을 수행해 보았습니다.

이것은 잘 작동하지 않는 것 같아서 그것이 내 접근 방식인지 또는 문제를 일으키는 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) 

VI

이 또 하나 아래를 확인 계절 지수에 대한 별도의 값을 제공해야합니다

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

계절 구성 요소 (주기적으로 재발 이벤트)뿐만 아니라 동향 (규범의 느린 변화)뿐만 아니라 처리 할 수있는 방법은 훌륭하게 롭 J Hyndman에 의해 구현 구체적으로, stl()입니다.

decomp Hyndman 기능이 부여 (이하 재생)이 seasonality 검사를 위해 매우 유용 제철 (있는 경우), 다음으로 trenddecomposing 시계열 및 부품 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)) 
} 

당신이 그것을 볼 수 있듯이

은 ( loess를 사용하는) stl()을 사용합니다.

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으로 보내주십시오. –