I have:
mu_x - a 10x10 matrix of real values
ptype - a 10000 long vector
sender_name_type - a 10000 long vector
I'd like to find the values of
x_real - a 10000 long vector
The code I currently have, and works, is:
for(i in 1:N){
if(x_available[i]){
x_real[i]~normal(x[i],0.01);} else{
x_real[i]~normal(mu_x[ptype[i],sender_name_type[i]],0.1);
}
}
I'd like however, to vectorize it. To do that, I'd first need to deal with the if clause. To do that, I tried just adding two distributions, like so:
x_real ~ normal(mu_x[ptype,sender_name_type],0.1) * (1-x_avaiable) + normal(x,0.01) * x_available;
However, Rstan seems to not handle adding/multiplying distributions. The second approach I tried was like so:
x_real ~ normal(mu_x[ptype,sender_name_type],0.1);
x_real[x_available == 1] ~ normal(x,0.01);
Which is similar to the first approach, but it redefines the rows of x_real, for which the condition is met. However, it gives me the error of
No matches for:
real[] ~ normal(matrix, real)
How can I vectorize my current solution, if possible? Are there any other ways I could speed it up?