【发布时间】:2014-04-21 22:16:21
【问题描述】:
/* 我不想在 R 中使用 HoltWinters 函数,我已经看到 R code 用于 holtwinters 函数,但我真的不想实现或复制整个 R 代码。主要是我想写一个代码来得到和holtwinters得到的答案一样的结果*/
到目前为止,我有以下代码,但我不确定应该使用哪个函数来绘制新罕布什尔州从 1912 年到 1971 年的年平均温度测量值,并使用 lines() 对其进行指数平滑处理
require(datasets)
data(nhtemp)
plot.ts(nhtemp)
lines(nhtemp, col="red") # gives the same plot as plot.ts(nhtemp)!!
我不知道如何使用lines() 覆盖nhtemp 的指数平滑
P.S.:我不想尝试任何外部软件包,例如 forecast 或 stats,但我只是在尝试以下一些实验:
我尝试按照下图中提到的说明进行操作,但收到此错误:
> lines(nhtemp$fitted)
#Error in lines(nhtemp$fitted) :
# error in evaluating the argument 'x' in selecting a method for function 'lines': #Error in nhtemp$fitted : $ operator is invalid for atomic vectors
> HoltWinters(nhtemp)
#Error in decompose(ts(x[1L:wind], start = start(x), frequency = f), seasonal) :
# time series has no or less than 2 periods
【问题讨论】:
-
这篇文章不是和交叉验证更相关吗?我不知道为什么它被迁移或关闭了?!
-
这应该转到 CrossValidated 并且您需要重新表述整个问题。正如您尝试过的代码暗示您正在尝试在某些数据集上运行
HoltWinters()函数并遇到错误,而实际上您要做的是自己编写指数平滑函数
标签: r time-series data-visualization