我想预测(或预测)具有权重的时间序列。
以下工作使用常规的l线性m拟合技术,lm通过对输入数据应用(Sigmoidal)权重分布,本质上对后者数据点的权重比前者更大:
library("stats")
lm.weight.function <- function(x) {10 / (1 + exp(-x))} # Sigmoidal
lm.weights <- lapply(seq(-13, 14, length.out = 27), lm.weight.function)
lm.input <- as.data.frame(c(23957, 46771, 60767, 73284, 60296, 73122, 78304, 87154, 80459, 76885, 56479, 18809, 13453, 13951, 25140, 12035, 11920, 20683, 30357, 35019, 37732, 46150, 47856, 41931, 20985, 32526, 27283))
lm.input <- cbind(1:27, lm.input)
colnames(lm.input) <- c('x', 'y')
lm.model <- lm(formula = y ~ log(x), data = lm.input, weights = unlist(lm.weights))
predict.input <- as.data.frame(28:55)
colnames(predict.input) <- 'x'
predict.model <- predict(lm.model, predict.input)
plot(1:(27+28), c(lm.input$y, predict.model), type = 'l', xlab = 'x', ylab = 'y')

现在我希望使用forecast包做同样的事情。但是,我很难指定weights:
library("forecast")
ts.weight.function <- function(x) {10 / (1 + exp(-x))} # Sigmoidal
ts.weights <- as.data.frame(lapply(seq(-13, 14, length.out = 27), ts.weight.function))
colnames(ts.weights) <- 'trend'
ts.input <- ts(c(23957, 46771, 60767, 73284, 60296, 73122, 78304, 87154, 80459, 76885, 56479, 18809, 13453, 13951, 25140, 12035, 11920, 20683, 30357, 35019, 37732, 46150, 47856, 41931, 20985, 32526, 27283), frequency = 1)
ts.model <- tslm(formula = ts.input ~ log(trend), weights = unlist(ts.weights))
以上打印错误:
Error in eval(expr, envir, enclos) :
..1 used in an incorrect context, no ... to look in
如何使用tslm权重预测时间序列?