This is my first time using JAGS and I ran into some errors when modeling my data.
Here is a brief description of my data:
A total of n
people (e.g., 2) each solved m
problems (e.g., 6). All problems have 3 answers, each of a certain value V
.
Here is the graphic model (some variable names are different: IG
and y
are the same as V
and answer
, respectively; x
is not included in my model).
The probability that Person i
chooses each answer for Problem j
follows the "softmax decision rule": exp(V[j,]/tau[i])/sum(exp(V[j,]/tau[i]))
. Here, tau is the noise in decision with a Gamma distribution: tao → 0, a person chooses the answer of the highest value; tao → ∞, a person chooses randomly among 3 answers.
This is my model file model.txt
:
model{
# data
for(i in 1:n) # for each person
{
for (j in 1:m) # for each problem
{
# answer chosen
answer[i,j] ~ dcat(exp(V[j,]/tau[i])/sum(exp(V[j,]/tau[i])))
}
}
# priors
for (i in 1:n)
{
tau[i] ~ dgamma(0.001,0.001)
}
}
Here's my R script:
library(R2jags)
m <- 6 # number of problems
n <- 2 # number of people
V <- matrix(c(0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)), nrow=m, ncol=3, byrow = T)
answer <- matrix(c(2,3,1,1,2,3,1,1,1,1,3,2), nrow=n, ncol=m, byrow = T)
data <- list("m", "n", "V", "answer")
myinits <- list(list(tau = rep(1,n)))
parameters <- c("tau")
samples <- jags(data, inits=myinits, parameters,
model.file ="model.txt", n.chains=1, n.iter=1000,
n.burnin=1, n.thin=1, DIC=T)
After running the script in R, I got the error message below:
Compiling model graph Resolving undeclared variables Allocating nodes Deleting model
Error in jags.model(model.file, data = data, inits = init.values, n.chains = n.chains, : RUNTIME ERROR: Invalid vector argument to exp
What might be the problem? Many thanks for your help!