Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

I want to jointly estimate a very simple MV-Normal two-dimensional AR[1] process, $[x_t,y_t]=[x_{t-1},y_{t-1}]+\text{[Bivariate Gaussian error]}$, in BUGS. But the syntax has been impossible to figure out. Here's the problem part of the code:

 ## transition model (aka random walk prior)
 for(i in 2:NPERIODS1){         
    mu.vector[i,1:2]<-vector[i-1,1:2]
    vector[i,1:2]~dmnorm(mu.vector[i,1:2], omega[1:2,1:2])
    }

The compiler throws up a "Expected a multivariate node" error. Looking through some examples, there doesn't seem to be any easy way to introduce a structured mean or covariance variables for the multivariate normal function. How should I proceed?

Edit: Changed omega[,] to omega[1:2,1:2] for clarity.

share|improve this question

3 Answers

up vote 1 down vote accepted

Have you tried replacing omega[,] with omega[1:2,1:2]? I haven't got BUGS here but IIRC that's what it expects inside dmnorm.

share|improve this answer
Doesn't help, unfortunately. Having isolated different parts of the code, I'm pretty sure the issue is that it's not reading the mean vector as I want it to. – DavidShor May 29 '11 at 18:54
1  
Darn. Googling the syntax just now turned up BUGS code for a VAR model here; it's purported to work :) maybe a clue in there... – JMS May 29 '11 at 19:33
Thank you! Googling for working BUGS code is always difficult, due to the unfortunate name of the language. Statisticians make this mistake a lot, I mean, R?! – DavidShor May 30 '11 at 9:27

Even though this is over a year late, for posterity I think it should be answered since I stumbled onto this thread with essentially the same question. The problem is that in BUGS the <- assignment operator is only defined on scalars. So, the appropriate code is

## transition model (aka random walk prior)
for(i in 2:NPERIODS1){   
    for(j in 1:2){      
        mu.vector[i,j]<-vector[i-1,j]
    }
    vector[i,1:2]~dmnorm(mu.vector[i,1:2], omega[1:2,1:2])
}

I'm not entirely sure why it doesn't give a model-check error, so maybe there is a valid way to use <- with vectors/matricies/arrays, but not here at any rate.

share|improve this answer

I disagree with @guy since the "<-" assignment works for matrices.

I think you have to "fill" the matrix mu.vector starting from the first line, you cannot start from the second line. Then type :

 for(i in 2:NPERIODS1){         
    mu.vector[i-1,1:2]<-vector[i-1,1:2]
    vector[i,1:2]~dmnorm(mu.vector[i-1,1:2], omega[1:2,1:2])
    }

I'm not sure because I haven't used WinBUGS since a couple of years. Another possibility is that it does not allow operations on the indices inside the brackets "[...]". If that holds true, then define a vector j such that j[i]=i-1 and type

   for(i in 2:NPERIODS1){         
        mu.vector[j[i],1:2]<-vector[j[i],1:2]
        vector[i,1:2]~dmnorm(mu.vector[j[i],1:2], omega[1:2,1:2])
        }

By the way your code is incomplete (how is vector[1,] defined ?..). Hence this is difficult to help ! The error is possibly due to wrong dimensions when you load initial values or data.

share|improve this answer
Perhaps I was loose with how I phrased it, but it doesn't always do what one would expect it to do. I ran into it by attempting to do A[k, 1:J, 1:J] <- B[1:J, 1:J] * c, and it returned the same error. All the index suggestions you made held in my particular example, and this is completely analogous to the correct syntax for an array of Wishart random variables, A[k, 1:J, 1:J] ~ dwich(B[1:J, 1:J], df). Regardless of how "<-" operator works, my suggestion should fix it. – guy Jul 19 '12 at 6:31
@guy The multiplication of a vector/matrix by a scalar does not work, but the assignement such as in the OP works. – Stéphane Laurent Jul 19 '12 at 6:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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