Hi,
Im trying to run a model that has only binary values in my dataframe, such that if:
G_1=\alpha_2 + b_{sex} * sex + b_{Q1} * Q1 + b_{Q2} * Q2
and
G_2=\alpha_1 + a_{sex} * sex + a_{QE1} * QE1 + a_{QE2} * QE2
Then:
Result \sim \frac{\exp(G_1)}{1+\exp(G_1)} + (1-\frac{\exp(G_1)}{1+\exp(G_1)}) \cdot \frac{\exp(G_2)}{1+\exp(G_2)}
This can be seen as the combination of two Logit models which I wrote this way to express better the question, but as you will see in the stan code below, I used “bernoulli_logit” as the way to make it work.
Here I am using the same dataframe, but values in G_1 are those who meet a binary Condition.
And so,Instead of separating the dataframe into the total and the ones in which the condition is met; I thought of multiplying all values in G_1 by the “Condition” as you will see in the following model.
m1 <- '
data {
int<lower=0> N; //number of observations
int<lower=0,upper=1> result[N];
vector[N] sex;
vector[N] QE1;
vector[N] QE2;
vector[N] Q1;
vector[N] Q2;
vector[N] Condition;
}
parameters {
real alpha1;
real alpha2;
real a_sex;
real a_QE1;
real a_QE2;
real b_sex;
real b_Q1;
real b_Q2;
}
model {
alpha1 ~ normal(0,100);
alpha2 ~ normal(0,100);
a_sex ~ normal(0,100);
a_QE1 ~ normal(0,100);
a_QE2 ~ normal(0,100);
b_sex ~ normal(0,100);
b_Q1 ~ normal(0,100);
b_Q2 ~ normal(0,100);
result ~ Condition*bernoulli_logit(alpha2 + b_sex * sex + b_Q1 * Q1 + b_Q2 * Q2) + (1-Condition*bernoulli_logit(alpha2 + b_sex * sex + b_Q1 * Q1 + b_Q2 * Q2))*bernoulli_logit(alpha1 + a_sex * sex + a_QE1 * QE1 + a_QE2 * QE2 ) ;
}
generated quantities {
real y_hat;
y_hat <- 0.5*inv_logit(alpha2 + b_sex * 10 + b_Q1 * 10 + b_Q2 * 10 ) + (1-0.5*inv_logit(alpha2 + b_sex * 10 + b_Q1 * 10 + b_Q2 * 10 ))*inv_logit(alpha1 + a_sex * 10 + a_QE1 * 10 + a_QE2 * 10 );
}
'
This is giving me the following Error
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
error in 'model19c94397024c8_236aab19ab785550c469da10762b0549' at line 39, column 12
-------------------------------------------------
37:
38:
39: result ~ Condition*bernoulli_logit(alpha2 + b_sex * sex + b_Q1 * Q1 + b_Q2 * Q2) + (1-Condition*bernoulli_logit(alpha2 + b_sex * sex + b_Q1 * Q1 + b_Q2 * Q2))*bernoulli_logit(alpha1 + a_sex * sex + a_QE1 * QE1 + a_QE2 * QE2 ) ;
^
40: }
-------------------------------------------------
PARSER EXPECTED: <distribution and parameters>
Error in stanc(file = file, model_code = model_code, model_name = model_name, :
failed to parse Stan model '236aab19ab785550c469da10762b0549' due to the above error.
I would love to get some help in how can I multiply logit models which is what I understand is creating the problem