Today we're talking about dummy variables.
So basically the information that we have is the profit
of each, company or of each startup.
Then the R&D spend, the admin spend, the marketing spend.
So those three are expenses that the company incurred
and then the state in which it operates, either in New York or California.
The challenge that we're faced with is that the venture capitalist
fund wants to see if there's any correlations between profit
and the amounts that have been spent on,
different expenses, R&D, admin and marketing, and also,
whether on which in which state the company operates.
So is there a correlation between profit and, all of these variables?
And how would you go about creating a model to understand
how knowing R&D spend admin and marketing and state to predict profit.
And so therefore profit is our dependent variable
and the rest, the blue ones, are all independent variables.
And what we need to do is build a linear regression.
So let's go ahead and get started.
As we would with multiple linear regression.
We would start by saying y which is profit is equal to what.
What is it equal to.
Well, first of all, there's a constant.
In this case it's b zero.
And I've put it under the profit column just because I needed to fit it somewhere.
And then we would start adding on these, variables into our equation.
So then we've got the b1 coefficient times the X1 variable
which is R&D spend in this case.
And x1 is actually the amount, the dollar amount that you see in the R&D column.
Then you've got the admin.
variable which is x2.
It's got a coefficient of B2. Once again admin.
So in this case x2 is going to be the dollar amount you see in the admin column.
Then you've got the marketing spend
x3 which will be the dollar amount you see in the marketing column.
And then you've got the state variable.
And here when we get here we're questioning
what should we place in our equation for the state column.
Because we don't actually have a number, we don't have a dollar value
or any other type of number to add into our equation.
We can't just add a word into our equation.
And the thing here is that the state is actually a categorical variable.
So we talked about types of variables before.
And we understood that
there's categorical variables and there's numeric variables.
Well in this case state is a categorical variable.
And therefore we can't add it to our equation.
We need to do something about this situation
and the approach that you need to take when you face categorical variables
in regression models is you need to create dummy variables.
Let's see how we we can do that.
First you need to go through your column and find all the different categories
you have. So in this case we have two categories.
So for every single category that you found you need to create a new column
for New York.
We're going to create a column called New Yorker for California.
We're going to create a column California.
So we're kind of expanding our dataset and adding some additional columns into it.
And how do we populate the columns.
So this is the fun part
to populate these columns, let's start with the New York column.
You need to find all of your rows where state actually says New York,
and you need to.
For those rows, you need to put a one in the New York column and then in California
and for all the rows that say, California, basically for all the rows
that don't say New York, whatever else they say, you just put a zero.
And then for California, for the column California,
you do the same thing wherever a row says California.
In the state column, you place a one in the California column.
And for any other values in the state
column, you place a zero in the California column.
And so you end up with a data set like this.
And these two new columns are called dummy variables.
And building your regression model from here is very simple.
All you have to do is use the New York column,
and you're going to be using it instead of states.
You're not going to be using state anymore.
And basically you add a variable which is B4 times D1
and D1 in this case is your dummy variable for New York.
And you don't use the California column either.
So as you can see here, all of the information in our data is preserved.
If we just stick to the One New York column, because you can tell right away
if D1 is a one, then it's a company that works in it operates in New York.
If D1 is a zero, it's a company that operates in California.
So we didn't lose any information by including only the New York column.
And we will actually talk more about why you should never include
all of your dummy variable columns in your regression model.
We'll talk more about that in the, next tutorial when we're talking
about the dummy variable trap.
But for now I would like to discuss two things.
So first of all,
the New
York column or all of the dummy variables they work as switches.
In this case.
Let's look at the New York column, which we're including in our regression.
It works like a light switch.
So if it's a one then you know that this company is in New York
if it's a zero.
So off in this case,
in the case of the picture, then you know that the company doesn't work
in New York options.
So the dummy variables work like light switches.
And that's why they're ones and zeros and they don't need any other values in them.
And the second thing is that when you look at this approach, it might seem biased.
So we are including a variable for New York.
And there's a coefficient for new.
So we basically have this benefit of having
a coefficient in our equation for New York which is before.
But for California there's no coefficient because when D1 is zero,
that whole last part of the equation becomes zero.
And there's no benefit of a coefficient in our equation for California
and might seem biased at first, but in reality, that's not the case
because the way regression models work is that they will take by default
that state or that variable, that dummy variable that you have not included.
It will become the default situation for this regression model.
So basically what that means is that the coefficient for California
is going to be included in the constant in B0.
And by default when d1 is equal to zero,
this whole equation will turn into an equation.
You can think of it as it'll turn into an equation for California.
But then when d1 becomes one, you're adding B4,
which is once again like this is a very basic explanation,
but you're adding a coefficient, which is the difference
between New York and California.
So so basically
you'll altering from California to New York by flipping this light switch.
If it's on or off, then kind of default state.
And the whole equation is working for California.
If it's on on, then by adding that before you're altering the equation
from the default state of California to New York.
So that's a intuitive way to think of dummy variables.
So there's nothing wrong with the fact that we're only including one.
And once again, in the next tutorial, we'll talk more about why
it is a bad idea to ever include both dummy variables.
I'll look forward to seeing you next time until then, happy analyzing.