在下面的例子中,我试图在日常数据上使用Holt-Winters平滑,但我遇到了几个问题:
# generate some dummy daily data
mData = cbind(seq.Date(from = as.Date('2011-12-01'),
to = as.Date('2013-11-30'), by = 'day'), rnorm(731))
# convert to a zoo object
zooData = as.zoo(mData[, 2, drop = FALSE],
order.by = as.Date(mData[, 1, drop = FALSE], format = '%Y-%m-%d'),
frequency = 7)
# attempt Holt-Winters smoothing
hw(x = zooData, h = 10, seasonal = 'additive', damped = FALSE,
initial = 'optimal', exponential = FALSE, fan = FALSE)
# no missing values in the data
sum(is.na(zooData))
这会导致以下错误:
ets中的错误(x,“AAA”,alpha = alpha,beta = beta,gamma = gamma, damped = damped,:你一定是在开玩笑。我需要更多数据! In 另外:警告信息:在ets(x,“AAA”,alpha = alpha,beta = beta,gamma = gamma,damped = damped,:遇到缺失值。 使用时间序列中最长的连续部分
强调我的。
几个问题: 1.缺失值来自何处? 2.我假设试图估计365个季节性参数会产生“需要更多数据”吗?
根据Gabor的建议,我为数据重建了一个小数索引,整数是几周。
我有几个问题 1.当周期性假设为每周时,这是处理日常数据的适当方式吗? 2.使用日常数据时,是否有更优雅的方式处理日期?
library(zoo)
library(forecast)
# generate some dummy daily data
mData = cbind(seq.Date(from = as.Date('2011-12-01'),
to = as.Date('2013-11-30'), by = 'day'), rnorm(731))
# conver to a zoo object with weekly frequency
zooDataWeekly = as.zoo(mData[, 2, drop = FALSE],
order.by = seq(from = 0, by = 1/7, length.out = 731))
# attempt Holt-Winters smoothing
hwData = hw(x = zooDataWeekly, h = 10, seasonal = 'additive', damped = FALSE,
initial = 'optimal', exponential = FALSE, fan = FALSE)
plot(zooDataWeekly, col = 'red')
lines(fitted(hwData))
答案 0 :(得分:3)
hw
需要ts
个对象而不是zoo
个对象。使用
zooDataWeekly <- ts(mData[,2], frequency=7)
除非有充分理由准确指定模型,否则让R为您选择最佳模型通常会更好:
fit <- ets(zooDataWeekly)
fc <- forecast(fit)
plot(fc)