Dummy variable trap.
Last time we learned how to create dummy variables
to replace our categorical predictor estate in the model, we also discussed
that you can never include both dummy variables at the same time.
In our example, we omitted the California dummy.
Now why is that?
What will happen if we include the second dummy variable in the model as well?
Let's see.
The intuition here is that you're basically duplicating a variable.
This is because D2 always equals to one minus d1.
The phenomenon where one or several independent variables
in a linear regression predict another is called multicollinearity.
As a result of this effect, the model cannot distinguish between
the effects of D1 from the effects of D2, and therefore it won't work properly.
And this is called the dummy variable trap.
If you do the math behind the scenario, you will see that
the real problem is that you cannot have these three elements
in your model at the same time the constant and both the dummy variables.
I will leave it up to you to figure this one out on your own,
and let me know if you have any trouble.
I'll definitely help you out.
So to sum up, whenever you're building a model, always omit one dummy variable.
And this applies irrespective of the number of dummy variables
they are in that specific dummy set.
If you have nine, then you should only include eight.
If you have 100.
Then you should only include 99 of them.
Also note that if you have two sets of dummy variables,
then you need to apply the same rule to each set.
For instance, we could have had a column which specifies
the industry in which the companies operate.
To build the model.
In that case, we would have had to perform exactly the same steps and create
another set of dummy variables specifically for that column.
And then we would include all but one of those dummy variables in our actual model.
I hope this explanation was useful, and you will never fall
victim of the dummy variable trap in your modeling.
Next time we're going to cover the different ways you can build a model.
We will learn all about backward elimination,
forward selection, stepwise regression, and much more.
It's going to be an exciting tutorial and I look forward to seeing you then.