Hi Sarah,
The code suggests that y is the data matrix with n rows and item=4 columns. Now, for your problem, y has n rows but differing number of items for each row. Here is the recipe I usually employ in such cases. This needs some data preparation that I will do in R.
1. Construct n.items as the vector containing n "item" values and find the maximum of this vector, i.e.
max.n.items <- max(n.items)
2. Define the matrix y as having n rows and max.n.items columns
y <- matrix (NA, nrow=n, ncol=max.n.items)
Note that, currently y is a matrix of missing values only.
3. Fill in y with your data, which I assume that currently sit in a list, say list.data, having n elements. Element i of list.data is the data vector for the ith observation with number of items equal to n.items[i]. Here is how you fill in y:
for (i in 1:n){
y[i,1:n.items[i]] <- list.data[[i]]
}
Note that, in ith row of y, first n.itmes[i] entries are data values and rest are missing values (NA). However, these missing values play no role in the model defined below.
4. Now, use the following modified code:
model {
for(i in 1:n){# n is the number of obs
for(item in 1:n.itmes[i]){
logit(Z[i, item, 1]) <- alpha[item, 1] - beta[item]*x[i]
logit(Z[i, item, 2]) <- alpha[item, 2] - beta[item]*x[i]
Pi[i, item, 1] <- Z[i, item, 1]
Pi[i, item, 2] <- Z[i, item, 2] - Z[i, item, 1]
Pi[i, item, 3] <- 1 - Z[i, item, 2]
y[i, item] ~ dcat(Pi[i, item, 1:3])
}
x[i] <- mu[country[i], year[i]]
}
sigma ~ dunif(0,1)
kappa <- pow(sigma, -1)
for(c in 1:n.country){
mu[c, 1] ~ dnorm(0, 1)
for(t in 2:n.year){ #n.year is number of years
mu[c, t] ~ dnorm(mu[c, t-1], kappa)
}
}
for(j in 1:4){
beta[j] ~ dgamma(4, 3)
alpha0[j, 1] ~ dnorm(0, .25)
alpha0[j, 2] ~ dnorm(0, .25)
alpha[j, 1:2] <- sort(alpha0[j, 1:2])
}
}
---------------------------------------
Khurram Nadeem
Postdoctoral Research Fellow
Department of Mathematics & Statistics
Huggins Science Hall
Acadia University
WolfVille, Nova Scotia, B4P 2R6 CANADA.
-------------------------------------------------------------------
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
|