2

我正在尝试使用dlmMLER 中的函数作为dlm库的一部分来估计多元状态空间模型,但不断收到以下错误。

Error in fit < dlmMLE(Y, parm = c(rep(0, 10)), build = model) : 
  comparison of these types is not implemented

我使用的模型规格是:

y1t = At + beta1*Ft + e1t
y2t = a2 + beta2*Ft + e2t
y3t = a3 + beta3*Ft + e3t

Ft = phi1*Ft-1 + phi2*Ft-2 + vt

At = At-1 + wt

where: 
 - y1, y2 and y3 are the observable variables, 
 - At is a time varying coefficient modelled as a random walk, 
 - a2 and a3 are fixed coefficients, 
 - Ft is a latent factor which follows an AR(2) process.

我在 R 中指定了模型,如下所示。

model <- function(x) {

  FF <- matrix(c(x[1:3],rep(0,3),diag(3)), nr=3)
  V  <- diag(c(exp(x[4:6])))

  TL <- matrix(c(x[7],1,x[8],0),nr=2)
  TR <- matrix(c(rep(0,2*3)),nr=2)
  BL <- matrix(c(rep(0,2*3)), nc=2)
  BR <- diag(3)

  GG <- rbind(cbind(TL,TR),cbind(BL,BR))
  W  <- diag(c(exp(x[9]),0,exp(x[10]),rep(0,2)))

  m0 <- rep(0,5)
  C0 <- 100*diag(5)

  dlm(FF=FF, V=V, GG=GG, W=W, m0=m0,C0=C0)
}

# where x[1:10] correspond to beta[1:3], e[1:3], phi[1:2], v and w, respectively.

fit < dlmMLE(Y, parm=c(rep(0,10)), build=model)
#Y is the matrix containing time series for observable variables y1, y2, y3

当我运行代码时,它会执行到dlmMLE调用函数的最后一行并返回我提到的错误。

我一直在努力解决这个问题一段时间,但似乎无法让模型工作。有人可以提供一些帮助吗?将不胜感激。

谢谢,斯特凡

4

0 回答 0