每周数据的时间序列分解 [英] Time Series Decomposition of weekly data

查看:34
本文介绍了每周数据的时间序列分解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 R 完全陌生,刚刚开始使用它.我有三年的每周数据.我想将这个时间序列数据分解为趋势、季节性和其他组件.我有以下疑问:

I am totally new to R and have just started using it. I have three years of weekly data. I want to decompose this time series data into trend, seasonal and other components. I have following doubts:

  1. 我应该使用哪个函数 - ts()decompose()
  2. 如何处理闰年情况.

如果我错了,请纠正我,频率是52.

Please correct me if I am wrong, the frequency is 52.

提前致谢.我真的很感激任何形式的帮助.

Thanks in Advance. I would really appreciate any kind of help.

推荐答案

欢迎使用 R!

是的,频率是 52.

如果数据尚未归类为时间序列,您将需要 ts()decompose().要查找数据集的类,请使用 class(data).如果它返回 "ts",就 R 而言,您的数据已经是一个时间序列.如果它返回其他内容,例如 "data.frame",那么您需要将其更改为时间序列.为 ts(data) 分配一个变量并再次检查类以确保.

If the data is not already classed as time-series, you will need both ts() and decompose(). To find the class of the dataset, use class(data). And if it returns "ts", your data is already a time-series as far as R is concerned. If it returns something else, like "data.frame", then you will need to change it to time-series. Assign a variable to ts(data) and check the class again to make sure.

有一个月度时间序列数据集 sunspot.month 已经加载到 R 中,您可以在上面练习.这是一个例子.您还可以通过编写 ?decompose

There is a monthly time-series dataset sunspot.month already loaded into R that you can practice on. Here's an example. You can also read the help file for decompose by writing ?decompose

class(sunspot.month)
[1] "ts"

> decomp <- decompose(sunspot.month)

> summary(decomp)

         Length Class  Mode     
x        2988   ts     numeric  
seasonal 2988   ts     numeric  
trend    2988   ts     numeric  
random   2988   ts     numeric  
figure     12   -none- numeric  
type        1   -none- character

> names(decomp)
[1] "x"        "seasonal" "trend"    "random"   "figure"   "type"    

> plot(decomp)  # to see the plot of the decomposed time-series 

names 的调用表明您还可以访问各个组件数据.这可以通过 $ 操作符来完成.例如,如果您只想查看季节性组件,请使用 decomp$seasonal.

The call to names indicates that you can also access the individual component data. This can be done with the $ operator. For example, if you want to look at the seasonal component only, use decomp$seasonal.

这篇关于每周数据的时间序列分解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆