R:Holt-Winters,提供每日数据(预包装) [英] R: Holt-Winters with daily data (forecast package)

查看:210
本文介绍了R:Holt-Winters,提供每日数据(预包装)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下示例中,我尝试对每日数据使用Holt-Winters平滑,但是遇到了两个问题:

In the following example, I am trying to use Holt-Winters smoothing on daily data, but I run into a couple of issues:

# 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, 阻尼=阻尼,:您必须在开玩笑.我需要更多数据!在 另外:警告消息:在ets(x,"AAA"中,alpha = alpha,beta = beta,伽玛=伽玛,阻尼=阻尼,:缺少的值. 使用时间序列的最长连续部分

Error in ets(x, "AAA", alpha = alpha, beta = beta, gamma = gamma, damped = damped, : You've got to be joking. I need more data! In addition: Warning message: In ets(x, "AAA", alpha = alpha, beta = beta, gamma = gamma, damped = damped, : Missing values encountered. Using longest contiguous portion of time series

强调我的.

一对问题: 1.缺失值从何而来? 2.我假设需要更多数据"来自尝试估算365个季节性参数?

Couple of questions: 1. Where are the missing values coming from? 2. I am assuming that the "need more data" arises from attempting to estimate 365 seasonal parameters?

根据Gabor的建议,我为整数为周的数据重新创建了分数索引.

Based on Gabor's suggestion, I have recreated a fractional index for the data where whole numbers are weeks.

我有几个问题.
1.如果假定周期性为每周一次,这是处理每日数据的适当方法吗?
2.在处理每日数据时,是否有更优雅的方式来处理日期?

I have a couple of questions.
1. Is this is an appropriate way of handling daily data when the periodicity is assumed to be weekly?
2. Is there is a more elegant way of handling the dates when working with daily data?

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))

推荐答案

hw需要ts对象而不是zoo对象.使用

hw requires a ts object not a zoo object. Use

zooDataWeekly <- ts(mData[,2], frequency=7)

除非有充分的理由准确指定模型,否则通常最好让R为您选择最佳模型:

Unless there is a good reason for specifying the model exactly, it is usually better to let R select the best model for you:

fit <- ets(zooDataWeekly)
fc <- forecast(fit)
plot(fc)

这篇关于R:Holt-Winters,提供每日数据(预包装)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆