Hello,
I would be very grateful if somebody more knowledgeable then me could assist
me in the following.
I have two (three actually but for simplicity I will say two) models which I
would like to fit jointly as a state space object. Here are the equations:
(1)
w = a1 + b1*(p) + e1
a1 = a1[t-1] + g1
g1 = g1[t-1] + e2
b1 = b1[t-1] + e3
(2)
d = a2 + b2*(w) + e3
a2 = a2[t-1] + e4
b2 = b2[t-1] + e5
Thus far, I have fitted each of the models individually, and the results
have been good. Therefore, I have tried to extend my state space model to
jointly fit both models using the dlmSum function. However, when I try to
estimate the unknown parameters, via maximum likliehood, I get an error
message stating that the sum of dlm's can only be used in constant models.
Is this true? I have looked a the Petris et al. book, and the dlm vignette
and other related articles and I am struggling to find an answer. Please
find my code below, perhaps there is a mistake which can easily be
rectified.
Kind regards,
Alan
> library(dlm)
> mydata <- read.csv("Data.csv", header=TRUE)> pc <-
mydata[,c(2,3,5,22)]> > pc[,1] <- log(pc[,1]/pc[,3]) ; pc[,2] <-
log(pc[,2]/pc[,3])> pc[,3] <- log(pc[,3]) ; pc[,4] <-
log(100*pc[,4])> lagr <- function(x){return(c(NA,x[1:(length(x)-1)]))}>
pc[,5] <- lagr(pc[,4])> names(pc) <-
c("b","d","p","w","w1")> pc
<- ts(pc, start=1650, frequency=1)> dr <- lm(pc[,4]~pc[,3])> pos
<- lm(pc[,2]~pc[,4])> > # set up SS models> ssm1 <-
function(parm){+ rwdw <- dlmModPoly(order=2, + dV =
exp(parm[1]), + dW = exp(parm[2:3]),+
m0 = c(coef(dr)[1],0), + C0 = diag(2)*10)+ slpw <-
dlmModReg(X=pc[,3], + addInt = FALSE, +
dV = exp(parm[4]), + dW = exp(parm[5]), +
m0 = c(coef(dr)[2]), + C0 = diag(1)*10) +
w <- rwdw + slpw+ + rwdd <- dlmModPoly(order=1, +
dV = exp(parm[6]), + dW = exp(parm[7]),+
m0 = c(coef(pos)[1]), + C0 = diag(1)*10)+ slpd <-
dlmModReg(X=pc[,3], + addInt = FALSE, +
dV = exp(parm[8]), + dW = exp(parm[9]), +
m0 = c(coef(pos)[2]), + C0 = diag(1)*10) +
d <- rwdd + slpd+ + return(dlmSum(w, d))+ }> > > # estimate
parameters> fit1 <-
dlmMLE(y=cbind(pc[,4],pc[,2]),parm=c(rep(-2,9)),build=ssm1,hessian=T)Error in
dlmSum(w, d) :
Sum of dlm's is only implemented for constant models>
--
Alan Fernihough
IRCHSS Scholar
UCD School of Economics
[[alternative HTML version deleted]]