The code below uses the Rethinking package in R to fit a multilevel model to simulated decision making data for a group of individuals. It estimates “noise” and “riskTol” posterior distributions for each unique ID, as well as the distributions from which they are themselves drawn. It works perfectly with simulated data, recovering the noise and riskTol values used to simulate the choice data, as well as the distributions from which the noise and riskTol values were drawn for the simulation.
Here’s my question: I want to model a situation in which the riskTol values were drawn from two separate distributions. Basically, I need rMu in the model to vary depending on whether individual ID comes from group 1 or group 2. I tried a bunch of different things to add a group cluster (e.g., rMu[group]) but nothing seems to work. I keep getting this error: Random variable has dimension = 100, expecting dimension = 10000
Any suggestions? Apologies in advance if it is not clear what I am attempting to do.
fitLotto_MLVL <- ulam(
alist(
choice ~ dbinom( 1 , p ) ,
logit(p) <- (uLotto - uRef)/noise[ID] ,
uRef <- refValues^riskTol[ID]*refProbabilities ,
uLotto <- lotteryValues^riskTol[ID]*lotteryProbabilities ,
riskTol[ID] ~ dlnorm(rMu,rSig) ,
rMu ~ dnorm(-.3,.3) ,
rSig ~ dexp(1) ,
noise[ID] ~ dlnorm(nMu,nSig) ,
nMu ~ dnorm(0,.3) ,
nSig ~ dexp(1)
) , data=dat_list, iter=numIter, control = list(adapt_delta=0.99), chains=4,
start = list(riskTol=rep(.5, numsubjs), noise=rep(1, numsubjs)))