在 Holtwinter 中查找平均绝对偏差

Finding Mean Absolute Deviation in Holtwinter

假设我们的数据集如下所示;

demand <- ts(BJsales, start = c(2000, 1), frequency = 12)
plot(demand)

现在我将时间序列对象传递给 HoltWinter 并绘制拟合数据。

hw <- HoltWinters(demand)
plot(hw)

我想区分需求数据和拟合数据以求出平均绝对偏差 (MAD)。 我接受了 hw$x 的需求 我通过 hw$fit

适应了
accu_Holt_data <- as.data.frame(hw$x)
 fore_holt <- as.data.frame(hw$fit)
differnce <- accu_Holt_data - fore_holt  

不能因为行长度不同而有所不同

根据我上面的评论,你可以这样做:

dta <- cbind(hw$fit[, 1], hw$x)
mean(abs(dta[, 2] - dta[, 1]), na.rm = TRUE)

您的方法有两个主要问题:首先,hw$fit 是一个多列数据框,其中第一列 xhat 代表过滤后的系列。其次,两个时间序列有不同的指标。因此需要像 cbind 这样的东西来合并时间序列。