# In Linear regression is it possible to have same sign coefficients for dummies coming from the same variable?

So I have a categorical variable color which can take the values white, black, red.

I created dummy variables for each of those colors and the related coefficients for all of those dummy variables is negative.

I wonder how is this possible, what would be the baseline here?

EDIT: y variable is price, using sklearn.linear_model.LinearRegression coupled with pandas.get_dummies

• what is your y variable? what code/data are you using? Feb 20, 2019 at 12:36
• See edit Im using sklearn and pandas the y variable is price. Feb 20, 2019 at 12:59

This is no problem. Intuitively, if you include all three categories, their coefficients "absorb" the intercept, which might be negative.

• The intercept is positive, and all the coefficients are negative. Feb 20, 2019 at 11:52

Yes, the intercept is the base level, and the coefficient of each color is relative to that base level. Here is a short example in R. relevel allow to decide which level of the factor will be used as the base line.

library('dplyr')

> col <- factor(sample(c('red', 'blue', 'white'), n, replace = TRUE))
>
> y <- case_when(col == 'red' ~ 30,
+                col == 'blue' ~ 80,
+                col == 'white' ~ 115) + rnorm(n, 0, 5)
>
>
> col <- relevel(col, 'red')
> lm(y ~ col) ### coefficients will be positive

Call:
lm(formula = y ~ col)

Coefficients:
(Intercept)      colblue     colwhite
29.84        50.02        86.14

>
> col <- relevel(col, 'blue')
> lm(y ~ col) ### coefficients will be positive and negative

Call:
lm(formula = y ~ col)

Coefficients:
(Intercept)       colred     colwhite
79.86       -50.02        36.12

>
> col <- relevel(col, 'white')
> lm(y ~ col) ### coefficients will be negative

Call:
lm(formula = y ~ col)

Coefficients:
(Intercept)      colblue       colred
115.98       -36.12       -86.14


Example when all the coefficients are negative (notice there is no intercept)

> y <- case_when(col == 'red'   ~ -30,
+                col == 'blue'  ~ -80,
+                col == 'white' ~ -115) + rnorm(n, 0, 5)
>
> lm(y ~ 0 + col) ### coefficients will be negative

Call:
lm(formula = y ~ 0 + col)

Coefficients:
colwhite   colblue    colred
-115.75    -80.30    -30.24

• But in this case you have one of the levels as the baseline, in my case all the levels have negative coefficients. Feb 20, 2019 at 11:53
• If you have an intercept in the model, then one of the factors level is absorbed by it (notice in the example that the intercept value is similar to that of the level). Ill add an example in the answer. Feb 20, 2019 at 11:58
• Thanks for the example, but in my particular case, in sklearn implementation in Python, there is an intercept which is positive, and at the same time there is a coefficient for each of the variables, which are all negative. Feb 20, 2019 at 12:09