Hi,
Last month I posted a question about how to handle AR(p) models in BUGS. I
got several responses and here is one way to proceed:
1)I found this to work, though it might not be optimal: in case of an AR(4)
model, write for example:
%model{for (i in 5:n){
% y[i]~dnorm(mu[i],tau)
% mu[i]<-beta+phi1*y[i-1]+phi2*y[i-2]+phi3*y[i-3]+phi4*y[i-4]
% }
and then specify priors on the first 4 observations (you can specify a
normal distribution, centered around the true value, with very high
precision). This can actually be considered as specifying the full
likelihood: write P(y(1),...y(n))=P(y(1),...y(4))*P(y(5)|y(4),...y(1))*P(y
(6)|y(5),...y(2)), etc. In the code given above, the first 4 observations
are independent in the likelihood, which might be inappropriate in a time
series setting
2) a solution to the above problem can be given by the following code,
kindly supplied by Ralph Silva:
model{
mu[1]<-theta[1]*ya+theta[2]*yb+theta[3]*yc+theta[4]*yd
y[1]<-dnorm(mu[1],tau)
mu[2]<-theta[1]*y[1]+theta[2]*ya+theta[3]*yb+theta[4]*yc
y[2]<-dnorm(mu[2],tau)
mu[3]<-theta[1]*y[2]+theta[2]*y[1]+theta[3]*ya+theta[4]*yb
y[3]<-dnorm(mu[3],tau)
mu[4]<-theta[1]*y[3]+theta[2]*y[2]+theta[3]*y[1]+theta[4]*ya
y[4]<-dnorm(mu[4],tau)
for (i in 5:N){
mu[i]<-theta[1]*y[i-1]+theta[2]*y[i-2]+theta[3]*y[i-3]+theta[4]*y[i-4]
y[i]<-dnorm(mu[i],tau)
}
ya ~ dnorm(0,0.001)
yb ~ dnorm(0,0.001)
yc ~ dnorm(0,0.001)
yd ~ dnorm(0,0.001)
...
# prior for theta and tau
}
Here, there is obviously more dependence: y(2) depends on y(1), y(3)
depends on y(2) and y(1), etc. Additional variables ya, yb, yc and yd are
introduced in this scheme.
Hope this helps. Please let me know if you have any suggestions!
Best,
Martijn van Hasselt
Brown University
Department of Economics
-------------------------------------------------------------------
This list is for discussion of modelling issues and the BUGS software.
For help with crashes and error messages, first mail [log in to unmask]
To mail the BUGS list, mail to [log in to unmask]
Before mailing, please check the archive at www.jiscmail.ac.uk/lists/bugs.html
Please do not mail attachments to the list.
To leave the BUGS list, send LEAVE BUGS to [log in to unmask]
If this fails, mail [log in to unmask], NOT the whole list
|