# Help with JAGS model using matrix multiplication and Dirichlet prior [closed]

I want to set up a simple JAGS model using matrix multiplication, but I am not sure how to set up the matrices. My overall equation is $c=yx$ where $c$ is a 2x1 matrix defined in R of observed data values, $y$ is a 2x2 matrix of prior distributions, and $x$ is a 2x1 matrix of values to be estimated with the prior of the Dirichlet distribution.

Here is my model file:

model{

c[] ~ dnorm(mu[],tau)
mu[] <- y[,] %*% x[,]

y[1,1] <- mN
y[1,2] <- fN
y[2,1] <- mO
y[2,2] <- fO

# priors
tau ~ dunif(0,1)
x ~ ddirch(alpha[1:2])
# d15N manure and septic source
mN ~ dunif(0,25)
# d15N fertilizer source
fN ~ dunif(-10,5)
# d18O manure and septic source
mO ~ dunif(-20,25)
# d18O fertilizer source
fO ~ dunif(-20,25)
}


When I try to compile this model I get the error:

Dimension mismatch in subset expression of c

• Try to change c[] to c[,] and/or mu[] to mu[,], and see if any of the changes help. I've run into this problem before, and I believe this is what I had done. Mar 5, 2014 at 7:20
• You could also try defining the stochastic nodes (nodes defined with ~) 1 element at a time (use a for() loop) Mar 5, 2014 at 16:27
• Thanks all, the for loop approach worked for me. I changed my code to calculate the stochastic notes in c individually. I also changed c in my R code to be a numeric vector. for(i in 1:n){ c[i] ~ dnorm(mu[i],tau) mu[i] <- inprod(x[1:3],y[i,]) } Mar 6, 2014 at 1:00