Dear all,
I was wondering whether I could get some help on a model where I’m trying to include a Jacobian adjustment (which I’ve never done before). The model converges easily, but the results are biased - and always in the same way which makes me think that something is wrong in the model.
The data generation is like this:
a ~ normal(muA,sdA)
b ~ normal(muB,sdA)
control is from list c(0.2,0.5,0.8)
feedback = control*a + (1-control)*b
I give to the model ‘a’ and ‘feedback’ and I want it to estimate muA, sdA and control:
data {
int nrow; // size of my data
int nenv; // number of levels of control
int envID[nrow]; // which control level it is (1,2 or 3)
real feedback[nrow];
real a[nrow];
}
parameters{
real muA;
real<lower=0> sdA;
real muB;
real<lower=0,upper=1> control[nenv];
}
transformed parameters{
real b[nrow];
for (irow in 1:nrow){
b[irow] = (feedback[irow]-control[envID[irow]]*a[irow])/(1-control[envID[irow]]);
}
}
model{
// priors
muA ~ normal(0,5);
muB ~ normal(0,5);
sdA ~ normal(0,1);
// sdB ~ normal(0,1);
for (irow in 1:nrow){
a[irow] ~ normal(muA,sdA);
b[irow] ~ normal(muB,sdA);
// Jacobian adjustment (from Quotient rule)
target += log(fabs((feedback[irow]-a[irow])/(1-control[envID[irow]])^2));
}
}
I am not sure about how I am defining ‘b’ in the transformed parameters and then sampling it in the model and the target+= statement that I’ve added, trying to follow what the handbook says about using the log of the absolute derivative.
Just from the Maths of this problem, I’m quite sure it should be solvable given that the variance of the sum of two normally distributed variables is defined as:
var_sum = (control)^2var_A + (1-control)^2var_B
and in the present version of the model I have set sdB=sdA and variance of the sum (i.e. the feedback) is also known, so this should definitely be solvable, which makes me think that there is a mistake in my model.
(It’s not really relevant but the reason I’ve built this model is that I’m making a model of cognition where I want to estimate how different people can learn these distributions and I wanted to first see whether an ‘optimal observer’ can solve this problem.)
I would be very grateful for any advice.
Best wishes
Jacquie