In this video we're going to talk about an introduction to simple linear
regression. We're gonna use this to begin to lay a foundation for regression
models and what they are in general; so simple linear regression can be used
when our Y variable is numeric or continuous and our X variable is also
numeric or continuous although in fact the X variable can actually be
categorical or a factor. Okay but we'll get to that later.
we'll start with the kind of conventional intro where x and y are
both numeric variables to work through the concepts. we're going to work with
this example here so we're gonna look at the relationship between X being the
gestational age of a baby and Y being their head circumference measured in
centimetres. Okay so this data is looking at gestational age and head
circumference for 39 low birth weight babies. If we were to calculate Pearson's
correlation for this data we'd find that it's going to come out to be 0.78
but one thing about the correlation coefficient is that it only
helps describe the direction and strength of association so here we can
see there's a positive association: as x increases Y increases and this
tells us something about the strength of the linear Association but it doesn't
allow us to say anything about the effect of X on Y; so for example every
time gestational age increases by one day what do we expect to happen to the
head circumference or if we want to build a model in a predictive sense use
the gestational age to try and estimate what the head circumference will be so
Pearson's correlation is a useful measure for summarizing an association
but it's quite limited so what we're going to do is we're going to start to
build up the idea of how we can model Y as a linear function of X because that's
what linear regression is all about so let me just draw the line here to try
and describe what I mean by that; we can try and fit a line through this that
helps us say for a given x value what do we think the Y value is and so this is
our first encounter of using the term model. A lot of stuff we talked
about earlier t-test, two sample t-test anova, chi-square test, all these can be
thought of as very simple models but this is the first time we're
actually going to really start to explore the concept of modeling. Okay so
it's important to start off with a few notes here: the first is a quote from a
relatively well known statistician George Box and he had said: all models
are wrong but some are useful; again I think this makes a great point and that
all models and for the most part all theory, they are oversimplifications of
reality and that end up magnifying or highlighting some aspects and ignoring
others and so here when we build this model to describe a relationship between
gestational age and head circumference we're ignoring other certain factors
we're ignoring biological variability we're ignoring things like
the age of the mother or father, what's the weight of the mother or father are
probably an important one, what's the head circumference of the mother or
father, so the point is that we're ignoring some aspects and we're going to
try and highlight some others what we're going to try and do here is we're going
to start to build up simple linear regression and we're going to use it as
a foundation for understanding regression models in general later after
an intro stats course you tend to move into stuff like generalized linear
models where you start to learn about logistic regression models Poisson
regression models maybe survival models or mixed effects models these different
sorts of things and these are all just a step up from what simple linear
regression is. So what we want to do is lay a good foundation for understanding
what is regression, what are the important concepts, what are the
interpretations, and what are the limitations, these sorts of things and we
can use that as a really good foundation for understanding all the higher level
models; okay in some sense all of these regression models try and model Y as
some function of X or X variables. so again we're going to use this to set a
foundation. So what we do is we're to start by introducing just some of the
terminology and some of the concepts around simple linear regression. so first
what I'm going to do is just label one of the observations here we're going to
pick on this one here and for this one this we label xi this is the observed X
value for person i
and this here we label yi, it's the observed Y value for person i, alright so
for this baby here's their observed gestational age
and their observed head circumference; we can also use the regression line to
start to try and estimate Y values. so for this particular individual here
at a hundred and eighty days of gestation our model would estimate that
their head circumference is roughly 25 okay that's what we predict our
estimated should be; so we're going to label this yi-hat (Yi^)
a hat (^) to indicate that it's an estimated value or we could also
label it the mean and again hat (^) to indicate it's an estimated mean of Y
given X. in a moment will differentiate between these two and what we mean by
Yi verse mu of Y given X but give it a moment and we'll get to that. The next
thing we want to label here is this difference here: this is the distance
between the observed Y value for this individual and their estimated Y value
okay so this distance here we're gonna label ei okay it's the error or the
residual it's the difference between the observed Y and the predicted or
estimated Y: here it can be written (yi- yi^) the difference between
the observed y value and the predictor estimated y value; so this gets
called a error or residual okay there is a slight difference between the two the
difference is that the term error is generally reserved for kind of the
theoretical errors and when it's an observed error for a set of data we call
it a residual but for the most part the term error and residual tend to get used
interchangeably, very similar to the concept of a
standard deviation and a sample standard deviation like one is the theoretical one
one is the observed one for sample of data but they're the exact same
conceptually; okay so for the most part you're going to hear error and residual
used interchangeably now let's label the regression line that
we fit. This here is the line that we fit and we'll get to talking about how we
choose this line but first we can label this as yi^ or the estimated mean of
Y given X is b-not + b1X and this b-not being the y-intercept and b1
being the slope of the line. So in order to define a line we need to give it some
point on the line as well as the slope and carry the rate of increase for the
line, the points we choose are the y-intercept we'll get to talking about
what that is in a moment but to say it quickly
it's where the line crosses the y axis at x equals 0 so let's take a moment
here to talk about the difference between labeling this is yi or miu of y
we can think of this line as either modeling individuals so the predicted
value for an individual so for a baby of 180 days gestation we predict or we
estimate that their head circumference will be about 25 centimetres. We can also
think of this line as modeling the estimated mean
of a population: for babies of 180 days gestation we estimate that the average
head circumference is going to be 25 centimetres. We tend to estimate that
people are going to take on the mean value okay so this line we can think of
as representing predicted values for individuals or estimating the mean for a
population; there is a slight difference between the two and we're
going to build up to that and talk a bit more about it later that mainly has to
do with the estimate of the variability around each of these there's gonna be
more variability in the estimate of individuals head circumference than the
mean for a population okay but we'll we'll build our way up to that some
other important notes if you reach back to things you may recall from
earlier training and math sometimes the equation for a line gets written as y= mX+b
and so here b being the intercept and m being the slope. Another important
note to just add in there sometimes when you look at different sources different
instructors different textbooks different things sometimes this gets
written as a+bX a being the intercept b being the slope. Okay so the
notation I'm going to stick to using is b-not for the intercept b1 for the slope.
and but just a note you do see different, slightly different notation use
A separate topic that is not going to fit into this video it's something
that that should be explored later is how we choose the best line well how we
define the best line and then how we choose that. The quick version now
to say the key terms is we use something called the method of least squares where
we try to minimize the sum of squared error we can explore that concept later
this ends up being the same as using a method of maximum likelihood again
that's a topic beyond the scope of this simple intro video but something that is
worth exploring later so for now let's just suppose that the equation for the
line our choice for the best line comes out to be
yi^; here the estimated mean of Y given X
5.06+ 0.11X. 0.11 times X, the gestational age plus 5.06 is going to
give us the predicted head circumference for a baby or the estimated mean for
that value of x. now let's talk about the slope as well as the intercept for this
line: so first let's get to the slope; the slope which we label b1 in terms of a
formula comes out to be the correlation times the standard deviation of the Y
values of the head circumference is over the standard deviation of the X values
the standard deviation of the gestational ages, this came out to be 0.11 centimetres
An important note we don't really want to focus on plugging
into formulas okay you're probably not going to spend much time in your life
trying to calculate the slope and the intercept for a regression line by hand
but the reason that I show this formula is to get some intuition into what the
slope for the regression line is or how it's being estimated so you can notice
here that the slope is essentially the correlation, the measure of
association between x and y but it gets scaled by the standard deviation of Y
over the standard deviation of X. And if we think about this for a moment
suppose we change the unit you have gestational date gestational age from
days suppose we change it to weeks okay what would happen the 210 days sitting
here becomes 30 weeks, so if we were to redo this plot instead of using X in
days using X in weeks, the 210 days is gonna scale all the way back here to
30 weeks. The plot is going to shift up, the slope of the line is going to shift up
The correlation is going to be the same, right, correlation between x and
y is independent of units so this slope here is essentially taking the
correlation but building in the scale of x and the scale of y,
the units of x and y. What this ends up the interpretation of the slope
is it tells us the change in Y for a one unit change in X, so to say that in words
what it's telling us is every time the gestational age increases by one day we
associate that with an increase of 0.11 centimetres in head circumference
every time X goes up by one what do we expect to happen to Y? each additional
day of gestation is associated with an increase of 0.11 centimetres in the
head circumference now let's talk about the y-intercept.
In terms of a formula the intercept b-not comes out to be the mean of Y minus the slope times the mean of X.
If you work this out numerically we find that comes out to be
5.06 centimetres and again the interpretation of this is the
y-intercept tells us the estimated y value for x equals zero or what's the
value of y when x equals zero right again where does the line cross the y
axis at x equals zero. Okay so in our particular example this would be telling
us what's the estimated head circumference for a baby of zero days
gestation. Now you're probably gonna notice that doesn't really have a
meaningful interpretation, right! what's the the size you know of a head
circumference for a baby who's been in a stomach for zero days right it doesn't
exist so the intercept does not always have a meaningful interpretation and
here it's because we haven't even observed data in the range of x equals 0
So it doesn't really make sense to interpret you know what's a y-value for
x equals zero when we have no idea right we've only observed x-values of 160 or
larger we can give the intercept a more meaningful interpretation by doing
something called centering the X variable
Again that's a topic beyond this video we can explore that separately but
essentially what it involves doing is labeling some other point in
here as being the zero observation so if we were to centre it around 2 that would
be like calling sorry centre around 200, calling 200 days zero and then our
intercept would be where is the line cross the y axis at x equals zero but
again that was kind of a very quick explanation we'll explore the concept of
centering separately so there's all sorts of reasons for building a
regression model for now we just want to introduce the concepts of a regression
model and some of the important parts what is the slope what's the intercept
what are some of the interpretations of these coefficients and later we'll get
up to building up to goals for regression models but let's do a very
quick overview of that now: so breaking it into two broad classes the goals for
our model one thing we might want to do is estimate the effect of X on Y okay so
that might be our focus and that essentially means we're really
interested in this slope term here estimating and interpreting this okay
what is the effect of X on Y every time gestational age goes up by one day what
happens to the head circumference. we estimate it goes up by 0.11 centimetres
so this sometimes gets called an effect size model or estimating the effect of X
on Y, a separate focus is a predictive model so we may really wanting to
be building a model to try and predict Y, right, give us an x value as an input
predict what Y will be. So let's take a look at doing that here if we want to
predict the Y value 5.06 plus 0.11 times the gestational age of 180 so I'm
going to use 180, for 180 days gestation what do we estimate or predict the head
circumference to be if you work that out it's going to come up to 24.9 centimetres
So 480 days gestation we predict that the head circumference
will be 24.9 centimetres. So we'll expand later on the kind of
competing goals, are we really trying to estimate the effect of X on Y or is our
focus more predictive and trying to predict the outcome. When we get to
multiple linear regression and including multiple X variables the way we built
the model and the variables we select will depend will be different it will
depend on is our ultimate goal to predict the outcome or is our ultimate
goal to get an unbiased estimate of the slope or the effect of X on Y but we'll
build up to that later.
Like all these approaches there are some necessary
assumptions for building a linear regression model and we'll explore those
separately they separately we'll look at what are the assumptions for this model
how can we check the assumptions as well as what can we do if some of the
assumptions aren't met how can we try and address violations or what are
alternative approaches we might try using. The final note is that it's worth
noting that linear regression is an absolutely huge topic and it can be a
course or multiple courses on its own so really what we want to do here is
exploring the idea of what is linear regression what are some of its uses
some of the important components and will slowly build on to it as we progress through the course