0
$\begingroup$

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?

$\endgroup$

1 Answer 1

1
$\begingroup$

If you are going to use a numerical representation using 0 or 1 you do not need to factor the categorical variable. When the value of the categorical variable is 0 then you have created your reference group (because 0 x beta = 0) so the beta of the categorical variable when x= 1 will be interpreted as the effect of having a condition present compared to the reference group (not present) on average holding all else constant.

If you do not want to use 0 or 1 then yes you need to have your categorical variable set as a factor, and it helps to specify which factor is your reference factor. You can use the following code to specify your reference group for your factor variable.

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.

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – jjcii
    Apr 30, 2021 at 23:36
  • 1
    $\begingroup$ I updated my comment, sorry I skimmed over the interaction part! $\endgroup$
    – Hunter M.
    Apr 30, 2021 at 23:47
  • $\begingroup$ 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? $\endgroup$
    – jjcii
    May 4, 2021 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.