data{
int <lower=0> J; // number of components in the pool
int <lower=0> K; // K interaction
matrix<lower=0,upper=1>[K, J] prior_activity;
matrix<lower=0,upper=1>[K, J] prior_qed;
matrix<lower=0,upper=1>[K, J] prior_sa;
matrix<lower=0,upper=1>[K, J] observed_activity; // observed activity scores
matrix<lower=0,upper=1>[K, J] observed_qed; // observed qed scores
matrix<lower=0,upper=1>[K, J] observed_sa; // observed sa scores
int <lower=0> advice [K];
int <lower=0, upper=1> decision[K];
}
parameters{
simplex[3] w; // weights for activity, qed, sa
real<lower=1,upper=4> beta1; // bias parameter in prior knowledge
real<lower=10,upper=40> beta2; // bias parameter in prior knowledge
}
transformed parameters{
real <lower=0, upper=1> prob[K];
// for (i in 1:K){
// if(prior_choice[i]!=advice[i]){
// prob[i]=switch_prob[i];
// }
// else{
// prob[i]=1;
// }
}
model {
w ~ normal(.5, .15);
beta1~uniform(1,4);
beta2~uniform(10,40);
decision~bernoulli(prob);
}
generated quantities{
matrix<lower=0,upper=1>[K, J] prior_scores=w[1]* prior_activity+ w[2]*prior_qed + w[3]* prior_sa;
matrix<lower=0,upper=1>[K, J] observed_scores= w[1]*observed_activity+w[2]*observed_qed+ w[3]*observed_sa;
vector<lower=0,upper=1>[J] prior_prob;
vector<lower=0,upper=1>[K] switch_prob;
// real <lower=0, upper=1> prob[K];
real logits;
int prior_choice[K];
for (i in 1:K){
prior_prob=softmax(to_vector(prior_scores[i]*beta1));//socres in i-th interaction
prior_choice[i]=categorical_rng(prior_prob);
logits=observed_scores[i,advice[i]]- observed_scores[i,prior_choice[i]];
switch_prob[i]=exp(logits)/(1+exp(logits));
if(prior_choice[i]!=advice[i]){
prob[i]=switch_prob[i];
}
else{
prob[i]=1;
}
}
I want to model decisions based on some prior and observations. There are 3 parameters w transformed priors and observations to prior score and observation scores. Based on prior score, there is a prior choice using softmax function. Then, either or not to switch prior choice to advice depends on observation score. Now, the final decision to take prior choice or advice will depends on switch probability. The decision is assumed under a bernoulli distribution with a probability prob.
Now, my problem is I don’t know where should I define parameter prob. If I define prob in transformed parameters, then it is not allow to generate a categorical variate and define int variate. If I define prob in generated quantities, then I can’t use prob in the model. How should I organise the code to make it right?