2

I am attempting to estimate a multivariate state space model using the dlmMLE function in R as part of the dlm library but keep getting the below error.

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

The specification of the model I am using is:

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.

I have specified the model in R as per below.

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

When I run the code it executes up to the last line where the dlmMLE function is called and returns the error I mentioned.

I have been struggling to fix this problem for a while now, but can't seem to get the model to work. Could anyone please offer some assistance? It would be much appreciated.

Thanks, Stefan

Stefan
  • 41
  • 4

0 Answers0