Hi,
I am building a FHMM with R and OpenBUGS and am having a problem.
Here is my BUGS model:
###### begin Code ######
# M=3, K=2, N=100 in my test
model <- function() {
for( m in 1:M ) {
s[m,1] ~ dcat(pi[m,1:K])
for( i in 2:N ) {
s[m,i] ~ dcat(trans[s[m,i-1],1:K,m])
}
}
for( m in 1:M ) {
for( i in 1:N ) {
mu0[m,i] <- mu[m,s[m,i]]
sigma0[m,i] <- 1/tau[m,s[m,i]]
}
}
for( i in 1:N ) {
mm[i] <- sum(mu0[1:M,i])
tt[i] <- 1/sum(sigma0[1:M,i])
y[i] ~ dnorm(mm[i],tt[i])
}
}
##### end Code #####
OpenBUGS keeps giving me this "index out of range error" when it tries to update s[1,2].
While debugging, I found that s[1,1] is 0, and thus causing an illegal indexing into trans[].
But I don't know why dcat for s[,1] was not working properly.
I also tried the following model in which I manually create s1~s3 instead of s[m,].
Although pretty silly, it worked without problem.
##### begin Code #####
# K=2, N=100
model <- function() {
s1[1] ~ dcat(pi1[1:K])
s2[1] ~ dcat(pi2[1:K])
s3[1] ~ dcat(pi3[1:K])
for( i in 2:N ) {
s1[i] ~ dcat(trans1[s1[i-1],1:K])
s2[i] ~ dcat(trans2[s2[i-1],1:K])
s3[i] ~ dcat(trans3[s3[i-1],1:K])
}
for( i in 1:N ) {
sigma1[i] <- 1/tau1[s1[i]]
sigma2[i] <- 1/tau2[s2[i]]
sigma3[i] <- 1/tau3[s3[i]]
mu[i] <- mu1[s1[i]]+mu2[s2[i]]+mu3[s3[i]]
tau[i] <- 1/(sigma1[i]+sigma2[i]+sigma3[i])
y[i] ~ dnorm(mu[i],tau[i])
}
}
##### end Code #####
I am new to BUGS and your help would be really appreciated.
Thanks in advance.
-------------------------------------------------------------------
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
|