【发布时间】:2015-03-11 23:18:45
【问题描述】:
我有一列从 1/2004 到 12/2010 的 84 个月支出,在 Excel 中看起来像...
12247815.55
11812697.14
13741176.13
21372260.37
27412419.28
42447077.96
55563235.3
45130678.8
54579583.53
43406197.32
34318334.64
25321371.4
...(74 more entries)
我正在尝试从该系列的预测包中运行 stl(),因此我加载了数据:
d <- ts(read.csv("deseason_vVectForTS.csv",
header = TRUE),
start=c(2004,1),
end=c(2010,12),
frequency = 12)
(如果我设置 header=FALSE,它将吸收第一个条目 - 122...- 作为第二列的标题,并将第一列的标题命名为“X”)
但我的环境没有填充Time Series Object from 2004 to 2011(正如它之前所说),它只是说ts[1:84, 1]。
可能相关的是,
fit <- stl(d)
抛出
Error in stl(d) : only univariate series are allowed.
尽管
head(d)
[1] 12247816 11812697 13741176 21372260 27412419 42447078
和
d
Jan Feb Mar Apr May Jun Jul Aug Sep Oct
2004 12247816 11812697 13741176 21372260 27412419 42447078 55563235 45130679 54579584 43406197
("years 2005-2010 look exactly the same, and all rows have columns for Jan-Dec; it just doesn't fit on here neatly - just trying to show the object has taken the ts labeling structure.")
我做错了什么?据我所知,这与我过去构建时间序列对象的方式相同......
【问题讨论】:
-
什么? inside-r.org/packages/cran/forecast/docs/stlfsn-p 就是它在 excel 中的样子。
-
请在控制台输入 ?forecast 并在再次响应之前查看该包中的 stl 函数 - 一定要使用 forecast 包的 stl 函数。
-
stl() 不在预测包中。它是 stats 包的一部分。 stlf() 在预测包中。
-
这有助于返回到 OP,因为 stlf 函数会抛出相同的错误。 (不确定在未加载 stats 包时如何调用 stl() ,但这确实不是这个问题的重点。)
-
stlf() 正在调用 stl()。使用 R 时,您始终会加载 stats 包。
标签: r csv time-series forecasting