我正在尝试计算一些时间序列特征,并且在 R 中使用 tsfeatures 函数时出现以下错误:
Warning messages:
1: In .f(.x[[i]], ...) : Insufficient data to compute STL decomposition
2: In .f(.x[[i]], ...) : Insufficient data to compute STL decomposition
对于每个时间序列,都有 365 天的测量值,所以我对数据不足的警告感到困惑。
我怀疑该错误可能与原始数据有关,我曾尝试将其从面板数据强制转换为矩阵格式的时间序列,如下所示,但我可能搞砸了:
library(tsfeatures)
set.seed(25)
inds <- seq(as.Date("2022-05-01"), as.Date("2023-04-30"), by = "day")
values <- c(rnorm(length(inds), mean = 20, sd = 2),rnorm(length(inds), mean = 200, sd = 20))
products <- rep(c("A","B"), each = 365)
df <- data.frame(c(inds,inds),products,values)
df_mts <- ts(matrix(df$values, ncol = n_distinct(df$products), nrow = 365), frequency = 365, start = c(2022, as.numeric(format(as.Date("2022-05-01"), "%j"))))
features <- bind_cols(
tsfeatures(df_mts, c("acf_features","entropy","lumpiness","flat_spots","crossing_points")),
tsfeatures(df_mts,"stl_features", s.window = "periodic", robust = TRUE)
)
这是将日常数据转换为ts格式的正确方法吗?