2
$\begingroup$

I have been trying to estimate state space models using dlm package in R. The problem is that the model I am estimating requires inclusion of a few exogenous variables. I still can't figure out how to do it. Does any one know how to add exogenous variables to a state space model in dlm package?

$\endgroup$
1
$\begingroup$

You almost certainly want to do this with a wrapper function and function pointers.

data(endogenous);
data(exogenous);
model <- function(en, ex) {
   # do stuff
   ...
}
# Now you can't call dlm on model because it expects a function of the form f(x)
# so you need to create one of that format
f <- function(x) {
   return( model(x,exogenous) );
}
out <- dlmMLE(endogenous, rep(0,6), f);

The second function (f) is basically a wrapper for your model in the correct form.

$\endgroup$
1
$\begingroup$

Most probably those exogeneous variables will take known values which are multiplied by elements of the state vector. Then, you can make them time-varying elements of the observation matrix. There is a utility function which does almost all the work for you: dlmModReg. Type example(dlmModReg) to see how it constructs a state-space model with two "regressors". Also, have a look at the book Dynamic Linear Models with R if you can get hold of a copy.

If you provide a concrete example of model that you want to fit, we might help some more.

$\endgroup$
  • $\begingroup$ Actually I am trying to replicate Labauch and Williams (2003) paper on natural interest rate. It involves estimation in 3 stages, each stage requires inclusion of exogenous variables. Say: Measurement equations: $y_t = y_t^* + \alpha_1 (y_{t-1} - y_{t-1}^*)-\alpha_2 (r_{t-1} - r_{t-1}^*) + e_{1t}$, $\pi_t = \beta_1 \pi_{t-1} + b_y (y_t - y_{t-1}^*)+b_f (\pi_{t-1}^o-\pi_{t-1})+e_{2t}$ State equations: $r_t^* =c g_t +z_t, g_t =g_{t-1} +e_{5t}, y_t^* =y_{t-1}^* +g_{t-1}+e_{4t}, z_t = \gamma_1 z_{t-1} + e_{3t}$ For now only measurement equations have exogenous variables ($\pi_{t-1}^o$). $\endgroup$ – AmateurRuser Dec 9 '12 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.