# For a logistic regression, how to include continuous independent variable that also depends on binary independent variable?

Hi trying to better understand the statistical approach for the below problem. We'd like to build a logistic model (binary outcome) with two independent variables: one binary and the other continuous.

The tricky part is that the continuous variable is dependent on the binary variable. To clarify I'll use an example regarding detecting cancer on mammograms. Say that:

• The binary variable is "calcifications, yes or no?" (i.e., are there calcifications on mammogram?)
• The continuous variable is "size of calcifications" (i.e., given there are calcifications present, the size of calcifications observed)
• Dependent variable = Cancer or not cancer (i.e., what we'd like to predict with the above)

In this example, the presence of calcifications lends its own probability of cancer/no cancer, but if present, we can further refine the probability of cancer based on the size of calcifications.

Not sure if this requires two models, whose outputs are the combined in some way? or if this can be incorporated into a single model? Here to ask the community how best to approach this problem...

Apologies if this is a redundant question-- I'm struggling to find this scenario through searches.

• Welcome to cv, AStar! It is a good question to ask when you do such analyses. Have a look at this question - does it answer yours? You can run one model or two separate ones - maybe that is the main question here
– Ute
Commented Jul 25, 2023 at 20:07
• Thanks! Yes I'm more trying to figure out how to best accomplish incorporating a continuous variable that only exists when a binary variable (also in the model) is =1. Appreciate the help! Commented Jul 26, 2023 at 15:19

There are several possible options, but here is one I might try first:

$$\Pr(\text{Cancer} = 1)=\Lambda(\alpha + \beta \cdot \text{has_calcification}+\gamma \cdot \text{calcification_size}),$$

where $$\text{calcification_size}$$ is set to zero for those with $$\text{has_calcification}=0$$ and $$\Lambda()$$ is the inverse logit function.

In this case, if someone has no calcification, the probability of cancer is just $$\Lambda(\alpha)$$.

If someone has calcification, then it becomes $$\Lambda(\alpha + \beta +\gamma \cdot \text{calcification_size})$$. This allows calcification to have two effects: one from having any calcification, which is then modified by the size. It's possible that one of these calcification coefficients could be zero.

A more parsimonious specification would drop $$\text{has_calcification}$$ from the model if this makes sense given domain knowledge. I would also use this if there was relatively little variation in calcification size for those with calcification.

• Thanks! This is super helpful. Commented Jul 26, 2023 at 15:20