Re: [R] Setting up a State Space Model in dlm

2011-08-26 Thread Giovanni Petris
This was an example using package KFAS, which needs to be loaded before running the code ('kf' is the function that computes Kalman filter in package KFAS) Giovanni On Fri, 2011-08-26 at 07:11 -0700, quantguy wrote: > Thanks! However, I added the line of code and receive an error during the > opt

Re: [R] Setting up a State Space Model in dlm

2011-08-26 Thread quantguy
Thanks! However, I added the line of code and receive an error during the optim() procedure: rror in fn(par, ...) : could not find function "kf" The update code is here: tmp <- ts(read.table("http://shazam.econ.ubc.ca/intro/P.txt";, header=T), start=c(1978,1), frequency=12) * 100 y <- tmp[,1:4

Re: [R] Setting up a State Space Model in dlm

2011-08-26 Thread Giovanni Petris
I just saw this old post, but it seems that nobody replied, so let me try. If you can assume that also U[t] evelves as a random walk, I would build a DLM by taking the state vector to be x[t] = (U[t], UN[t], pi[t])' By plugging in the equation for pi[t] the random walk expressions for U[t] and

Re: [R] Setting up a State Space Model in dlm

2011-08-26 Thread Giovanni Petris
Oops.. You need to add the following line, right after the "m <- NCOL(y)" statement: k <- m * (m+1) / 2 'k' is the number of independent parameters in an m-by-m covariance matrix, and two such matrices are estimated (Ht and Qt, both time invariant). Hence the unknown parameter theta has length

Re: [R] Setting up a State Space Model in dlm

2011-08-25 Thread quantguy
I get the identical error even when applying the sample code from the dlm vignette on state space models: http://www.jstatsoft.org/v41/i04/paper The sample code is here: tmp <- ts(read.table("http://shazam.econ.ubc.ca/intro/P.txt";, header=T), start=c(1978,1), frequency=12) * 100 y <- tmp[,1:4] -

Re: [R] Setting up a State Space Model in dlm

2011-06-10 Thread Michael Ash
Thank you.    The new article linked below is excellent. BTW, I have had trouble getting the sample code to run.In particular, there is a variable k that does not appear to be set when it is used at line 227. Here is the line where it is called: fit <- optim(par = rep(0, 2 * k), fn = logLik,

Re: [R] Setting up a State Space Model in dlm

2011-06-10 Thread Gavin Simpson
On Tue, 2011-06-07 at 17:24 +0100, Michael Ash wrote: > This question pertains to setting up a model in the package "dlm" > (dynamic linear models, > http://cran.r-project.org/web/packages/dlm/index.html The author of the dlm package has just published a paper on state space models in R including

[R] Setting up a State Space Model in dlm

2011-06-07 Thread Michael Ash
This question pertains to setting up a model in the package "dlm" (dynamic linear models, http://cran.r-project.org/web/packages/dlm/index.html I have read both the vignette and "An R Package for Dynamic Linear Models" (http://www.jstatsoft.org/v36/i12/paper), both of which are very helpful. Ther