我知道这个问题已存在于此:Creating an fts object in R with ftsa to functional data analysis of a time series
但缺少可重复的示例和答案,所以希望我的示例和数据得到答案。我的数据如下:
> data
date GDBR2 GDBR5 GDBR10 GDBR30
1 2015-10-15 -0.261 -0.032 0.550 1.310
2 2015-11-15 -0.370 -0.107 0.558 1.414
3 2015-12-15 -0.339 -0.049 0.641 1.411
4 2016-01-15 -0.394 -0.158 0.540 1.314
5 2016-02-15 -0.521 -0.312 0.237 0.928
6 2016-03-15 -0.453 -0.243 0.316 1.062
7 2016-04-15 -0.510 -0.382 0.127 0.805
8 2016-05-15 -0.513 -0.381 0.124 0.829
9 2016-06-15 -0.594 -0.483 -0.010 0.542
10 2016-07-15 -0.652 -0.551 0.006 0.530
11 2016-08-15 -0.613 -0.521 -0.074 0.433
12 2016-09-15 -0.640 -0.478 0.047 0.654
我能够创建声称为fts / zoo的fts1对象,但无法运行ftsm
,因为is.fts
返回FALSE
library(ftsa)
library(fts)
fts1 <- as.fts(data.frame(asofdate=data$date,data[,-1]))
class(fts1)
[1] "fts" "zoo"
ftsm(fts1, order=3)
Error in 1:ncol(y$y) : argument of length 0
is.fts(fts1)
[1] FALSE
对于如何创建ftsm函数中使用的fts对象的任何帮助表示赞赏。
这里输入数据:
> dput(data)
structure(list(date = structure(c(16723L, 16754L, 16784L, 16815L,
16846L, 16875L, 16906L, 16936L, 16967L, 16997L, 17028L, 17059L
), class = "Date"), GDBR2 = c(-0.261, -0.37, -0.339, -0.394,
-0.521, -0.453, -0.51, -0.513, -0.594, -0.652, -0.613, -0.64),
GDBR5 = c(-0.032, -0.107, -0.049, -0.158, -0.312, -0.243,
-0.382, -0.381, -0.483, -0.551, -0.521, -0.478), GDBR10 = c(0.55,
0.558, 0.641, 0.54, 0.237, 0.316, 0.127, 0.124, -0.01, 0.006,
-0.074, 0.047), GDBR30 = c(1.31, 1.414, 1.411, 1.314, 0.928,
1.062, 0.805, 0.829, 0.542, 0.53, 0.433, 0.654)), row.names = c(NA,
-12L), class = "data.frame", .Names = c("date", "GDBR2", "GDBR5",
"GDBR10", "GDBR30"))
答案 0 :(得分:1)
有不同的包定义了一个类“fts”而你使用的是错误的。
library(ftsa)
#see the link in the documentation for the correct constructor
fts1 <- rainbow::fts(x = data$date, y = as.matrix(data[,-1]))
#apparently colnames must be numbers of the given frequency
#this appears to be at least an documentation bug
#but I know nothing about this kind of analysis
colnames(fts1$y) <- seq_along(colnames(fts1$y))
ftsm(fts1, order=3)
#Functional time series model
#
#Call: ftsm(y = fts1, order = 3)
#
#Main effects: Mean
#Order of interaction: 3
# y: as.matrix(data[, -1])
# x: data$date