2016-08-02 3 views
0

STL 분석 결과를 벡터로 저장할 수 있습니까?STL 시계열 출력 - 새 벡터 만들기 - R

> stl(satat.ts, s.window = 4) 
    Call: 
    stl(x = satat.ts, s.window = 4) 

    Components 
     seasonal trend remainder 
    2015 Q1 -169.91957477 2914.934 137.98532 
    2015 Q2 11.37099404 3155.224 15.40541 
    2015 Q3 0.09573424 3395.513 -125.60867 
    2015 Q4 165.60565883 3636.489 -132.09422 
    2016 Q1 -184.86967286 3877.464 -68.59450 
    2016 Q2 -10.47226510 4125.118 121.35381 
    2016 Q3 25.14061969 4372.773 115.08665 
    2016 Q4 196.59890247 4593.852 33.54917 
    2017 Q1 -198.92478464 4814.931 58.99366 
    2017 Q2 -45.81852354 5031.778 -123.95919 
    2017 Q3 42.63407915 5248.624 -16.25838 
    2017 Q4 229.27354553 5461.215 27.51108 

트렌드의 벡터를 만들고 싶습니다. 각 값을 수동으로 입력하지 않고 (예 : Trend_data < - stl (satat.ts $ trend))

감사합니다.

답변

1

물론, 그냥 지정하십시오. 나는 당신의 데이터가없는, 그래서 ?stl의 맨 아래에있는 예제를 사용합니다 :

는 "시간이 시리즈는"유망 소리
str(stllc) 
# List of 8 
# $ time.series: mts [1:468, 1:3] -0.000185 0.00173 0.00367 0.007019 0.00869 ... 
# ..- attr(*, "dimnames")=List of 2 
# .. ..$ : NULL 
# .. ..$ : chr [1:3] "seasonal" "trend" "remainder" 
# ..- attr(*, "tsp")= num [1:3] 1959 1998 12 
# ..- attr(*, "class")= chr [1:3] "mts" "ts" "matrix" 
# $ weights : num [1:468] 1 1 1 1 1 1 1 1 1 1 ... 
# $ call  : language stl(x = log(co2), s.window = 21) 
# $ win  : Named num [1:3] 21 21 13 
# ..- attr(*, "names")= chr [1:3] "s" "t" "l" 
# $ deg  : Named int [1:3] 0 1 1 
# ..- attr(*, "names")= chr [1:3] "s" "t" "l" 
# $ jump  : Named num [1:3] 3 3 2 
# ..- attr(*, "names")= chr [1:3] "s" "t" "l" 
# $ inner  : int 2 
# $ outer  : int 0 
# - attr(*, "class")= chr "stl" 

, 그것을 확인 :

stllc <- stl(log(co2), s.window = 21) 

이의가 무엇 보자 out :

str(stllc$time.series) 
# mts [1:468, 1:3] -0.000185 0.00173 0.00367 0.007019 0.00869 ... 
# - attr(*, "dimnames")=List of 2 
# ..$ : NULL 
# ..$ : chr [1:3] "seasonal" "trend" "remainder" 
# - attr(*, "tsp")= num [1:3] 1959 1998 12 
# - attr(*, "class")= chr [1:3] "mts" "ts" "matrix" 

좋아요, 그래서 행렬이고 열 중 하나의 이름은 "trend"입니다.

my_trend = stllc$time.series[, "trend"] 

좋아요!

도중에 도움이되는 설명서를 읽을 수도 있습니다. ?stl는 말한다 : 열 seasonal, trendremainder와 여러 시계열 :

stl 구성 요소

와 클래스 "stl"의 객체

time.series를 반환합니다.

... 같은 결과로 우리를 이끌 것

.

+0

감사를 정보 그레고르을 위해. – Starbucks

1

샘플 데이터를 사용 :

nottem # sample dataset from R 
nottem.stl <- stl(nottem, s.window="periodic") 

nottem.stl 
#   seasonal trend remainder 
# Jan 1920 -9.3471980 49.68067 0.266525379 
# Feb 1920 -9.8552496 49.54552 1.109728805 
# Mar 1920 -6.8533008 49.41037 1.842931803 
# ... 

당신은 지금 당신이 원하는 데이터를 내보낼 수 있습니다

seasonal <- nottem.stl$time.series[, 1] 
trend <- nottem.stl$time.series[, 2] 
remainder<- nottem.stl$time.series[, 3] 

seasonal 
#    Jan  Feb  Mar  Apr ... 
# 1920 -9.3471980 -9.8552496 -6.8533008 -2.7634710 ... 
# 1921 -9.3471980 -9.8552496 -6.8533008 -2.7634710 ... 
# ...