# Why is my categorical variable split up into separate variables in my regression model in r

I'm creating a multivariate model in R right now.

When I plot categorical variables into the lm() function and check the summary() output, my categorical variable gets split up into a beta coefficient for each option inside of the variable.

When I checked the data type it came back as a factor variable, here is the output of summary to visualize the issue easier.

• Each category is modeled as the difference between it and a reference category (the intercept). Iif you 5 categories, you need 4 coefficients to model those 5 means. Nov 29, 2019 at 19:54
• I'm finding it hard understanding this from a more traditional numeric variable regression. I figured the variable would have a constant number next to the coefficient to fit for whatever the beta value would be.
– Freddy Haug
Nov 29, 2019 at 20:07
• See e.g. here or here. R basically automatically expands your factor into binary dummy variables. Nov 29, 2019 at 20:18
• If you want a global "test" for your factor (as in an ANOVA) you can use for example drop1 that basically compare the model with and without the factor as explanatory variable. For example : m <- lm(Sepal.Length ~ Species, data = iris) ; drop1(m, test = "F") Nov 29, 2019 at 20:27
• In R, it's also common to car::Anova to get a traditional anova table (with type ii sum of squares by default). To use @Gilles ' example: if(!require(car)){install.packages("car")}; m = lm(Sepal.Length ~ Species, data = iris); library(car); Anova(m) Nov 30, 2019 at 15:50