Welcome to Highline BI class video number 46.
Hey, if you want to download this workbook, BI348-Chapter04.
This is the Excel workbook.
Or you can download the PowerPoint.
Click on the link below the video.
Hey, last video, we took this data set.
We had 190 records.
There's some rows hidden right there.
We had x equals weekly expense, and then
y, that's our weekly sales.
We plotted it to see if there's a relationship
between weekly ad expense and weekly sales.
The markers show us that as x is increasing,
y tends to be increasing.
From our visual interpretation that there's
a positive or direct relationship,
we then learn how to calculate covariance and coefficient
of correlation.
Now, given that we see there is a direct relationship visually
and in our numerical measure, we want
to create an equation that can help us predict.
We want to be able to say something
like $43,000 for weekly ad expense--
what should the weekly sales be?
Now I'm going to jump over to our PowerPoints.
I'm going to hit Shift-F5 to start on this slide.
This is slide 18.
Now, in algebra, you may have seen y equals mx plus b.
y, that's the value we're trying to predict.
X, that's the value we throw into this equation,
the independent variable that will predicament
the dependent or predicted variable.
The m is the slope, the b is the y-intercept.
All that's algebra here in statistics.
We have two different equations, one
for our population parameters and one
for our sample statistics.
Yes, we usually aren't going to know the actual population
y-intercept or the population slope.
So we're going to have to use methods to calculate the sample
statistics for slope and for intercept.
This will be called y hat and I will write it like this.
We'll actually use the symbol.
Y hat equals slope times x plus y-intercept.
Now, slope, whichever variable you use,
the meaning of the slope is going to be for every one unit
x, how much does y change?
In a positive relationship, y will go up.
In a negative relationship, y will go down.
And the intercept, whichever variable you use,
it simply is going to tell us at what point
does the line cross the y-axis.
Or, what is y when x equals to 0?
And of course, this equation, any one of these equations,
describes a straight line.
Now let's go to our next line, because, guess what?
We're not always going to have our population parameter.
So the simple linear regression model-- y
equals slope times x plus E intercept plus an error value.
Now, these are called beta sub 1, beta sub 0,
and this is epsilon.
Now, this error is going to come from the fact
that we're creating an equation or a straight line.
And I'm going to go to the next slide.
And guess what?
All of the original sample data points
are not on the straight line.
This straight line comes from this equation.
We're going to create this equation for making prediction.
There is the slope, there's the x, there's the y-intercept.
That equation describes that line.
And because all of the sample point markers above and below
are not exactly on the line, we have some error.
Now, if we're going to use this model,
we have to make some assumptions about this error.
So again, there's some sample points
that are above and below.
And I want you to think about this for a second.
Here's a marker above.
That's the actual value from our sample, look at where
the projection's going to be.
The prediction's going to be way down here.
So in this particular instance, the actual predictive value
is less than the particular value from the sample
the model where the equation underpredicts.
Down here, it's the opposite.
The model overpredicts.
So because we don't want our equation
to overpredict or underpredict too much,
we want to look at the assumptions necessary for such
a model, a model that will not over or underpredict too much.
Now, notice-- this has x and y.
When I go to the next slide, we're
going to look at these assumptions necessary.
I'm going to tip this on its side.
So next slide-- you're going to notice I've tilted this.
But the x, that's weekly ad expense, and y,
predicted weekly sales, they're still there.
I've just tilted it on the side.
And these bell shaped distributions
are our assumptions about how the error should
be distributed.
Now, here's the line.
There's the equation.
And notice-- no error term.
Because right on the line, the expected value of epsilon
should be zero.
That's our first assumption.
And all that means is if this is a probability distribution
for the possible error values above or below, as we
go higher and higher above the line or below the line,
the probability gets smaller and smaller
that we can get one of those errors.
And right in the middle, that's where the frequency is highest.
The probability is highest.
We're hoping to get errors right at zero or close.
So in order for this line to not over and under predict
too much, we really need most of the errors
to be right near the middle.
So number one, the expected value of epsilon, our error
is going to be a zero.
If that's true, we can treat the slope and the y-intercept
as a constant and not include our error term.
Assumption number two-- we have a bell shaped distribution.
Hopefully, most of the errors are right near the middle.
Now, the third assumption is that that error, the variation
or the standard deviation, will be constant across all
of the x's on our line.
Now, we'll actually be able to test this later using
what's called a residual plot.
We also want you to notice that expected value of y
given x, that's actually for population values.
So if you imagine that scatter plot we just saw,
if there was some values for the y up above and below the line,
if we took the mean of all those,
then the expected value of y for the population given
a particular x would be exactly on the line.
Now, if that's true for this equation,
if we go to our next slide, then we
can see we don't have to show the distribution of errors
because expected value of epsilon,
the error is going to be zero.
So there is what is called the simple linear regression
equation without the error value.
Now we'll go back to slide number 19.
When we use the word model, that's
the parameters and the error.
If we go to slide number 22, simple linear regression
equation, population parameters without the error value.
Now, of course, most of the time,
we are not going to have our population parameter, slope,
and y-intercept.
So we're going to have to figure out
formulas to calculate both of those
to create our sample statistics for slope and y-intercept.
If we go to slide number 24, we can
see estimated, simple, linear regression equation.
This is going to be with our population parameters
for slope and y-intercept.
So this will be called y hat.
I'm going to sometimes do it as y sub hat
or use the actual symbol sample statistics--
slope times x plus sample statistic y-intercept.
Now, this value will predict two different things.
If we want to estimate the population parameter,
then y hat will be the point estimate
of expected population value of y given a particular x.
That will be the mean of all the y values for a particular x
in the population.
But most of the time, we're going
to be using y hat to make predictions.
Y hat can predict an individual y value
for a particular business situation.
So we're going to use y hat for our weekly ad
expenses and weekly sales.
We'll simply throw in an x, say, 43,000 for our weekly ad
expense and the y hat will tell us
what our predicted weekly sales will be.
Now we need our formula for calculating
slope and y-intercept.
Let's go to slide 27.
For slope b sub 1, we have numerator and denominator.
Look at this.
This is the standard deviation of x times deviation of y
we did for covariance and correlation.
And then in denominator, we're going
to take the sum of the x deviations squared.
Once we get our b, we simply plug it into this equation y
bar minus slope times x bar.
We will then have our sample statistic for y-intercept
and for our slope.
Here are the variables.
Here are some alternatives you may see.
We're going to use this formula, but you
may see this as a formula for slope or this one.
All right, now we want to put this formula right here
into action and calculate slope.
We're going to go over to Excel.
Now we're on the sheet slope and intercept.
Now, here's our same data set-- weekly ad
expense and weekly sales.
In our last video, we already calculated the x deviation--
particular x minus the x bar-- the y deviation--
the particular y minus the y bar.
And then we multiply those two and added them.
That is our numerator for the slope.
Now, what do we need?
We need to take x minus x bar and square it.
But we already have the deviation x minus x bar.
So right here, I'm simply going to come over and say equals,
hey, that deviation for x, carat 2 to square it, Control-Enter.
Now we can copy this down.
Come to the bottom, Alt-Equals.
And when I hit Enter, there's the total.
That's going to be our denominator.
So we can come over to slope equals
the sum of the product of the two deviations, that's
the numerator, divided by-- and the denominator
is going to be the sum of the deviations for x squared.
When I hit Enter, that is our slope.
Now, our y-intercept, we can simply say,
hey, where is our y bar?
There it is, minus the slope times the x bar.
And that will give us our y-intercept.
Now we don't have to go through all these steps.
Once we've done it once or twice, we can simply use--
and there's a great function equals slope.
It wants the known y's.
So I highlight all the y's.
Comma, the known x's-- I highlight all the x's.
And when I hit Enter, it gives me the exact same number.
Y-intercept, they named this one smartly just like they did
slope-- intercept, known y's comma known x's.
And there is the y-intercept.
That means we have our estimated regression
equation y hat equals 8.24 times x plus 36,857 and four pennies.
That slope [INAUDIBLE] because then we can see over here
that [? slope's ?] right there, $8.24,
means our estimated equation predicts
for every $1 increase in ad expense,
weekly sales will go up by $8.24.
Now, the y-intercept, sure it's where,
if we were to throw x of 0 into this,
the line would cross right there.
But we're never going to do that because our sample
data has a min and a max.
And that value is way outside what's
called the experimental region.
Since we have our sample data here-- that's the only evidence
we have-- we have no idea what this relationship might
do outside this range in either direction.
So we want to keep our predictions only
between the Min and the max of our x values.
Now I want to come back over here.
I definitely want to calculate the min and the max
for our experimental region.
And this is the x value because the x is what we're throwing in
into our equation.
So, 14,591 equals and the max of our x values.
So our experimental region goes from about 14,000
to about 65,000.
We definitely should limit our estimates and predictions
to the experimental range.
Any extrapolation outside the range
yields unreliable estimates.
Now here it is.
Here's our $43,000.
We have our slope and y-intercept where we're
going to build our equations.
Equals, and I'm going to take this slope-- there
is our slope we calculated-- times the x
we're going to throw into our equation plus our y-intercept.
And when I hit Enter, hey, wait a second.
The 43,000-- was it within our experimental region?
You got it.
So we have a reasonable estimate.
If we spend $43,000 as ad expense,
our estimated weekly sales will be $391,243.
Now, of course, the beauty of this
is we can put whatever we want-- 60,000 here for weekly ad
expense.
And our equation predicts that weekly sales will be $531,349.
If I go ahead and throw in a 150,000,
that is an unreliable estimate.
Our experimental range, we don't know.
You know, way out here, maybe things
start to exponentially increase because we're
doing so much with ads.
But over our range, we can go ahead and slap whatever
we want in here-- 63,000.
There is our estimate.
Now we do want to make sure that we correctly interpret
the slope and the y-intercept.
As we said for the slope, for every $1 increase in ad
expense, the equation predicts that weekly sales
will increase by $8.24.
And that's of course over our experimental range.
As for the y-intercept, when x equals 0
the equation predicts that we'll have weekly sales of 36,857,
but that's an unreliable estimate because 0 is not
in our experimental range.
Extrapolating what the sales would be at x equals
0, of course, yields an unreliable estimate.
All right, now we want to go look at a second example.
We're going to go over to experimental range 2.
Hey, here's our same data set.
We have intro level BMX racing bikes,
the bicycle weight, the price.
We already calculated correlation and plotted it.
So now we can simply calculate our slope, equals slope.
And I'm going to put in the known y's comma the known x's.
And when I hit Enter-- whoops.
When I hit Enter, I get a slope that
is negative because this is a negative or inverse
relationship.
As bike weight increases, the price decreases.
That slope says for every one pound of bike increase,
the price is predicted to go down by $58.
Now, the y-intercept, intercept, known y's comma known x's.
And the y-intercept is 1,732.
So that, of course means at bike weight equal to 0,
that's how much the bike will cost.
That is not in our experimental range.
That is an extrapolation.
We cannot have a bike that has zero pounds,
so that is meaningless.
However over the range of our min and max,
it certainly helps our equation make a prediction.
All right, so now let's estimate what a 25 pound bike would be.
Equals, and we have our slope of minus $58 times number
of pounds plus our y-intercept.
And there it is.
If we have a bike that's 25 pounds,
our estimated regression equation
predicts that the bikes should cost $267.
All right so, in this video, we saw
how to create an estimated regression equation.
We saw the formulas for slope and y-intercept
and we also made sure that we talked
about experimental range, the min, and the max
for making predictions with our equation.
All right, next video, we'll actually
learn how to calculate a measure called
r squared that will tell us the goodness of fit
of the estimated equation line to the actual sample data
points.
All right, we'll see you next video.