Hello and welcome to this art tutorial.
So in the previous tutorial, we prepared our data correctly
so that now we are ready to fit our simple linear
regression to our data set without any issues.
So we're going to do that right now.
And as usual we are going to use the simplest way,
which is to take the LM function.
So we're going to do that right now we're going to call a new variable
regressor.
And that's going to be the simple linear
regressor itself then equals.
And then that's where we use the LM function.
So let's just type lm here.
And then let's press F1 to see the info
of this function and especially the arguments.
So let's see the first argument we have to input is formula.
So let's input it formula.
And according to you what is it going to be.
Well this is going to be the dependent variable
expressed as a linear combination of the independent variable.
So here it's very simple.
Since we only have one dependent variable and one independent variable
we just need to type formula equals salary.
Then I'll plus n.
Here you go.
And then we put the independent variable which is years experience.
So what does this notation means.
That means that the salary is proportional to years experience.
Okay. So that's it for the first argument.
That's the formula we need to input.
And that's actually the simple linear regression formula.
And then we need to add a second argument
which is let's see the data okay.
And that's normal.
That's because we have to specify to R on which data
we want to train our simple linear regression model.
And of course this data is the training set.
Because the training set is the set on which you build your model.
Okay. So that's it.
Actually I know there are some other arguments,
but these are optional arguments that we don't really need here.
So we will just use this two formula and data.
Okay. So that's it.
The regressor will be ready once we select it and execute it.
So let's do this right now.
And let's press Command and Control plus enter to execute.
Here we go.
Now the regressor is ready.
As you can see it just appeared here.
If you want to have some info about this regressor then the best way to do it
is to, you know, go here in the console and type summary
regressor because the name of our regressor is regressor.
Then type enter and then you have some very good informations
about your simple linear model for example.
Okay. So let's see.
let's just put that up
right.
So first it tells you what the formula is okay.
So it's the salary being proportional to the number of years of experience.
And that the model is built on the training set.
Then you have some info about the residuals.
We won't be talking about this now.
But the really important section is this one coefficients.
Because not only itself,
the value of your coefficients in the simple linear regression equation,
but also it tells you the statistical significance of your career efficiency.
And here we observe three stars.
Here.
That means the years
experience independent variable is highly statistically significant
because you can either have no star or one star two stars or three stars.
No star means that there is no statistical significance,
and three stars means that there is a high statistical significance.
So that's the first info.
That's the first hint of what is going to happen,
because we already know by looking at this that there will be a strong linear
relationship between the salary and the number of years of experience.
And the other info here is the p value.
Then the p value is another indicator of the statistical significance,
because the lower the p value is,
the more significant your independent variable is going to be.
That is, the more impact, the more effect
your independent variable is going to have on the dependent variable.
And usually a good threshold for the p value is 5%, which means that
when we are below 5%, the independent variable is highly significant,
and when we are over 5%, that means that it's less significant.
And here, as you can see, the p value is 1.52 ten at the power of -14,
which means that it's a very, very, very small p value.
So that means that this independent variable
years of experience is highly statistically significant.
And it has high impact and high effect on the formula dependent variable.
So that's very important information.
Get the reflex to look at these by you know typing summary regressor.
Because this is really important especially when you want to try out
several potential independent variables.
You need to look at their statistical significance to choose them.
And then you have some informations of your model
globally which will we'll be talking about at the end of this part.
Part one regression,
when we'll be talking about ways to evaluate your model when here.
As you can see, you have the multiple R-squared that we'll talk to you about.
And the adjusted R-squared.
If you have several models with several
teams of independent variables, then that's the adjusted R-squared.
You must choose to choose the best model.
All right.
So that was just a parenthesis to give you this very important trick
to know in R and learn how to evaluate your model already.
So actually we are done
fitting the simple linear regression to our data set, our training set.
And in the next tutorial we are going to be predicting the test
set results to finally see how our simple linear
regression behaves on a new set on some new observations.
Okay, so that's the end of this tutorial.
I look forward to seeing you in the next one.
And until then, enjoy machine learning.