# Must interacting dichotomous categorical predictors be treated as factors?

If examining the main effects of dichotomous categorical variables, the levels of which are binary and absolute (present/absent), must they be treated as factors rather than numerics?

Would the answer change if also including in one's regression model the interactions between those variables? Notably, when factorized the number of interaction predictors double (in light of additional contrasts, yes?). What gets lost when relying on the numeric * numeric interaction terms in such a model rather than various factor * factor versions of such terms?

I presume factorizing the variables is good form, regardless. However, I'm having difficult wrapping my head around what's differently captured in the interactions of dichotomous numerics vs. dichotomous factors.

I presume the response is a matter of the math, not the software, but if relevant, I am examining the above scenario in R.

Clarification: Note, I understand the mechanical process of factorizing a categorical variable and, in theory when to do it. My question relates more to the math involved when dealing with interactions between such dichotomous categorical variables. In a model containing both main effects and interactions, a model that treats the dichotomous predictors as factors includes additional predictor terms compared to a model in which the predictors are treated as numerics (as the interaction is then represented by multiple factor-level interaction terms and no longer simply a single numeric * numeric interaction term). When comparing these two models, why would the main effect values for these dichotomous predictors change?

dat$$x = as.factor(dat$$x)
dat$$x = relevel(dat$$x, ref = "not present")
Then the coefficient of the present group will be evaluated as the effect of having a condition present compared to not having the condition present on average holding all other covariates constant. Sorry not sure how to include $, between dat and x without it formatting to an equation. Both would give you the same answer in terms of your estimate. Now for interactions of a numericnumeric interaction and factorfactor interactions. When using categorical variables it is important to note that the reference group is swallowed up in the intercept term. Meaning that when the covariates are equal to zero and the disease is not present the expected value of the response variable would be the intercept term on average. So if you have two categorical variables then both reference groups are included in the intercept term. You are not losing any information using a numeric or factor. Since they are doing the same thing. So let's say your other dichotomous categorical variable is whether or not an individual smokes. We then have the categorical interaction model below; $$\hat{y} = \hat\beta_0 + \hat\beta_1(x_{present}) + \hat\beta_2(x_{smokes}) + \hat\beta_3(x_{present})(x_{smokes})$$ Now the reference groups are excluded from the model since they are taken up in the intercept term. This is understood more easily in numerical form. "not present" = 0 and "no smoking" = 0. $$\hat{y} = \hat\beta_0 + \hat\beta_1(0_{not present}) + \hat\beta_2(0_{no smoke}) + \hat\beta_3(0_{not present})(0_{no smoke})$$ Since all coefficients except for the intercept terms are multiplied by 0, the resulting model gives, $$\hat{y} = \hat\beta_0$$. The factor*factor model gives the same resulting model for the reference group. • Thanks for response. Note, I understand the mechanical process of factorizing a categorical variable and, in theory when to do it. I suppose my question relates more to the math involved when dealing with interactions between such dichotomous categorical variables. I've edited the original post to elaborate/clarify. Apr 30, 2021 at 23:36 • I updated my comment, sorry I skimmed over the interaction part! Apr 30, 2021 at 23:47 • Very helpful, thanks. However, I realize now my confusion stemmed from me examining three-way interactions between three dichotomous predictors. In that case, shifting from numerics to factors does appear to make a difference, as each three-way interaction is represented through two separate model terms for factors (one for each level of the first variable, with reference levels identical for variables 2 and 3). For instance, something like$(0_{notpresent})(0_{nosmoke})(0_{nodiet})$and$(x_{present})(0_{nosmoke})(0_{nodiet})\$. Might you be able to lend insight into why this is the case? May 4, 2021 at 21:25