R反向应用增长率

R反向应用增长率,r,zoo,R,Zoo,我有一个数据,有两个不同的月序列和一年的重叠 ts1 <- ts(cumsum(rnorm(120,.1,1)), start = 1995, frequency = 12) ts2 <- ts(cumsum(rnorm(120,.2,1)), start = 2004, frequency = 12) ts1这里有一种方法,使用重叠位上的简单线性回归来确定两个序列之间的关系,然后将该模型应用于ts1的非重叠部分,以估计ts2的早期值。最后一步为您提供了一个新的ts对象,该对象表示

我有一个数据,有两个不同的月序列和一年的重叠

ts1 <- ts(cumsum(rnorm(120,.1,1)), start = 1995, frequency = 12)
ts2 <- ts(cumsum(rnorm(120,.2,1)), start = 2004, frequency = 12)

ts1这里有一种方法,使用重叠位上的简单线性回归来确定两个序列之间的关系,然后将该模型应用于
ts1
的非重叠部分,以估计
ts2
的早期值。最后一步为您提供了一个新的
ts
对象,该对象表示非重叠期间
ts2
的预测值

# Make the toy data
set.seed(1)
ts1 <- ts(cumsum(rnorm(120,.1,1)), start = 1995, frequency = 12)
ts2 <- ts(cumsum(rnorm(120,.2,1)), start = 2004, frequency = 12)
# Now do the estimation
x <- as.vector(window(ts1, start = c(2004,1), end = c(2004,12)))
y <- as.vector(window(ts2, start = c(2004,1), end = c(2004,12)))
tsmod <- lm(y ~ x)
ts2preds <- predict(tsmod, newdata = as.data.frame(window(ts1, start = c(1995,1), end = c(2003,12))))
ts2prior <- ts(data = ts2preds, start = c(1995, 1), end = c(2003, 12), frequency = 12)
以下是产生以下结果的情节:

以下是两个系列的比较:

> cor(ts2plus$mean, ts2preds)
[1] 0.9760174

<> P>如果你的主要目标是对这些早期值进行最好的预测,你可以考虑运行两个版本并平均它们的结果。然后这就变成了一个非常简单的多模型集合预测(或回溯)。

这里有一种方法,在重叠位上使用简单的线性回归来确定两个序列之间的关系,然后将该模型应用于
ts1
的非重叠部分,以估计
ts2
的早期值。最后一步为您提供了一个新的
ts
对象,该对象表示非重叠期间
ts2
的预测值

# Make the toy data
set.seed(1)
ts1 <- ts(cumsum(rnorm(120,.1,1)), start = 1995, frequency = 12)
ts2 <- ts(cumsum(rnorm(120,.2,1)), start = 2004, frequency = 12)
# Now do the estimation
x <- as.vector(window(ts1, start = c(2004,1), end = c(2004,12)))
y <- as.vector(window(ts2, start = c(2004,1), end = c(2004,12)))
tsmod <- lm(y ~ x)
ts2preds <- predict(tsmod, newdata = as.data.frame(window(ts1, start = c(1995,1), end = c(2003,12))))
ts2prior <- ts(data = ts2preds, start = c(1995, 1), end = c(2003, 12), frequency = 12)
以下是产生以下结果的情节:

以下是两个系列的比较:

> cor(ts2plus$mean, ts2preds)
[1] 0.9760174
<> P>如果你的主要目标是对这些早期值进行最好的预测,你可以考虑运行两个版本并平均它们的结果。然后,这就变成了一个非常简单的多模型集合预测(或回溯)