Elementary: The error message, "Error in y - f : non-conformable
arrays", is informative, though less than perfect. The help file for
"SS" explains the model, which consists of an observation equation and
a
transition equation. The observation equation is as follows:
Y_t = F_t^T * theta_t + v_t, v_t ~ N(0,V_t).
What are the dimensions of the matrices involved? When I print
'model', the first few lines repeat the model and then give the
dimensions:
Dimensions of the involved terms:
dim(Y_t) = 1 x 1 (dx1)
dim(F_t) = 2 x 1 (pxd)
dim(G_t) = 2 x 2 (pxp)
dim(V_t) = 1 x 1 (dxd)
dim(W_t) = 2 x 2 (pxp)
dim(C_0) = 2 x 2 (pxp)
dim(m_0) = 2 x 1 (px1)
This says dim(Y_t) = 1 x 1. This seems strange, since you defined y_
to be 20 x 2. However, upon closer examination, I found that matrix(y_)
was 40 x 1. Oops. When I replaced "matrix(y_)" by just
"y_", I got a
different error in a different place.
From examining further the model and what you specified, I found that
your Vmat and Wmat matrices were NOT symmetric, and they are required to
be symmetric and nonnegative definite, i.e., can be decomposed into a
product of a matrix times its transpose. I didn't do it all in this
order, so I don't have a simple example to give you to tie it all in a
neat bow, but I trust you will get the idea.
I want to thank you for including a self-contained, reproducible
example, without which it would have been much more difficult for me to
diagnose your problem.
If you have further questions about this, please submit another post.
Let me ask now, however, if you have worked through the examples in
"~\library\sspir\demo"? I haven't tried them all, but I'm
sure they
must have worked for the authors of the package, so they probably still
work and might help you understand and use the package more effectively.
Also, one of my favorite tools for tracing problems like this is
"debug". For example, you could type "SS" at a command
prompt, then
copy the code into a script window so you could follow the code line by
line after saying 'debug(SS)', then issuing a command like 'model
<-
SS(...)'. That's not how I found this problem, but have used this with
similar problems, and it has been a great help to me, both in finding
how I've misused other people's code and in debugging my own code.
Since 'kfilter' calls 'UseMethod', you need to know to try
"methods('filter')". This identified "kfilter.SS"
and "kfilter.ssm".
Since class(model) = "SS", you want kfilter.SS.
hope this helps,
Spencer Graves
Fernando Saldanha wrote:> I am having a problem with the package SSPIR. The code below
> illustrates it. I keep getting the message: "Error in y - f :
> non-conformable arrays."
>
> I tried to tweak the code below in many different ways, for example,
> substituting rbind for cbind, and sometimes I get a different error
> message, but I could not find a variation of this code that would
> work.
>
> Any help will be greatly appreciated. I am running R version 2.3, on
> Windows XP Professional.
>
>> library(sspir)
>>
>> # Create observation vector
>> y_ <- cbind(rep(1, 20), rep(2, 20))
>>
>> mat <- rbind(c(1, 2), c(3, 4))
>>
>> #####################################################################
>> # Create model
>> model <- SS(y = matrix(y_),
> + Fmat = function(tt, x, phi) {
> + FM <- mat
> + cat("Fmat", dim(FM), "\n")
> + FM
> + },
> + Gmat = function(tt, x, phi) {
> + GM <- mat
> + cat("Gmat", dim(GM), "\n")
> + GM
> + },
> + Vmat = function(tt, x, phi) {
> + VM <- mat
> + cat("Vmat", dim(VM), "\n")
> + VM
> + }, # var observation equation
> + Wmat = function(tt, x, phi) {
> + WM <- mat
> + cat("Wmat", dim(WM), "\n")
> + WM
> + },
> + m0 = matrix(c(1, 2), nrow = 1),
> + C0 = mat)
> Gmat 2 2
> Gmat 2 2
>> model.f <- kfilter(model)
> Gmat 2 2
> Wmat 2 2
> Fmat 2 2
> Vmat 2 2
> Error in y - f : non-conformable arrays
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html