R预测多元回归

时间:2015-02-13 15:32:35

标签: r time-series simulation regression normal-distribution

线性多元方程Yt = A Yt-1 + B Xt + C * Zt +常数,Xt遵循正态分布,具有时间依赖性均值和方差,Xt~N(Mean(t), STD(t))的。在这种情况下,如何创建一个循环还是有其他方法来预测接下来的12个时期的Yt?谢谢。

1 个答案:

答案 0 :(得分:1)

这不是一个引人注目的问题,你遗漏了很多信息,但这应该会有所帮助:

# define time dependent mean & std for X
xmean <- function(t) 0.5*t
xstd <- function(t) t^(1/3)
xgen <- function(t) rnorm(1, xmean(t), xstd(t))

# define constants (unspecified)
A <- runif(1, min = -1, max = 1)
B <- runif(1, min = -1, max = 1)
C <- runif(1, min = -1, max = 1)

# define Z as Gaussian white noise (unspecified)
zgen <- function(t) rnorm(1)

# set up structure and initialize
y <- numeric(1000)
y[1] <- 0

# define multivariate equation
ygen <- function(t) A*y[t - 1] + B*xgen(t) + C*zgen(t)

# "forecast"
forecasting <- sapply(2:1000, ygen)