Is one-hot encoding required for a binary categorical variable? We are performing multiple linear regression.
Dataset:

*

*let's call the response Y and the predictors X1, X2 and X3,

*where Y, X1, X2 are continuous, whereas X3 is binary categorical variable (i.e. it can take either two values, 1 or 2).

Now, we have two choices

*

*Choice #1: Without one-hot encoding of X3

*

*i.e. Linear regression on raw variables lm(Y ~ X1 + X2 + X3)



*Choice #2: With one-hot encoding of X3

*

*i.e. X3 is one-hot encoding in [X3a, X3b]

*e.g. Possible values: [1, 0] and [0, 1]

*Hence, the linear regression model is lm(Y ~ X1 + X2 + X3a + X3b)
Question:
Since X3 is a binary variable, whether or not we one-hot encode (i.e. Choice#1 or Choice#2), will it make any difference (especially in terms of the model's loss)?

@Tim,
I think both would give same performance because:

*

*Rationale#1:Mathematically, there's enough room for parameter to adjust (to give same y value).


*Rationale#2: Computationally, we get the same explanatory power (i.e. R^2 value). Minimal reproducible example:

# Read Data
data("mtcars")
data <- mtcars
attach(data)

# Model 1: My Model
am_new <- am+1
model_1_my <- lm(mpg ~ am_new)
print(summary(model_1_my))        # Output: R-squared:  0.3598

# Model 2: Tim's Model
model_2_tim <- lm(mpg ~ am)
print(summary(model_2_tim))       # Output: R-squared:  0.3598   (again)

