R dlmMLE多变量模型估计

时间:2017-03-04 17:29:19

标签: r kalman-filter mle state-space

我正在尝试使用R中的dlmMLE函数估算多变量状态空间模型,作为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函数的最后一行,并返回我提到的错误。

我一直在努力解决这个问题一段时间,但似乎无法让模型发挥作用。有人可以提供一些帮助吗?非常感谢。

谢谢, 斯蒂芬

0 个答案:

没有答案