Great to see you back here.
And today we're going to look at the handy trick
that will help your models become more robust.
Before we continue, though, I wanted to quickly recap on what we did last time.
And what we did is we used the backward elimination method
to construct a multiple linear regression using our data.
And through that method we constructed four separate models.
You can see them on the back in the background here.
So model 123 and then four.
And when we go to model four we were only left with one
independent variable spent on research and development
because all of the other ones were eliminated.
And basically we completed the backward elimination process.
However, we were left with kind of a feeling
that maybe we shouldn't have excluded the last variable.
And why is that? Well.
First of all, we saw that this p value is not that much bigger than,
the significance level that we selected.
We select a significance level of 0.05.
The p value here is 0.06.
So just a bit greater than the threshold.
So that kind of leaves us with a feeling
maybe we shouldn't have excluded that variable.
The problem here is that this,
these methods, these stepwise regression methods, they are very arbitrary.
So once you select your significance level threshold,
you got to stick to it, right?
You use we selected 0.05 this 10.06.
So that's greater.
And we just got to cut it off and not look not look back anymore.
And just proceed with the method.
So how can we improve our method of building models
to assess situations like that
and give, you know, like an extra opinion or have another criteria
to tell us whether or not we should have actually kept this, variable.
And there is a way and we're going to talk about it right now.
So let's look at this top part over here.
The top part is responsible for the variable.
So you have the coefficients and you've got the p values and so on.
So we've talked about it quite quite extensively.
But now let's look at the bottom part the second part of our report.
And here as we discussed before
we've got the stats there are for the model as a whole.
So how well has been fitted, how well it's working and so on.
So the stats that we'll be looking at today
are R squared and adjusted R squared.
And they will help us come up with a cool approach
or great approach, to improve our, backward elimination method.
So we already talked about both the R squared
and adjusted r squared in the section of this course.
However, if you chose to skip that section because you're not interested
in the formulas and so on, then I'll quickly recap for you. Now.
So r squared over here is basically a characteristic
or a parameter of your model which tells you about the goodness of fit.
So how well your model has been fitted.
And r squared can never be greater than one.
And you want it to be as close to one as possible.
The closer to one it is, the better.
Your model is seem to be fitted.
However, r squared is biased, and it's biased in a way that
it the way is constructed and the way these models are run.
So the ordinary least squared, method,
it's doesn't allow r squared to ever decrease.
So the more variables you add to your model, the greater r squared will be.
So basically what what we're, what this means is that
as long as you keep adding variables, r squared will always grow.
And we can observe that here.
So if we start from the end
where we have only one variable, you can see that r squared is 0.94.
Then r squared became.
Well if you if you go this way it's 0.95.
But then it's 0.90 507.
So as you can see the more variables we have the greater r squared gets.
And that's that's always going to be the case.
Just because of the way r squared is derived.
And moreover you can even include completely random variables.
So if I throw into this model I throw another variable
which is basically the temperature outside.
Like air temperature outside right now then.
And I throw that in as an independent variable.
Of course it's not a predictor.
It can't predict profit of a company that works in New York or California.
But R squared is still going to grow and is going to imply
that our model is now even better fitted.
So that way r squared is biased.
And that's where adjusted r squared comes into play.
Adjusted R squared is very similar to r squared.
It's got a very similar formula.
But it actually has a penalization factor.
So basically just like r squared would grow
if you had more variables adjusted R square would also grow.
But there's a penalization factor which makes it small
which reduces adjusted r squared as you add more variables.
So there's kind of these two effects battling each other.
On one hand it's growing because of the way it's constructed.
On the other hand, the penalization factor is penalizing you or penalizing
the adjusted R squared and reducing it every time you add a variable.
So basically, if the variable that you added doesn't,
make adjusted R doesn't make r squared grow that much,
like for instance, here you can see 0.9505 to 0.9507.
So it only grew by a fraction very very small amount.
Well if that happens
then the penalization factor is going to overwhelm this growth.
And therefore the adjusted r squared is actually going to decrease
in that scenario.
And that way we can use and we will use the adjusted R squared
to watch the goodness of fit our models and how it changes.
So let's let's go ahead and do that.
Let's observe that adjusted r squared in our method.
What was the adjusted r squared here.
It was 0.94.
Then when
we excluded administration expenses
adjusted r squared went from 0.9.
5 to 0.9475.
So as you can see here adjusted r squared went up.
We reduced.
basically what that means is that the model is now better.
It's being it's fitted better. It works.
these variables in this combination fit,
the profit variable fit this model to explain the profit variable
better than these variables in this combination,
to explain the profit variable, which is good.
It's a good step okay.
So that means we improved our model here.
Adjusted R squared is 0.9475.
Let's see what had happened to it when we moved to the next step.
And the next step.
Adjusted R squared is 0.9483.
So it went up again meaning that once again we improved our model.
So altogether these variables
are doing a better job explaining profit.
Then these variables together are doing a job explaining profit.
That's great. We improved our model again.
And now let's see what happens when we take out the loss variable
marketing spend.
So we went from adjusted R squared 0.9483
to adjusted r squared 0.9454.
And what does that tell us.
Our adjusted r squared went down and went down
by from by 0.003 approximately.
So that means that this model, this new model
is actually worse than this model.
So this model was better fitted to predict or explain the variance in profit.
Then this model is doing so.
So there you go.
So even though we excluded a variable
according to our backward elimination method, this
this variable should have been excluded because it was in
it was with us with this variable,
this model is actually working better.
And that is your takeaway, handy trick.
How to, observe your models and, how to create them.
You don't only just follow the backward elimination or whatever method
that you're using and, arbitrarily follow the rules.
Just instead follow the rules,
but also watch the adjusted R squared and see if it's actually improving.
So if it's growing, then you're doing the right thing.
As soon as you see the R adjusted r squared drop
then you have to stop and question, did I just do the right thing or not.
And you know what.
What is the trade off
of excluding a certain variable or the opposite of including the variable.
So adjusted r squared is kind of your indicator.
How are you going along the way.
but that's it for today.
I hope you find this useful and hope you can apply.
You'll find ways to apply this in your actual work.
I look forward to seeing you next time.
And until then, happy analyzing.