I am doing an ordinary least squares regression (in python with statsmodels) using a categorical variable as a predictor. There are 5 values that the categorical variable can have. However, after running the regression, the output only includes 4 of them.

Here is what I am running:

>>> from statsmodels.formula.api import ols
>>> model = ols("normalized_score ~ C(general_subreddit)", data=df_feature)
>>> results = model.fit()
>>> results.summary()

The output of the last command includes the following rows in the table: ols output

I can check the count of each of the categorical variables as follows:

>>> from collections import Counter
>>> Counter(df_feature["general_subreddit"])
Counter({nan: 20,
     'community': 4159,
     'ending_addiction': 3819,
     'mental_health': 4650,
     'other': 6920,
     'relationships': 4318})

Ignoring the NaNs, why does the categorical value of "community" not appear in the model summary?


1 Answer 1


When a logistic model is built using a categorical variable with N levels, it only considers N-1 levels, as the remaining level is used as a reference by the model.

What this means to your model as a whole is that, each level (when remaining variables remain same) is compared to the reference level.

In your example, "community" level is used as the reference. So, ending_addiction contributes 0.0749 units more than "community" to the dependent variable.

Hit this up if it's not clear --> https://community.alteryx.com/t5/Alteryx-Designer-Discussions/In-the-Logistic-Regression-Report-Factor-Missing/m-p/10100/highlight/true#M5169


Your Answer

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

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