# Multiplying Logits

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

I’m not sure I quite understand your model here unfortunately.

So where you have:

G_1=\alpha_2 + b_{sex} * sex + b_{Q1} * Q1 + b_{Q2} * Q2

Which corresponds to:

bernoulli_logit(alpha2 + b_sex * sex + b_Q1 * Q1 + b_Q2 * Q2)


And similarly for G_2, does this imply that G_1 and G_2 are binary observed variables, or binary parameters?

Then, where you have:

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)}

What kind of model is this aiming to represent? For example, is this is a regression where G_1 and G_2 are predictors or something else?

Thanks for the response!
Im trying to do a sort of “Custom” model.
I just used G_1 and G_2 as auxiliary variables for those values.
In particular Im working with a dataset such that some of the data points have values for Q_1 and Q_2 (those where a variable named Condition is equal to 1, while the others have values NaN for those columns.
On the other side all of my datapoints have values for QE_1 and QE_2.

What Im trying to do with the full equation is predict the result of a variable given those two scenarios.
Therefore my first Logit represents the probability given by those data points that meet the condition, and the second term in the addition corresponds to the probability given by all datapoints (given that the condition is not met)
That is why coincidentally the second term in the addition has that 1-\frac{exp(G_1)}{1+exp(G_1)}

It seems like im trying to do a composition or multiplication of classical “Logit” models that takes into consideration the fact that I have two scenarios that can occur.

So for example, If I did not have this condition, then my model would be a simple logistic regression where G_2 represents what you would put inside the bernoulli_logit stan offers, but since I have the condition, then I need to add the other logit as another term and multiply my current one by the term you see above.

I hope that makes my problem a little clearer, again thanks for the response!!!