Conditional hyper parameters using Rethinking package

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(
    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)))
1 Like

I am not very familiar with the rethinking interface, it might make sense to inspect the generated Stan code to see better what is actually happening.

In any case the way one would usually do this would be to build a linear predictor for rMu, so I would expect you might need something like:

rMu <- rMuIntercept + rMuGroup2 * isGroup2[ID],
rMuIntercept  ~ suitable prior for rMu in GRoup 1
rMuGroup2  ~ suitable prior for difference in rMu between the groups

where isGroup2 is an array where you put 0 for subjects in Group1 and 1 for subjects in Group2 (also known as “dummy coding”.

Would that resolve your issue?