Aru*_*shi 1 statistics r time-series
我是R的新手,刚开始使用它.我有三年的每周数据.我想将这个时间序列数据分解为趋势,季节和其他组件.我有以下疑虑:
ts()或者decompose()如果我错了请纠正我,频率是52.
提前致谢.我真的很感激任何帮助.
欢迎来到R!
是的,频率是52.
如果数据尚未被归类为时间序列,则需要ts()和decompose().要查找数据集的类,请使用class(data).如果它返回"ts",就R而言,您的数据已经是一个时间序列.如果它返回其他内容,"data.frame"那么您需要将其更改为时间序列.将变量分配给ts(data)并再次检查该类以确保.
每个时间序列数据集sunspot.month已经加载到R中,您可以练习.这是一个例子.您还可以decompose通过编写来阅读帮助文件?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
Run Code Online (Sandbox Code Playgroud)
该调用names表示您还可以访问单个组件数据.这可以由$操作员完成.例如,如果您只想查看季节性组件,请使用decomp$seasonal.