0

假设我模拟以下数据

alpha = 0.9   
beta = 0.2    
delta = alpha 
yt1 = rnorm(1, mean =10, sd = 1)
xt1 = rnorm(1, mean = 1,sd = 1)
Yt <- (alpha * yt1) + (beta * xt1) + rnorm(1,0,1)
T = 1320       #from a set of {330,990,1320}

xt <-c(xt1)
for (i in 2:T) {
  xt[i] <- alpha * xt[i-1] +rnorm(1,0,1)
  
}
plot(xt)
lines(xt)
yt <-c(yt1)
for (i in 2:T) {
  yt[i] <- (alpha * yt[i-1]) + (beta * xt[i-1]) + rnorm(1,0,1)
}
plot(yt)
lines(yt)

yt <- as.ts(yt)
xt <- as.ts(xt)
uu <- dynlm(yt ~ L(yt,(1:4))+ L(xt,(1:10)))
forecast(uu)

当我尝试预测时,出现以下错误:

Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : 
  variable lengths differ (found for 'L(xt, (1:10))')
In addition: Warning message:
'newdata' had 10 rows but variables found have 1317 rows.

有谁知道如何解决这个错误?

4

0 回答 0