首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >STL时间序列输出-创建新的向量-R

STL时间序列输出-创建新的向量-R
EN

Stack Overflow用户
提问于 2016-08-02 19:25:30
回答 2查看 148关注 0票数 0

可以将STL分析的输出保存到向量中吗?

代码语言:javascript
复制
    > 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))的情况下,我将如何做到这一点?

谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-08-02 19:42:16

当然,只要分配就行。我没有您的数据,所以我将使用?stl底部的示例

代码语言:javascript
复制
stllc <- stl(log(co2), s.window = 21)

让我们看看那里是什么

代码语言:javascript
复制
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"

“时间序列”听起来很有希望,看看它:

代码语言:javascript
复制
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"

好的,这是一个矩阵,其中一个列被命名为“趋势”。

代码语言:javascript
复制
my_trend = stllc$time.series[, "trend"]

看起来不错!

请注意,我们还可以阅读文档,以便在途中提供帮助。?stl说:

stl返回包含组件的类"stl"的对象。 time.series:包含seasonaltrendremainder列的多个时间序列。 ..。

这会让我们得到同样的结果。

票数 1
EN

Stack Overflow用户

发布于 2016-08-02 19:45:04

使用样本数据:

代码语言:javascript
复制
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
# ...

现在可以导出所需的数据:

代码语言:javascript
复制
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  ...
# ...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38728899

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档