Proof (part 3) minimizing squared error to regression line

WEBVTT
Kind: captions
Language: en

00:00:00.520 --> 00:00:03.590
All right, so where we left
off, we had simplified our

00:00:03.590 --> 00:00:07.850
algebraic expression for the
squared error to the line from

00:00:07.850 --> 00:00:09.040
the n data points.

00:00:09.040 --> 00:00:10.090
We kind of visualized it.

00:00:10.090 --> 00:00:13.410
This expression right here would
be a surface, I guess

00:00:13.410 --> 00:00:16.520
you could view it as a surface
in three dimensions, where for

00:00:16.520 --> 00:00:19.340
any m and b is going to be a
point on that surface that

00:00:19.340 --> 00:00:22.780
represents the squared
error for that line.

00:00:22.780 --> 00:00:26.860
Our goal is to find the m and
the b, which would define an

00:00:26.860 --> 00:00:30.760
actual line, that minimize
the squared error.

00:00:30.760 --> 00:00:34.570
The way that we do that, is we
find a point where the partial

00:00:34.570 --> 00:00:37.190
derivative of the squared error
with respect to m is 0,

00:00:37.190 --> 00:00:40.820
and the partial derivative
with respect to b is also

00:00:40.820 --> 00:00:41.590
equal to 0.

00:00:41.590 --> 00:00:43.600
So it's flat with
respect to m.

00:00:43.600 --> 00:00:45.540
So that means that the slope
in this direction

00:00:45.540 --> 00:00:46.660
is going to be flat.

00:00:46.660 --> 00:00:48.430
Let me do it in the
same color.

00:00:48.430 --> 00:00:51.110
So the slope in this direction,
that's the partial

00:00:51.110 --> 00:00:53.720
derivative with respect to
m, is going to be flat.

00:00:53.720 --> 00:00:55.640
It's not going to change
in that direction.

00:00:55.640 --> 00:00:57.420
The partial derivative
with respect to b

00:00:57.420 --> 00:00:58.400
is going to be flat.

00:00:58.400 --> 00:01:01.870
So it will be a flat point
right over there.

00:01:01.870 --> 00:01:04.680
The slope at that point in that
direction will also be 0,

00:01:04.680 --> 00:01:06.580
and that is our minimum point.

00:01:06.580 --> 00:01:08.960
So let's figure out the m and
b's that give us this.

00:01:08.960 --> 00:01:11.090
So if I were to take the partial
derivative of this

00:01:11.090 --> 00:01:13.220
expression with respect to m.

00:01:16.710 --> 00:01:18.700
Well this first term has
no m terms in it.

00:01:18.700 --> 00:01:21.330
So it's a constant from the
point of view of m.

00:01:21.330 --> 00:01:24.030
Just as a reminder, partial
derivatives, it's just like

00:01:24.030 --> 00:01:25.630
taking a regular derivative.

00:01:25.630 --> 00:01:28.690
You're just assuming that
everything but the variable

00:01:28.690 --> 00:01:31.290
that you're doing the partial
derivative with respect to,

00:01:31.290 --> 00:01:33.350
you're assuming everything
else is a constant.

00:01:33.350 --> 00:01:36.860
So in this expression, all the
x's, the y's, the b's, the

00:01:36.860 --> 00:01:38.490
n's, those are all constant.

00:01:38.490 --> 00:01:40.820
The only variable, when we take
the partial derivative

00:01:40.820 --> 00:01:43.500
with respect to m, that
matters is the m.

00:01:43.500 --> 00:01:45.190
So this is a constant.

00:01:45.190 --> 00:01:46.510
There's no m here.

00:01:46.510 --> 00:01:48.920
This term right over
here, we're taking

00:01:48.920 --> 00:01:52.700
with respect to m.

00:01:52.700 --> 00:01:56.690
So the derivative of this with
respect to m, it's kind of the

00:01:56.690 --> 00:01:57.880
coefficients on the m.

00:01:57.880 --> 00:02:03.560
So negative 2 times n times the
mean of the xy's, that's

00:02:03.560 --> 00:02:06.830
the partial of this
with respect to m.

00:02:06.830 --> 00:02:10.430
Then this term or right
here has no m's in it.

00:02:10.430 --> 00:02:12.700
So it's constant with
respect to m.

00:02:12.700 --> 00:02:15.450
So its partial derivative
with respect to m is 0.

00:02:15.450 --> 00:02:19.610
Then this term here, you have
n times the mean of the x

00:02:19.610 --> 00:02:21.080
squared times m squared.

00:02:21.080 --> 00:02:23.100
So this is going to be-- we're
talking about a partial

00:02:23.100 --> 00:02:31.740
derivative with respect to m--
so it's going to be 2 times n

00:02:31.740 --> 00:02:34.690
times the mean of the
x [? squareds ?]

00:02:34.690 --> 00:02:37.960
times m.

00:02:37.960 --> 00:02:42.060
The derivative of m squared is
2m, and then you just have

00:02:42.060 --> 00:02:43.990
this coefficient
there as well.

00:02:43.990 --> 00:02:46.400
Now this term, you also
have an m over there.

00:02:46.400 --> 00:02:49.950
So let's see, everything
else is just kind of a

00:02:49.950 --> 00:02:51.250
coefficient on this m.

00:02:51.250 --> 00:02:55.940
So the derivative with respect
to m is 2bn times

00:02:55.940 --> 00:02:57.120
the mean of the x's.

00:02:57.120 --> 00:03:01.500
If I took the derivative of 3m,
the derivative is just 3.

00:03:01.500 --> 00:03:03.340
It's just the coefficient
on it.

00:03:03.340 --> 00:03:05.530
Then finally, this is a constant
with respect to m.

00:03:05.530 --> 00:03:06.910
So we don't see it.

00:03:06.910 --> 00:03:09.510
So this is the partial
derivative with respect to m.

00:03:09.510 --> 00:03:10.670
That's that right over there.

00:03:10.670 --> 00:03:13.800
We want to set this
equal to 0.

00:03:13.800 --> 00:03:17.020
Now let's do the same thing
with respect to b.

00:03:17.020 --> 00:03:18.930
This term, once again, is
a constant from the

00:03:18.930 --> 00:03:20.520
perspective of b.

00:03:20.520 --> 00:03:21.940
There's no b here.

00:03:21.940 --> 00:03:23.380
There's no b over here.

00:03:23.380 --> 00:03:25.050
So the partial derivatives
of either of these with

00:03:25.050 --> 00:03:26.440
respect to b is 0.

00:03:26.440 --> 00:03:29.390
Then over here you have a
negative 2n times the mean of

00:03:29.390 --> 00:03:31.450
y's as a coefficient on a b.

00:03:31.450 --> 00:03:33.990
So the partial derivative with
respect to b is going to be

00:03:33.990 --> 00:03:40.500
minus 2n, or negative 2n, times
the mean of the y's.

00:03:40.500 --> 00:03:42.230
Then there's no b over here.

00:03:42.230 --> 00:03:43.550
Then we do have a b over here.

00:03:43.550 --> 00:03:47.480
So it's plus 2mn times
the mean of the x's.

00:03:53.090 --> 00:03:54.490
This is essentially
the coefficient

00:03:54.490 --> 00:03:55.480
on the b over here.

00:03:55.480 --> 00:03:58.520
It was written in a mixed order,
but all of these are

00:03:58.520 --> 00:04:00.850
constants from the point
of view of b.

00:04:00.850 --> 00:04:02.860
They are the coefficient
in front of the b.

00:04:02.860 --> 00:04:04.670
The partial derivative of that
with respect to b is just

00:04:04.670 --> 00:04:06.330
going to be the coefficient.

00:04:06.330 --> 00:04:08.860
Then finally, the partial
derivative of this with

00:04:08.860 --> 00:04:13.820
respect to b is going to be 2nb,
Or 2nb to the first you

00:04:13.820 --> 00:04:15.070
could even say.

00:04:21.860 --> 00:04:24.820
We want to set this
equal to 0.

00:04:24.820 --> 00:04:26.650
So it looks very complicated.

00:04:26.650 --> 00:04:28.840
But remember, we're just trying
to solve for the m's

00:04:28.840 --> 00:04:29.530
and the b 's.

00:04:29.530 --> 00:04:32.290
We have two equations with
two unknowns here.

00:04:32.290 --> 00:04:37.820
We have the m's and then
we have the b's.

00:04:37.820 --> 00:04:40.080
To simplify this, both of these
equations, actually the

00:04:40.080 --> 00:04:42.900
top one and the bottom
one, both sides are

00:04:42.900 --> 00:04:44.220
divisible by 2n.

00:04:44.220 --> 00:04:45.630
I mean 0 is divisible
by anything.

00:04:45.630 --> 00:04:46.530
It'll be just 0.

00:04:46.530 --> 00:04:49.440
So let's divide the top equation
and by 2n and see

00:04:49.440 --> 00:04:50.020
what we get.

00:04:50.020 --> 00:04:55.940
If we divide the top equation by
2n, this'll become just 1.

00:04:55.940 --> 00:04:58.950
That goes away, and then
those go away.

00:04:58.950 --> 00:05:04.220
You would just be left with
negative times the mean, the

00:05:04.220 --> 00:05:12.630
negative mean of the xy's plus
m times the mean of the x

00:05:12.630 --> 00:05:22.260
squareds, plus b times the mean
of the x's is equal to 0.

00:05:22.260 --> 00:05:24.550
That's this first expression
when you divide both sides by

00:05:24.550 --> 00:05:26.060
negative 2n.

00:05:26.060 --> 00:05:29.820
The second expression will
be, this will go away.

00:05:29.820 --> 00:05:31.440
This is when you divide
it by 2n.

00:05:31.440 --> 00:05:34.500
I don't want to say
negative 2n.

00:05:34.500 --> 00:05:37.240
When you divide this by 2n,
that'll go away, that will go

00:05:37.240 --> 00:05:39.330
away, and then those
will go away.

00:05:39.330 --> 00:05:45.120
You're just left with the
negative mean of the y's plus

00:05:45.120 --> 00:05:55.630
m times the mean of the x's
plus b is equal to 0.

00:05:55.630 --> 00:05:59.030
So if we find the m and the b
values that satisfy the system

00:05:59.030 --> 00:06:04.620
of equations, we have minimized
the squared error.

00:06:04.620 --> 00:06:06.100
We could just solve it
in a traditional way.

00:06:06.100 --> 00:06:07.860
But I want to rewrite this,
because I think it's kind of

00:06:07.860 --> 00:06:11.760
interesting to see what these
really represents.

00:06:11.760 --> 00:06:14.680
So let's add this mean
of the xy's to both

00:06:14.680 --> 00:06:15.930
sides of this top equation.

00:06:22.200 --> 00:06:23.260
What do we get?

00:06:23.260 --> 00:06:28.930
We get m times the mean of
the x [? squareds ?]

00:06:28.930 --> 00:06:36.110
plus b times the mean of the
x's is equal to, these are

00:06:36.110 --> 00:06:42.700
going to cancel out, is equal
to the mean of the xy's.

00:06:42.700 --> 00:06:44.390
That's that top equation.

00:06:44.390 --> 00:06:49.070
This bottom equation, right
here, let's add the mean of y

00:06:49.070 --> 00:06:50.880
to both sides of
this equation.

00:06:50.880 --> 00:06:53.040
I do that so that that
cancels out.

00:06:53.040 --> 00:06:57.730
And then we're left with m--
I'll do that in the blue color

00:06:57.730 --> 00:07:00.940
to show you the same equation--
we have m times the

00:07:00.940 --> 00:07:13.990
mean of the x's plus b is equal
to the mean of the y's.

00:07:13.990 --> 00:07:15.630
Now, I actually want to
get both of these

00:07:15.630 --> 00:07:16.960
into mx plus b form.

00:07:16.960 --> 00:07:18.100
This is actually
already there.

00:07:18.100 --> 00:07:24.260
Actually you can see, that if
our best-fitting line is going

00:07:24.260 --> 00:07:28.550
to be y is equal to mx plus b--
we still have to find the

00:07:28.550 --> 00:07:31.350
m and the b-- but we see on
that best-fitting line,

00:07:31.350 --> 00:07:33.710
because the m and the b that
satisfy both of these

00:07:33.710 --> 00:07:35.740
equations are going to be
the m and the b on that

00:07:35.740 --> 00:07:36.830
best-fitting line.

00:07:36.830 --> 00:07:42.950
So that best-fitting line
actually contains the point,

00:07:42.950 --> 00:07:46.780
and we get this from the second
equation right here.

00:07:46.780 --> 00:07:48.150
It contains the point.

00:07:51.160 --> 00:07:52.120
I should write it this way.

00:07:52.120 --> 00:08:04.080
The coordinate mean of x mean
of y lies on the line.

00:08:04.080 --> 00:08:05.640
And you could see it
right over here.

00:08:05.640 --> 00:08:10.800
If you put the mean of x in this
for the optimal m and b,

00:08:10.800 --> 00:08:14.720
you are going to get
the mean of the y.

00:08:14.720 --> 00:08:15.710
So that's interesting.

00:08:15.710 --> 00:08:17.690
This optimal line.

00:08:17.690 --> 00:08:20.160
Let's never forget what we're
even trying to do.

00:08:20.160 --> 00:08:25.370
This optimal line is going to
contain some point on it-- let

00:08:25.370 --> 00:08:28.315
me do that in a new color--
it's going to contain some

00:08:28.315 --> 00:08:31.627
point on it right here that is
the mean of all of the x

00:08:31.627 --> 00:08:36.260
values and the mean of
all the y values.

00:08:36.260 --> 00:08:37.140
That's just interesting.

00:08:37.140 --> 00:08:38.340
It kind of makes sense.

00:08:38.340 --> 00:08:40.270
It kind of makes intuitive
sense.

00:08:40.270 --> 00:08:43.330
Now this other thing, just to
kind of get it in the same

00:08:43.330 --> 00:08:43.970
point of view.

00:08:43.970 --> 00:08:46.590
Then it will actually become a
kind of an easier way to solve

00:08:46.590 --> 00:08:47.000
the system.

00:08:47.000 --> 00:08:48.880
You could solve this a million
different ways.

00:08:48.880 --> 00:08:51.210
But just to give us an intuition
of what even is

00:08:51.210 --> 00:08:53.690
going on here, what's another
point that's on the line?

00:08:53.690 --> 00:08:55.840
Because if you have two points
on the line, you know what the

00:08:55.840 --> 00:08:57.940
equation of the line
is going to be.

00:08:57.940 --> 00:09:01.630
Well the other point, we want
this to be in mx plus b form.

00:09:01.630 --> 00:09:05.180
So let's divide both sides of
this equation by this term

00:09:05.180 --> 00:09:07.250
right here, by the
mean of the x 's.

00:09:07.250 --> 00:09:12.710
If we do that, we get m times
the mean of the x

00:09:12.710 --> 00:09:14.080
[? squareds ?]

00:09:14.080 --> 00:09:21.450
divided by the mean of the x's
plus b is equal to the mean of

00:09:21.450 --> 00:09:26.350
the xy's divided by the
mean of the x's.

00:09:26.350 --> 00:09:28.560
So when you write it in this
form, this is the exact same

00:09:28.560 --> 00:09:30.890
equation as that, I just divided
both sides by the mean

00:09:30.890 --> 00:09:33.860
of the x's, you get another
interesting point that will

00:09:33.860 --> 00:09:38.130
lie on this optimal fitting
line, at least from the point

00:09:38.130 --> 00:09:39.970
of view of the squared
distances.

00:09:39.970 --> 00:09:49.060
So another point that will lie
on it, on this optimal line,

00:09:49.060 --> 00:09:53.720
the x value is going to be
this, the mean of the x

00:09:53.720 --> 00:09:54.380
[? squareds ?]

00:09:54.380 --> 00:09:57.630
divided by the mean
of the x's.

00:09:57.630 --> 00:10:01.020
Then the y value is going to
be the mean of the xy's

00:10:01.020 --> 00:10:03.380
divided by the mean
of the x's.

00:10:03.380 --> 00:10:05.370
I'll let you think about
that a little bit more.

00:10:05.370 --> 00:10:08.560
But already, this is actually
the two points that lie on the

00:10:08.560 --> 00:10:22.125
line, so both of these on the
best-fitting line based on how

00:10:22.125 --> 00:10:24.860
we're measuring a good fit,
which is the squared distance.

00:10:24.860 --> 00:10:26.930
These are on the line
that minimize

00:10:26.930 --> 00:10:27.930
that squared distance.

00:10:27.930 --> 00:10:29.850
What I'm going to do in next
video, and this is turning

00:10:29.850 --> 00:10:34.180
into like a six or seven video
saga on trying to prove the

00:10:34.180 --> 00:10:36.260
best-fitting line or finding
the formula for the

00:10:36.260 --> 00:10:36.770
best-fitting line.

00:10:36.770 --> 00:10:37.750
But it's interesting.

00:10:37.750 --> 00:10:39.810
There's all sorts of kind of
neat little mathematical

00:10:39.810 --> 00:10:41.390
things to ponder over here.

00:10:41.390 --> 00:10:43.930
But in the next video, we can
actually use this information.

00:10:43.930 --> 00:10:46.020
We could have just solved
the system straight up.

00:10:46.020 --> 00:10:48.550
But we can actually use this
information right here to

00:10:48.550 --> 00:10:49.710
solve for our m and b's.

00:10:49.710 --> 00:10:53.140
Maybe we'll do it both ways
depending on my mood.


Proof (part 2) minimizing squared error to regression line

WEBVTT
Kind: captions
Language: en

00:00:00.530 --> 00:00:03.580
Our goal is to simplify this
expression for the squared

00:00:03.580 --> 00:00:05.740
error between those n points.

00:00:05.740 --> 00:00:07.960
Just to remind ourselves
what we're doing, we

00:00:07.960 --> 00:00:09.420
have these n points.

00:00:09.420 --> 00:00:12.470
And we're taking the sum of the
squared error between each

00:00:12.470 --> 00:00:15.930
of those n points and
our actual line, y

00:00:15.930 --> 00:00:17.620
equals mx plus b.

00:00:17.620 --> 00:00:19.720
And we get this expression over
here, which we've been

00:00:19.720 --> 00:00:21.720
simplifying over the
last couple videos.

00:00:21.720 --> 00:00:23.190
We're going to try
to simplify this

00:00:23.190 --> 00:00:24.570
expression as much as possible.

00:00:24.570 --> 00:00:27.940
And then, we're going to
try to to minimize this

00:00:27.940 --> 00:00:28.620
expression.

00:00:28.620 --> 00:00:31.740
Or find the m and b values
that minimize it.

00:00:31.740 --> 00:00:34.790
Or I guess you could call it
the best fitting line.

00:00:34.790 --> 00:00:38.835
Now to do that, it looks like
we were just making the

00:00:38.835 --> 00:00:39.940
algebra even hairier
and hairier.

00:00:39.940 --> 00:00:42.910
But this next step is going to
simplify things a good bit.

00:00:42.910 --> 00:00:48.260
So just to show you that, if I
want to take the mean of all

00:00:48.260 --> 00:00:52.610
of the squared values of the
y's-- So that would be this.

00:00:52.610 --> 00:01:03.990
That would be y1 squared plus y2
squared plus all the way to

00:01:03.990 --> 00:01:05.750
yn squared.

00:01:05.750 --> 00:01:08.900
So I've summed n values,
n squared values.

00:01:08.900 --> 00:01:12.376
And then I want to divide
it by n, since there

00:01:12.376 --> 00:01:13.480
are n values here.

00:01:13.480 --> 00:01:19.560
And this is the mean
of the y's squared.

00:01:19.560 --> 00:01:24.240
That's how we can denote
it, just like that.

00:01:24.240 --> 00:01:29.390
Or, if you multiply both sides
of this equation by n, you get

00:01:29.390 --> 00:01:41.160
y1 squared plus y2 squared plus
all the way to yn squared

00:01:41.160 --> 00:01:56.970
is equal to n times the mean
of the squared values of y.

00:01:56.970 --> 00:02:02.860
And notice, this is exactly
what we have over here.

00:02:02.860 --> 00:02:07.280
That is n times the mean of
the squared values of y.

00:02:07.280 --> 00:02:11.830
Or the mean of the y squareds.

00:02:11.830 --> 00:02:19.580
And we can do that with each of
these terms. What is x1y1

00:02:19.580 --> 00:02:29.620
plus x2y2 plus all the way
to all the way to xnyn.

00:02:29.620 --> 00:02:32.460
Well, if we take this whole
sum and we divide it by n

00:02:32.460 --> 00:02:37.690
terms, this is going to be the
mean value for x times y.

00:02:37.690 --> 00:02:40.460
For each of those points,
you multiply x times y.

00:02:40.460 --> 00:02:42.460
And you find the mean of
all of those products.

00:02:42.460 --> 00:02:44.160
That's exactly what this is.

00:02:44.160 --> 00:02:47.180
Well, once again, you multiply
both sides of this equation by

00:02:47.180 --> 00:03:01.480
n, and you get x1y1 plus x2y2
plus all the way to xnyn is

00:03:01.480 --> 00:03:07.480
equal to n times the
mean of xy's.

00:03:12.180 --> 00:03:13.990
I think you see where
this is going.

00:03:13.990 --> 00:03:20.920
This term right here is going
to be equal to n times the

00:03:20.920 --> 00:03:24.200
mean of the products of xy.

00:03:24.200 --> 00:03:27.460
This term right here
is n times the

00:03:27.460 --> 00:03:29.300
mean of the y values.

00:03:31.940 --> 00:03:42.860
And then, this term right here
is n times the mean of the x

00:03:42.860 --> 00:03:45.050
squared values.

00:03:45.050 --> 00:03:49.340
This term right here is the
mean of the x's times n.

00:03:49.340 --> 00:03:51.530
If you divided this by n,
you'd get the mean.

00:03:51.530 --> 00:03:54.570
Since were not dividing it by
n, this is the mean times n.

00:03:54.570 --> 00:03:55.860
And then this is, obviously,
we don't

00:03:55.860 --> 00:03:56.700
the simplify anything.

00:03:56.700 --> 00:03:59.630
So let's rewrite everything
using our new notation,

00:03:59.630 --> 00:04:02.490
knowing that these are the
means of y squared,

00:04:02.490 --> 00:04:04.450
of xy, and all that.

00:04:04.450 --> 00:04:11.320
So our squared error to the
line from the sum of the

00:04:11.320 --> 00:04:14.150
squared error to the line from
the n points is going to be

00:04:14.150 --> 00:04:24.160
equal to-- this term right here
is n times the mean of

00:04:24.160 --> 00:04:26.370
the y squared values.

00:04:26.370 --> 00:04:36.550
This term right here is
equal to negative 2m.

00:04:36.550 --> 00:04:38.020
That's just that right there.

00:04:38.020 --> 00:04:44.200
Times n times the mean
of the xy values,

00:04:44.200 --> 00:04:45.730
the arithmetic mean.

00:04:45.730 --> 00:04:47.990
And then we have this
term over here.

00:04:47.990 --> 00:04:50.060
I think you can appreciate
this is simplifying the

00:04:50.060 --> 00:04:51.870
algebraic expression
a good bit.

00:04:51.870 --> 00:05:02.060
This term right over here is
going to be minus 2bn times

00:05:02.060 --> 00:05:04.900
the mean of the y values.

00:05:04.900 --> 00:05:16.980
And then we have plus m squared
times n times the mean

00:05:16.980 --> 00:05:21.260
of the x squared values.

00:05:21.260 --> 00:05:25.450
And then we have-- almost there,
home stretch-- we have

00:05:25.450 --> 00:05:33.360
this over here which is plus 2mb
times n times the mean of

00:05:33.360 --> 00:05:34.670
the x values.

00:05:34.670 --> 00:05:38.845
And then, finally, we have
plus nb squared.

00:05:41.480 --> 00:05:43.710
So really, in the last two to
three videos, all we've done

00:05:43.710 --> 00:05:48.370
is we simplified the expression
for the sum of the

00:05:48.370 --> 00:05:52.520
squared differences from the
those n points to this line, y

00:05:52.520 --> 00:05:55.900
equals mx plus b.

00:05:55.900 --> 00:06:00.220
So we're finished with the
hard core algebra stage.

00:06:00.220 --> 00:06:06.140
The next stage, we actually
want to optimize this.

00:06:08.690 --> 00:06:14.070
Maybe a the better way to talk
about it, we want to minimize

00:06:14.070 --> 00:06:16.150
this expression right
over here.

00:06:16.150 --> 00:06:19.320
We want to find the m and the
b values that minimize it.

00:06:19.320 --> 00:06:21.560
And to help visualize it, we're
going to start breaking

00:06:21.560 --> 00:06:22.260
into a little bit of

00:06:22.260 --> 00:06:24.150
three-dimensional calculus here.

00:06:24.150 --> 00:06:26.530
But hopefully it won't
be too daunting.

00:06:26.530 --> 00:06:27.620
If you've done any partial

00:06:27.620 --> 00:06:28.820
derivatives, it won't be difficult.

00:06:28.820 --> 00:06:30.630
This is a surface.

00:06:30.630 --> 00:06:34.460
If you view that you have
the x and y data points,

00:06:34.460 --> 00:06:37.340
everything here is a
constant except for

00:06:37.340 --> 00:06:39.250
the m's and the b's.

00:06:39.250 --> 00:06:41.310
We're assuming that we
have the x's and y's.

00:06:41.310 --> 00:06:44.020
So we can figure out the mean
of the squared values of y,

00:06:44.020 --> 00:06:47.610
the mean of the xy product, the
mean of the y's, the mean

00:06:47.610 --> 00:06:48.230
of the x squareds.

00:06:48.230 --> 00:06:50.670
We assume that those are
all actual numbers.

00:06:50.670 --> 00:06:54.410
So this expression right here,
it's actually going to be a

00:06:54.410 --> 00:06:56.550
surface in three dimensions.

00:06:56.550 --> 00:07:03.380
So you can imagine, this right
here, that is the m-axis.

00:07:03.380 --> 00:07:05.620
This right here is the b-axis.

00:07:12.940 --> 00:07:20.780
And then, you could imagine the
vertical axis to be the

00:07:20.780 --> 00:07:22.340
squared error.

00:07:22.340 --> 00:07:25.770
This is the squared error
of the line axis.

00:07:25.770 --> 00:07:28.670
So for any combination of m
and b, if you're in the mb

00:07:28.670 --> 00:07:30.710
plane, you pick some combination
of m and b.

00:07:30.710 --> 00:07:34.230
You put it into this expression
for the squared

00:07:34.230 --> 00:07:34.760
error of the line.

00:07:34.760 --> 00:07:36.360
It'll give you a point.

00:07:36.360 --> 00:07:40.600
If you do that for all of the
combinations of m's and b's,

00:07:40.600 --> 00:07:41.850
you're going to get a surface.

00:07:45.620 --> 00:07:47.730
And the surface is going to
look something like this.

00:07:47.730 --> 00:07:50.670
I'm going to try my
best to draw it.

00:07:50.670 --> 00:07:56.170
It's going to look like this.

00:07:56.170 --> 00:08:01.100
You could almost imagine
it as a kind of a bowl.

00:08:01.100 --> 00:08:02.370
Or you could even
think of it as a

00:08:02.370 --> 00:08:04.440
three-dimensional parabola.

00:08:04.440 --> 00:08:06.070
If you want to think
of it that way.

00:08:06.070 --> 00:08:08.670
Instead of a parabola that
just goes like this.

00:08:08.670 --> 00:08:11.350
If you were to kind of rotate
it around and distort it a

00:08:11.350 --> 00:08:13.700
little bit, you would get this
thing that looks kind of like

00:08:13.700 --> 00:08:16.350
a cup, or a thimble,
or whatever.

00:08:16.350 --> 00:08:19.970
And so what we want to do is
to find the m and b values

00:08:19.970 --> 00:08:22.070
that minimize.

00:08:22.070 --> 00:08:24.420
Notice, this is a
three-dimensional surface.

00:08:24.420 --> 00:08:26.480
I don't know if I'm doing
justice to it.

00:08:26.480 --> 00:08:31.110
So you can imagine a
three-dimensional surface that

00:08:31.110 --> 00:08:32.140
looks something like this.

00:08:32.140 --> 00:08:34.429
This is the back part that
you're not seeing.

00:08:34.429 --> 00:08:38.090
So that's the inside of our
three-dimensional surface.

00:08:38.090 --> 00:08:42.169
We want to find the m and b
values that minimize the value

00:08:42.169 --> 00:08:42.929
on the surface.

00:08:42.929 --> 00:08:46.040
So there's some m and b
value right over here

00:08:46.040 --> 00:08:49.390
that minimizes it.

00:08:49.390 --> 00:08:52.120
And I'll actually do the
calculation in the next video.

00:08:52.120 --> 00:08:56.500
But to do that, we're going to
find the partial derivative of

00:08:56.500 --> 00:08:58.910
this with respect to m.

00:08:58.910 --> 00:09:01.500
And we're going to find the
partial derivative of this

00:09:01.500 --> 00:09:04.370
with respect to b and set
both of them equal to 0.

00:09:04.370 --> 00:09:09.020
Because at this minimum point, I
guess you could say in three

00:09:09.020 --> 00:09:12.090
dimensions, this minimum point
on the surface is going to

00:09:12.090 --> 00:09:18.720
occur when the slope with
respect to m and the slope

00:09:18.720 --> 00:09:20.230
with respect to b is 0.

00:09:20.230 --> 00:09:25.010
So at that point, the partial
derivative of our squared

00:09:25.010 --> 00:09:28.860
error with respect to m is
going to be equal to 0.

00:09:28.860 --> 00:09:34.490
And the partial derivative of
our squared error with respect

00:09:34.490 --> 00:09:38.020
to b is going to
be equal to 0.

00:09:38.020 --> 00:09:39.890
So all we're going to do, in
the next video, is take the

00:09:39.890 --> 00:09:43.060
partial derivative of this
expression with respect to m,

00:09:43.060 --> 00:09:44.390
set that equal to 0.

00:09:44.390 --> 00:09:46.690
And the partial derivative of
this with respect to b, set

00:09:46.690 --> 00:09:47.680
that equal to 0.

00:09:47.680 --> 00:09:50.590
And then we're ready to solve
for the m in the b.

00:09:50.590 --> 00:09:53.580
Or the particular m and b.


Proof (part 1) minimizing squared error to regression line

WEBVTT
Kind: captions
Language: en

00:00:00.610 --> 00:00:04.090
In the last video, we showed
that the squared error between

00:00:04.090 --> 00:00:10.060
some line, y equals mx plus
b and each of these n data

00:00:10.060 --> 00:00:12.460
points is this expression
right over here.

00:00:12.460 --> 00:00:15.290
In this video, I'm really just
going to algebraically

00:00:15.290 --> 00:00:18.190
manipulate this expression so
that it's ready for the

00:00:18.190 --> 00:00:19.070
calculus stage.

00:00:19.070 --> 00:00:23.000
So we can actually optimize, we
can actually find the m and

00:00:23.000 --> 00:00:26.520
b values that minimize this
value right over here.

00:00:26.520 --> 00:00:29.500
So this is just going to be a
ton of algebraic manipulation.

00:00:29.500 --> 00:00:31.170
But I'll try to color code
it well so we don't

00:00:31.170 --> 00:00:33.030
get lost in the math.

00:00:33.030 --> 00:00:35.300
So let me just rewrite this
expression over here.

00:00:35.300 --> 00:00:37.370
So this whole video is just
going to be rewriting this

00:00:37.370 --> 00:00:38.430
over and over again.

00:00:38.430 --> 00:00:40.640
Just simplifying it a
bit with algebra.

00:00:40.640 --> 00:00:44.770
So this first term right over
here, y1 minus mx1 plus b

00:00:44.770 --> 00:00:48.400
squared, this is all going
to be the squared

00:00:48.400 --> 00:00:49.500
error of the line.

00:00:49.500 --> 00:00:52.370
So this first term over here,
I'll keep it in blue, is going

00:00:52.370 --> 00:01:03.800
to be if we just expand it, y1
squared minus 2 times y1 times

00:01:03.800 --> 00:01:12.970
mx1 plus b, plus mx1
plus b squared.

00:01:12.970 --> 00:01:15.930
All I did is I just squared
this binomial right here.

00:01:15.930 --> 00:01:19.480
You can imagine if this was a
minus b, it would be a squared

00:01:19.480 --> 00:01:22.720
minus 2ab plus b squared.

00:01:22.720 --> 00:01:23.880
That's all I did.

00:01:23.880 --> 00:01:25.860
Now I'll just have to do that
for each of the terms. And

00:01:25.860 --> 00:01:28.720
each term is only different by
the x and the y coordinates

00:01:28.720 --> 00:01:30.410
right over here.

00:01:30.410 --> 00:01:33.530
And I'll go down so that we
can kind of combine like

00:01:33.530 --> 00:01:38.070
terms. So this term over here
squared is going to be y2

00:01:38.070 --> 00:01:45.220
squared minus 2 times
y2 times mx2 plus b

00:01:45.220 --> 00:01:50.680
plus mx2 plus b squared.

00:01:50.680 --> 00:01:52.000
Same exact thing up here.

00:01:52.000 --> 00:01:57.330
Except now it was with x2 and
y2, as opposed to x1 and y1.

00:01:57.330 --> 00:01:59.660
And then we're just going to
keep doing that n times.

00:02:02.170 --> 00:02:05.780
We're going to do it for the
third, x3, y3, keep going,

00:02:05.780 --> 00:02:06.220
keep going.

00:02:06.220 --> 00:02:09.610
All the way until we get the
this nth term over here.

00:02:09.610 --> 00:02:12.640
And this nth term over here when
we square it is going to

00:02:12.640 --> 00:02:22.340
be yn squared minus 2yn
times mxn plus b,

00:02:22.340 --> 00:02:28.640
plus mxn plus b squared.

00:02:28.640 --> 00:02:31.610
Now, the next thing I want to
do is actually expand these

00:02:31.610 --> 00:02:34.130
out a little bit more.

00:02:34.130 --> 00:02:36.130
So let's actually scroll down.

00:02:36.130 --> 00:02:38.800
So this whole expression, I'm
just going to rewrite it, is

00:02:38.800 --> 00:02:41.670
the same thing as-- and remember
this is just the

00:02:41.670 --> 00:02:42.960
squared error of the line.

00:02:42.960 --> 00:02:44.830
So let me rewrite this
top line over here.

00:02:44.830 --> 00:02:48.920
This top line over here
is y1 squared.

00:02:48.920 --> 00:02:51.400
And then I'm going to
distribute this 2y1.

00:02:51.400 --> 00:02:58.740
So this is going to be
minus 2y1mx1, that's

00:02:58.740 --> 00:03:00.220
just that times that.

00:03:00.220 --> 00:03:01.470
Minus 2y1b.

00:03:05.770 --> 00:03:09.840
And then plus, and now let's
expand mx1 plus b squared.

00:03:09.840 --> 00:03:15.950
So that's going to be m squared
x1 squared, plus 2

00:03:15.950 --> 00:03:23.520
times mx1 times b
plus b squared.

00:03:23.520 --> 00:03:26.770
All I did, if was a plus b
squared, this is a squared

00:03:26.770 --> 00:03:29.330
plus 2ab plus b squared.

00:03:29.330 --> 00:03:31.340
And we're going to do that for
each of these terms. Or for

00:03:31.340 --> 00:03:33.370
each of these colors, I
guess you could say.

00:03:33.370 --> 00:03:35.480
So now let's move to
the second term.

00:03:35.480 --> 00:03:36.750
It's going to be
the same thing.

00:03:36.750 --> 00:03:38.620
But instead of y1's and
x1's, it's going

00:03:38.620 --> 00:03:40.530
to be y2's and x2's.

00:03:40.530 --> 00:03:52.410
So it is y2 squared minus
2y2mx2 minus 2y2b plus m

00:03:52.410 --> 00:04:01.280
squared x2 squared, plus 2 times
mx2b plus b squared.

00:04:01.280 --> 00:04:03.200
And we're going to keep
doing this all the way

00:04:03.200 --> 00:04:04.450
to get the nth term.

00:04:08.960 --> 00:04:10.690
I guess color we should say.

00:04:10.690 --> 00:04:16.755
So this is going to be yn
squared minus 2ynmxn.

00:04:22.750 --> 00:04:24.160
And you don't even
have to think.

00:04:24.160 --> 00:04:26.230
You just have to kind of
substitute these with n's now.

00:04:26.230 --> 00:04:27.260
We could actually
look at this.

00:04:27.260 --> 00:04:30.760
But it's going to be the
exact same thing.

00:04:30.760 --> 00:04:39.190
Minus 2ynb plus m squared
xn squared, plus

00:04:39.190 --> 00:04:44.920
2mxnb plus b squared.

00:04:44.920 --> 00:04:48.340
So once again, this is just the
squared error of that line

00:04:48.340 --> 00:04:49.320
with n points.

00:04:49.320 --> 00:04:53.270
Between those n points and the
line y equals mx plus b.

00:04:53.270 --> 00:04:56.200
So let's see if we can simplify
this somehow.

00:04:56.200 --> 00:05:00.390
And to do that what I'm going to
do is I'm going to kind of

00:05:00.390 --> 00:05:03.300
try to add up a bunch
of these terms here.

00:05:03.300 --> 00:05:08.880
So if I were to add up all of
these terms right here, if I

00:05:08.880 --> 00:05:11.060
were to add up this
column right over

00:05:11.060 --> 00:05:12.420
there, what do I get?

00:05:12.420 --> 00:05:22.300
It's going to be y1 squared plus
y2 squared all the way to

00:05:22.300 --> 00:05:25.230
all the way to yn squared.

00:05:25.230 --> 00:05:27.570
That's those terms
right over there.

00:05:27.570 --> 00:05:29.180
So I'm going to have that.

00:05:29.180 --> 00:05:37.800
And then have this common
2m amongst all of

00:05:37.800 --> 00:05:38.800
these terms over here.

00:05:38.800 --> 00:05:39.960
So let me write that down.

00:05:39.960 --> 00:05:45.920
So then you have this 2m
here, 2m here, 2m here.

00:05:45.920 --> 00:05:47.210
Let me put parentheses
around here.

00:05:47.210 --> 00:05:49.300
So you have these terms
all added up.

00:05:49.300 --> 00:05:58.690
Then you have minus 2m times all
of these terms. Actually,

00:05:58.690 --> 00:06:01.510
let me color code it so you
see what we're doing.

00:06:01.510 --> 00:06:04.580
I want to be very careful
with this math so

00:06:04.580 --> 00:06:06.040
nothing seems too confusing.

00:06:06.040 --> 00:06:08.120
Although this is really just
algebraic manipulation.

00:06:08.120 --> 00:06:13.440
If I had all of these up, I get
y1 squared plus y2 squared

00:06:13.440 --> 00:06:16.380
all the way to yn squared.

00:06:16.380 --> 00:06:19.080
I'll put some parentheses
around that.

00:06:19.080 --> 00:06:22.410
And then to that, we have this
common term, we have this

00:06:22.410 --> 00:06:25.460
minus 2m, minus 2m, minus 2m.

00:06:25.460 --> 00:06:27.680
And so we can distribute
those out.

00:06:27.680 --> 00:06:31.890
And so I should actually
write it like this.

00:06:31.890 --> 00:06:37.150
So we have a minus 2m, once we
distribute it out up here,

00:06:37.150 --> 00:06:40.080
we're just going to be
left with a y1x1.

00:06:40.080 --> 00:06:41.350
Or maybe I can call
it an x1y1.

00:06:44.580 --> 00:06:46.860
That's that over there with
the 2m factored out.

00:06:49.360 --> 00:06:51.015
Let me do that in
another color.

00:06:51.015 --> 00:06:52.960
I want to make this
easy to read.

00:06:52.960 --> 00:06:57.070
Plus x2y2.

00:06:57.070 --> 00:06:58.320
Plus xnyn.

00:07:01.790 --> 00:07:04.206
Well we're going to keep adding
up-- we're going to do

00:07:04.206 --> 00:07:05.660
this n times.

00:07:05.660 --> 00:07:09.770
All the way to plus xnyn.

00:07:09.770 --> 00:07:13.030
This last term over here,
ynxn, same thing.

00:07:13.030 --> 00:07:15.430
So that's the sum.

00:07:15.430 --> 00:07:20.860
So this stuff over here, the sum
of all of this stuff right

00:07:20.860 --> 00:07:26.960
over here, is the same thing as
this term right over here.

00:07:26.960 --> 00:07:29.330
And then we have to sum
this right over here.

00:07:29.330 --> 00:07:35.510
And you see again, we can factor
out here a minus 2b out

00:07:35.510 --> 00:07:50.350
of all of these terms. So we
have minus 2b times y1 plus y2

00:07:50.350 --> 00:07:54.180
plus all the way to to yn.

00:07:57.780 --> 00:08:01.670
So this business.

00:08:01.670 --> 00:08:06.880
These terms right over here,
when you add them up, give you

00:08:06.880 --> 00:08:09.650
these terms, or this term,
right over there.

00:08:09.650 --> 00:08:10.840
And let's just keep going.

00:08:10.840 --> 00:08:12.420
And in the next video, we're
probably going to run out of

00:08:12.420 --> 00:08:15.250
time in this one, I'll simplify
this more and clean

00:08:15.250 --> 00:08:17.370
up the algebra a good bit.

00:08:17.370 --> 00:08:19.260
So then the next term, what
is this going to be?

00:08:19.260 --> 00:08:22.190
Same drill.

00:08:22.190 --> 00:08:24.100
We can factor out
an m squared.

00:08:24.100 --> 00:08:31.750
So we have m squared times
times x1 squared plus x2

00:08:31.750 --> 00:08:36.650
squared-- actually, I want to
color code them, I forgot to

00:08:36.650 --> 00:08:37.900
color code these over here.

00:08:42.890 --> 00:08:48.140
Plus all the way
to xn squared.

00:08:48.140 --> 00:08:49.200
Let me color code these.

00:08:49.200 --> 00:08:52.060
This was a yn squared.

00:08:52.060 --> 00:08:55.600
And this over here
was a y2 squared.

00:08:55.600 --> 00:08:58.150
So this is exactly this.

00:08:58.150 --> 00:09:04.900
So in this last step we just
did, this thing over here is

00:09:04.900 --> 00:09:06.230
this thing right over here.

00:09:06.230 --> 00:09:07.340
And of course we
have to add it.

00:09:07.340 --> 00:09:08.980
So I'll put a plus out front.

00:09:08.980 --> 00:09:12.360
We're almost done with this
stage of the simplification.

00:09:12.360 --> 00:09:19.130
So over here, we have a common
2mb, so let's put a plus 2mb

00:09:19.130 --> 00:09:30.370
times, once again, x1 plus x2
plus all the way to xn.

00:09:36.450 --> 00:09:43.730
So this term right over here
this is the exact same thing

00:09:43.730 --> 00:09:45.540
as this term over here.

00:09:45.540 --> 00:09:48.610
And then finally, we have a b
squared in each of these.

00:09:48.610 --> 00:09:50.720
And how many of these b
squared do we have?

00:09:50.720 --> 00:09:52.850
Well we have n of these
lines, right?

00:09:52.850 --> 00:09:55.050
This is the first line, second
line, then bunch, bunch, bunch

00:09:55.050 --> 00:09:56.570
all the way to the nth line.

00:09:56.570 --> 00:10:00.170
So we have b squared added
to itself n times.

00:10:00.170 --> 00:10:06.320
So this right over here is
just b squared n times.

00:10:06.320 --> 00:10:12.560
So we'll just write that as
plus n times b squared.

00:10:12.560 --> 00:10:15.120
Let me remind ourselves what
this is all about.

00:10:15.120 --> 00:10:18.960
This is all just algebraic
manipulation of the squared

00:10:18.960 --> 00:10:23.270
error between those n points
and the line y

00:10:23.270 --> 00:10:25.350
equals mx plus b.

00:10:25.350 --> 00:10:27.540
It doesn't look like I've
simplified it much.

00:10:27.540 --> 00:10:29.020
And I'm going to stop in
the video right now.

00:10:29.020 --> 00:10:31.080
In the next video, we're just
going to take off right here

00:10:31.080 --> 00:10:33.730
and try to simplify
this thing.


Squared error of regression line

WEBVTT
Kind: captions
Language: en

00:00:00.480 --> 00:00:03.200
In the next few videos I'm going
to embark on something

00:00:03.200 --> 00:00:05.420
that will just result in
a formula that's pretty

00:00:05.420 --> 00:00:06.870
straightforward to apply.

00:00:06.870 --> 00:00:10.260
And in most statistics classes,
you'll just see that

00:00:10.260 --> 00:00:11.150
end product.

00:00:11.150 --> 00:00:12.870
But I actually want to show
how to get there.

00:00:12.870 --> 00:00:14.290
But I just want to warn
you right now.

00:00:14.290 --> 00:00:16.170
It's going to be a lot
of hairy math,

00:00:16.170 --> 00:00:17.890
most of it hairy algebra.

00:00:17.890 --> 00:00:20.290
And then we're actually going
have to do a little bit of

00:00:20.290 --> 00:00:21.330
calculus near the end.

00:00:21.330 --> 00:00:22.970
We're going to have to do a
few partial derivatives.

00:00:22.970 --> 00:00:25.870
So if any of that sounds
daunting, or sounds like

00:00:25.870 --> 00:00:29.290
something that will discourage
you in some way, you don't

00:00:29.290 --> 00:00:29.950
have to watch it.

00:00:29.950 --> 00:00:32.619
You could skip to the end and
just get the formula that

00:00:32.619 --> 00:00:33.810
we're going to derive.

00:00:33.810 --> 00:00:36.040
But I, at least, find it
pretty satisfying to

00:00:36.040 --> 00:00:37.450
actually derive it.

00:00:37.450 --> 00:00:40.020
So what we're going to think
about here is, let's say we

00:00:40.020 --> 00:00:46.870
have n points on a
coordinate plane.

00:00:46.870 --> 00:00:48.670
And they all don't have to
be in the first quadrant.

00:00:48.670 --> 00:00:51.420
But just for simplicity of
visualization, I'll draw them

00:00:51.420 --> 00:00:52.740
all in the first quadarant.

00:00:52.740 --> 00:00:55.910
So let's say I have this
point right over here.

00:00:55.910 --> 00:00:57.160
Let me do them in different
colors.

00:01:01.380 --> 00:01:05.580
And that coordinate is x1, y1.

00:01:05.580 --> 00:01:08.820
And then let's say I have
another point over here.

00:01:14.590 --> 00:01:18.970
The coordinates there
are x2, y2.

00:01:18.970 --> 00:01:20.940
And then I can keep
adding points.

00:01:20.940 --> 00:01:22.710
And I could keep drawing them.

00:01:22.710 --> 00:01:24.130
We'd just have a
ton of points.

00:01:24.130 --> 00:01:25.990
There and there and there.

00:01:25.990 --> 00:01:28.090
And we go all the way
to the nth point.

00:01:31.070 --> 00:01:34.330
Maybe it's over here.

00:01:34.330 --> 00:01:38.180
And we're just going to
call that xn, yn.

00:01:38.180 --> 00:01:39.840
So we have n points here.

00:01:39.840 --> 00:01:42.120
I haven't drawn all of
the actual points.

00:01:42.120 --> 00:01:46.720
But what I want to do is find
a line that minimizes the

00:01:46.720 --> 00:01:49.280
squared distances to these
different points.

00:01:49.280 --> 00:01:49.990
So let's think about it.

00:01:49.990 --> 00:01:52.610
Let's visualize that
line for a second.

00:01:52.610 --> 00:01:54.090
So there's going to
be some line.

00:01:54.090 --> 00:01:56.590
And I'm going to try to draw a
line that kind of approximates

00:01:56.590 --> 00:01:58.590
what these points are doing.

00:01:58.590 --> 00:02:00.930
So let me draw this line here.

00:02:00.930 --> 00:02:04.710
So maybe the line might look
something like this.

00:02:04.710 --> 00:02:09.330
I'm going to try my best
to approximate it.

00:02:09.330 --> 00:02:10.500
Actually, let me draw it
little bit different.

00:02:10.500 --> 00:02:15.230
Maybe it looks something
like that.

00:02:15.230 --> 00:02:17.190
I don't even know what it
looks like right now.

00:02:17.190 --> 00:02:20.470
And what we want to do is
minimize this squared error

00:02:20.470 --> 00:02:22.110
from each of these points
to the line.

00:02:22.110 --> 00:02:23.840
So let's think about
what that means.

00:02:23.840 --> 00:02:30.230
So if the equation of this line
right here is y is equal

00:02:30.230 --> 00:02:32.760
to mx plus b.

00:02:32.760 --> 00:02:35.080
And this just comes straight
out of Algebra 1.

00:02:35.080 --> 00:02:40.800
This is the slope on the line,
and this is the y-intercept.

00:02:40.800 --> 00:02:45.120
This is actually
the point 0, b.

00:02:45.120 --> 00:02:48.780
What I want to do, and that's
what the the topic of the next

00:02:48.780 --> 00:02:53.110
few videos are going to be, I
want to find an m and a b.

00:02:53.110 --> 00:02:55.750
So I want to find these two
things that define this line.

00:02:55.750 --> 00:02:59.060
So that it minimizes
the squared error.

00:02:59.060 --> 00:03:02.040
So let me define what
the error even is.

00:03:02.040 --> 00:03:05.050
So for each of these points, the
error between it and the

00:03:05.050 --> 00:03:07.470
line is the vertical distance.

00:03:07.470 --> 00:03:11.670
So this right here we
can call error one.

00:03:15.150 --> 00:03:19.670
And then this right here
would be error two.

00:03:19.670 --> 00:03:23.680
It would be the vertical
distance between that point

00:03:23.680 --> 00:03:24.410
and the line.

00:03:24.410 --> 00:03:26.790
Or you can think of it as the y
value of this point and the

00:03:26.790 --> 00:03:28.500
y value of the line.

00:03:28.500 --> 00:03:30.560
And you just keep going all
the way to the endpoint

00:03:30.560 --> 00:03:32.760
between the y value of
this point and the y

00:03:32.760 --> 00:03:34.840
value of the line.

00:03:34.840 --> 00:03:38.060
So this error right here, error
one, if you think about

00:03:38.060 --> 00:03:42.880
it, it is this value right
here, this y value.

00:03:42.880 --> 00:03:47.570
It's equal to y1 minus
this y value.

00:03:47.570 --> 00:03:49.830
Well what's this y value
going to be?

00:03:49.830 --> 00:03:52.820
Well over here we have
x is equal to x1.

00:03:52.820 --> 00:03:57.970
And this point is the
point m x1 plus b.

00:03:57.970 --> 00:04:01.400
You take x1 into this equation
of the line and you're going

00:04:01.400 --> 00:04:03.380
to get this point
right over here.

00:04:03.380 --> 00:04:09.190
So that's literally going to
be equal to m x1 plus b.

00:04:09.190 --> 00:04:10.340
That's that first error.

00:04:10.340 --> 00:04:12.450
And we can keep doing it
with all the points.

00:04:12.450 --> 00:04:16.450
This error right over here
is going to be y2

00:04:16.450 --> 00:04:21.700
minus m x2 plus b.

00:04:21.700 --> 00:04:25.290
And then this point right
here is m x2 plus b.

00:04:25.290 --> 00:04:28.580
The value when you take
x2 into this line.

00:04:28.580 --> 00:04:31.940
And we keep going all the
way to our nth point.

00:04:31.940 --> 00:04:43.630
This error right here is going
to be yn minus m xn plus b.

00:04:43.630 --> 00:04:48.040
Now, so if we wanted to just
take the straight up sum of

00:04:48.040 --> 00:04:50.460
the errors, we could just
some these things up.

00:04:50.460 --> 00:04:53.390
But what we want to do is a
minimize the square of the

00:04:53.390 --> 00:04:56.520
error between each of these
points, each of these n points

00:04:56.520 --> 00:04:57.040
on the line.

00:04:57.040 --> 00:05:07.040
So let me define the squared
error against this line as

00:05:07.040 --> 00:05:10.030
being equal to the sum of
these squared errors.

00:05:10.030 --> 00:05:14.250
So this error right here, or
error one we could call it, is

00:05:14.250 --> 00:05:19.110
y1 minus m x1 plus b.

00:05:19.110 --> 00:05:20.620
And we're going to square it.

00:05:20.620 --> 00:05:23.330
So this is the error
one squared.

00:05:23.330 --> 00:05:25.960
And we're going to go to
error two squared.

00:05:25.960 --> 00:05:36.580
Error two squared is y2
minus m x2 plus b.

00:05:36.580 --> 00:05:40.560
And then we're going to
square that error.

00:05:40.560 --> 00:05:45.100
And then we keep going, we're
going to go n spaces, or n

00:05:45.100 --> 00:05:46.340
points I should say.

00:05:46.340 --> 00:05:49.290
We keep going all the way
to this nth error.

00:05:49.290 --> 00:05:55.690
The nth error is going to
be yn minus m xn plus b.

00:05:55.690 --> 00:05:57.705
And then we're going
to square it.

00:06:01.850 --> 00:06:05.480
So this is the squared
error of the line.

00:06:05.480 --> 00:06:13.870
And over the next few videos, is
I want to find the m and b

00:06:13.870 --> 00:06:25.360
that minimizes the squared error
of this line right here.

00:06:25.360 --> 00:06:30.330
So if you viewed this as the
best metric for how good a fit

00:06:30.330 --> 00:06:33.850
a line is, we're going to try to
find the best fitting line

00:06:33.850 --> 00:06:35.220
for these points.

00:06:35.220 --> 00:06:36.610
And I'll continue in
the next video.

00:06:36.610 --> 00:06:40.120
Because I find that with these
very hairy math problems, it's

00:06:40.120 --> 00:06:42.210
good to kind of just deliver
one concept at a time.

00:06:42.210 --> 00:06:43.750
And it also minimizes my

00:06:43.750 --> 00:06:46.040
probability of making a mistake.


Comparing population proportions 2

WEBVTT
Kind: captions
Language: en

00:00:00.810 --> 00:00:03.230
Where we left off in the last
video, we were trying to

00:00:03.230 --> 00:00:05.340
figure out if there's a
meaningful difference between

00:00:05.340 --> 00:00:07.850
the proportion of men voting
for a candidate and the

00:00:07.850 --> 00:00:09.080
proportion of women.

00:00:09.080 --> 00:00:14.740
We sampled 1,000 men, sampled
1,000 women, and we got a

00:00:14.740 --> 00:00:17.140
sample proportion for
each of them.

00:00:17.140 --> 00:00:20.650
We got 0.642 for the men and
0.591 for the women.

00:00:20.650 --> 00:00:24.530
But our goal is to get a 95%
confidence interval.

00:00:24.530 --> 00:00:29.610
So just based on our actual
sample, we got-- let me write

00:00:29.610 --> 00:00:31.180
it over here.

00:00:31.180 --> 00:00:34.110
We got our sample proportion for
the men minus-- let me do

00:00:34.110 --> 00:00:36.040
this in a neutral color.

00:00:36.040 --> 00:00:40.750
We got our sample proportion for
the men minus our sample

00:00:40.750 --> 00:00:46.060
proportion for the women
being 0.642 minus

00:00:46.060 --> 00:00:52.400
0.591, that's 0.051.

00:00:52.400 --> 00:00:55.680
I just subtracted
this from that.

00:00:55.680 --> 00:01:01.600
So what we want to do when we
want a confidence interval, we

00:01:01.600 --> 00:01:02.600
want to be confident.

00:01:02.600 --> 00:01:05.160
I'll always have to say that
because it's not going to be

00:01:05.160 --> 00:01:06.310
super precise.

00:01:06.310 --> 00:01:15.050
We want to be confident that
there's a 95% chance that this

00:01:15.050 --> 00:01:20.610
thing right here-- remember,
when we took the two sample

00:01:20.610 --> 00:01:23.630
proportions and took their
difference, it's like taking a

00:01:23.630 --> 00:01:26.930
sample from the sampling
distribution of the statistic.

00:01:26.930 --> 00:01:31.300
So we want a 95% chance that
the true mean or the true

00:01:31.300 --> 00:01:37.360
value of this, that P1 minus P2
is within some range, let's

00:01:37.360 --> 00:01:46.430
say is within d, I'll say d for
distance, of the actual

00:01:46.430 --> 00:01:49.020
difference that we got
with our samples.

00:01:49.020 --> 00:01:54.470
Within d of 0.051.

00:01:54.470 --> 00:01:56.330
And I write this multiple
times, but I always

00:01:56.330 --> 00:01:56.890
write it this way.

00:01:56.890 --> 00:01:58.220
I don't just give the
formula that you

00:01:58.220 --> 00:01:59.230
normally see in books.

00:01:59.230 --> 00:02:01.490
It's very easy to memorize if
you do, but this way, you

00:02:01.490 --> 00:02:03.410
actually see why
this confidence

00:02:03.410 --> 00:02:04.270
interval makes sense.

00:02:04.270 --> 00:02:08.960
If there's a 95% chance that P1
minus P2, the actual true

00:02:08.960 --> 00:02:11.650
proportions, the difference of
the true proportions, is

00:02:11.650 --> 00:02:15.950
within d of the difference
between our sample

00:02:15.950 --> 00:02:21.230
proportions, this statement
right here is the same thing

00:02:21.230 --> 00:02:38.120
that there's a 95% chance that
0.051 is within d of this

00:02:38.120 --> 00:02:41.730
actual parameter, P1 minus
P2, which is the same

00:02:41.730 --> 00:02:42.830
thing as the mean.

00:02:42.830 --> 00:02:51.070
So we need to figure out some
distance around this mean,

00:02:51.070 --> 00:02:54.140
where if we take a random sample
from this, and this is

00:02:54.140 --> 00:03:01.740
a random sample from this
distribution, it has a 95%

00:03:01.740 --> 00:03:05.050
chance of being within d of
this mean, because if it's

00:03:05.050 --> 00:03:08.100
within d of the mean, then
there's also a 95% chance that

00:03:08.100 --> 00:03:10.890
the mean is within d of our
sample, and then we'll have

00:03:10.890 --> 00:03:12.310
our confidence interval.

00:03:12.310 --> 00:03:15.540
Our confidence interval would be
this value plus d and this

00:03:15.540 --> 00:03:17.000
value minus d.

00:03:17.000 --> 00:03:18.100
So what are these?

00:03:18.100 --> 00:03:19.960
What is the distance d?

00:03:19.960 --> 00:03:22.980
Well, in a normalized normal
distribution, I got a Z-table

00:03:22.980 --> 00:03:25.440
right over here, and we can
assume everything is normal,

00:03:25.440 --> 00:03:28.520
especially the sampling
distributions because our n is

00:03:28.520 --> 00:03:32.170
so big and also our proportion
is not close to zero or one.

00:03:32.170 --> 00:03:35.460
It's nice and close to the
middle, so we don't end up

00:03:35.460 --> 00:03:37.820
with all these weird cases
near the edges.

00:03:37.820 --> 00:03:41.400
We say, OK, how do we contain
the middle 95%?

00:03:41.400 --> 00:03:45.000
How many standard deviations in
a normal distribution do we

00:03:45.000 --> 00:03:51.060
need to be away from the mean in
order to contain 95% of the

00:03:51.060 --> 00:03:52.000
probability?

00:03:52.000 --> 00:03:54.460
Now these Z-tables, and we've
done it multiple times, give

00:03:54.460 --> 00:03:55.730
you cumulative distribution.

00:03:55.730 --> 00:03:59.090
We're looking for this Z-value
right over here.

00:03:59.090 --> 00:04:02.810
If it's containing 95%, you're
going to have 2.5% over here

00:04:02.810 --> 00:04:06.710
and you're going to have
2.5% over here.

00:04:06.710 --> 00:04:10.180
So from a Z-table's point of
view, this Z-table gives you

00:04:10.180 --> 00:04:15.630
the cumulative probability
up to that Z-value.

00:04:15.630 --> 00:04:19.850
So what we're looking for
is actually 97.5%.

00:04:19.850 --> 00:04:22.920
We're looking for something
that contains all

00:04:22.920 --> 00:04:24.170
of this over here.

00:04:28.050 --> 00:04:31.420
If we get the Z-value and then
apply it on both sides, then

00:04:31.420 --> 00:04:33.930
we're going to have something
that contains 95%.

00:04:33.930 --> 00:04:35.880
So let's look up the 97.5.

00:04:35.880 --> 00:04:42.170
97.5 is right over there, and
that is 1.96 standard

00:04:42.170 --> 00:04:43.450
deviations.

00:04:43.450 --> 00:04:49.040
So this is 1.96 for a normalized
standard deviation,

00:04:49.040 --> 00:04:52.460
or a Z-score of 1.96.

00:04:52.460 --> 00:04:56.140
So if we looked to this normal
distribution right over here,

00:04:56.140 --> 00:05:02.740
this distance that we care
about is going to be 1.96

00:05:02.740 --> 00:05:05.650
times the standard deviation of
this distribution, so it's

00:05:05.650 --> 00:05:09.710
going to be 1.96 times
all of this business.

00:05:09.710 --> 00:05:13.650
1.96 times the standard
deviation of this

00:05:13.650 --> 00:05:16.300
distribution.

00:05:16.300 --> 00:05:18.450
And so we just need to
calculate this and

00:05:18.450 --> 00:05:21.870
multiply it by 1.96.

00:05:21.870 --> 00:05:23.440
Now, we have a problem.

00:05:23.440 --> 00:05:26.410
We don't know the true
parameters P1 and P2.

00:05:26.410 --> 00:05:28.990
We don't know the true
population parameters.

00:05:28.990 --> 00:05:30.610
We don't know P1 and P2.

00:05:30.610 --> 00:05:31.990
That's part of the problem.

00:05:31.990 --> 00:05:33.170
We're trying to figure out
if there's a meaningful

00:05:33.170 --> 00:05:35.110
difference between P1 and P2.

00:05:35.110 --> 00:05:36.770
But we've seen it
multiple times.

00:05:36.770 --> 00:05:43.830
Since our sample size is a
large, we can estimate P1 and

00:05:43.830 --> 00:05:46.760
P2 with our sample
proportions.

00:05:52.210 --> 00:05:57.800
So we could change this to
approximately and we can use

00:05:57.800 --> 00:06:01.540
our sample proportions.

00:06:01.540 --> 00:06:02.710
And we know what those
values are.

00:06:02.710 --> 00:06:06.870
And actually this n over
here was 1,000.

00:06:06.870 --> 00:06:07.680
So let's figure that out.

00:06:07.680 --> 00:06:11.150
Let's just get the
calculator out.

00:06:11.150 --> 00:06:14.360
It's just going to be one
big calculation here.

00:06:14.360 --> 00:06:20.260
So what we have is the square
root, and then in parentheses,

00:06:20.260 --> 00:06:28.816
our sample proportion for the
men is 0.642, and then we're

00:06:28.816 --> 00:06:39.310
going to multiply that times
1 minus 0.642, close

00:06:39.310 --> 00:06:41.990
parentheses.

00:06:41.990 --> 00:06:46.020
That's that over there
divided by 1,000.

00:06:46.020 --> 00:06:49.710
And then we're going to add to
that plus-- do the same thing

00:06:49.710 --> 00:06:50.930
for the women.

00:06:50.930 --> 00:07:06.300
Our sample proportion is 0.591
times 1 minus 0.591.

00:07:06.300 --> 00:07:10.810
So that's this term right over
here divided by 1,000.

00:07:10.810 --> 00:07:12.520
Once again, I need to get
the parentheses right.

00:07:16.480 --> 00:07:19.010
And then we just need to close
the parentheses, this original

00:07:19.010 --> 00:07:20.770
parentheses, because we're
taking the square root of

00:07:20.770 --> 00:07:22.020
everything.

00:07:25.130 --> 00:07:33.540
So we get 0.021, or maybe
we'll say 0.022.

00:07:33.540 --> 00:07:44.040
So this value right here
is approximately 0.022.

00:07:44.040 --> 00:07:47.550
So going back to our question,
or this distance that we care

00:07:47.550 --> 00:07:51.180
about, this value is going to be
approximately, or our best

00:07:51.180 --> 00:07:55.080
estimate of it, is 0.022.

00:07:55.080 --> 00:07:56.640
So let's just multiply that.

00:07:56.640 --> 00:08:10.880
0.022 times 1.96 gives 0.043.

00:08:10.880 --> 00:08:12.180
I'll just round it.

00:08:12.180 --> 00:08:21.860
So this right here is
equal to 0.043.

00:08:21.860 --> 00:08:24.690
And just like that, we have
our confidence interval.

00:08:24.690 --> 00:08:32.900
We know that there's a 95%
chance that the true

00:08:32.900 --> 00:08:43.559
difference of the proportions is
within 0.043 of the actual

00:08:43.559 --> 00:08:46.240
difference of our sample
proportions that we got.

00:08:46.240 --> 00:08:48.100
Or if we actually want to get
an interval, we take this

00:08:48.100 --> 00:08:50.200
value minus 0.043.

00:08:50.200 --> 00:08:51.590
So let's do that.

00:08:51.590 --> 00:09:01.910
So we could have 0.051
minus 0.043 is

00:09:01.910 --> 00:09:04.320
going to give us 0.008.

00:09:04.320 --> 00:09:08.130
And then if we add
it, so 0.051 plus

00:09:08.130 --> 00:09:14.550
0.043, it gives us 0.094.

00:09:14.550 --> 00:09:20.480
So the 95% confidence interval
between the proportions of men

00:09:20.480 --> 00:09:22.390
and the proportion of women who
are going to vote for the

00:09:22.390 --> 00:09:45.450
candidate for P1 minus
P2 is 0.008 to 0.094.

00:09:45.450 --> 00:09:48.720
I have it right here
on the calculator.

00:09:48.720 --> 00:09:49.310
And we're done.

00:09:49.310 --> 00:09:53.290
So it does seem we're confident
that there's a 95%

00:09:53.290 --> 00:09:57.150
chance that men are more
likely to vote for the

00:09:57.150 --> 00:09:59.460
candidate than women.


Comparing population proportions 1

WEBVTT
Kind: captions
Language: en

00:00:00.660 --> 00:00:02.880
Let's say there's an election
coming up and I want to figure

00:00:02.880 --> 00:00:05.000
out if there's a meaningful
difference between the

00:00:05.000 --> 00:00:07.430
proportion of men and the
proportion of women that are

00:00:07.430 --> 00:00:08.990
going to vote for a candidate.

00:00:08.990 --> 00:00:11.160
So let's look at the population
distributions here.

00:00:11.160 --> 00:00:15.820
So we have the men, some
proportion are going to vote

00:00:15.820 --> 00:00:17.240
for the candidate.

00:00:17.240 --> 00:00:19.025
We'll call that P1.

00:00:19.025 --> 00:00:22.460
So this is the proportion that
will vote for the candidate.

00:00:22.460 --> 00:00:24.630
And the rest of the men will
not vote for the candidate.

00:00:24.630 --> 00:00:29.030
So 1 minus P1 will not vote
for the candidate.

00:00:29.030 --> 00:00:30.760
And then for the women,
you're going to

00:00:30.760 --> 00:00:32.360
see something similar.

00:00:32.360 --> 00:00:34.920
So this is the women
right over here.

00:00:34.920 --> 00:00:39.670
And some proportion will
vote for the candidate.

00:00:39.670 --> 00:00:42.040
We don't know if it's the same
as P1, we don't know if it's

00:00:42.040 --> 00:00:44.300
same as the men, so
we'll call it P2.

00:00:44.300 --> 00:00:45.850
And then the rest of
the women will not

00:00:45.850 --> 00:00:47.120
vote for the candidate.

00:00:47.120 --> 00:00:49.440
1 minus P2.

00:00:49.440 --> 00:00:52.370
So the not voting are zeroes,
the ones that

00:00:52.370 --> 00:00:54.250
are voting are ones.

00:00:54.250 --> 00:00:57.660
And these are both Bernoulli
distributions and we know,

00:00:57.660 --> 00:01:01.060
just because this'll be useful
later on, that the means of

00:01:01.060 --> 00:01:03.360
this distribution are the same
as the proportion that will

00:01:03.360 --> 00:01:05.069
vote for it.

00:01:05.069 --> 00:01:10.320
So the mean of the men, or the
proportion of the men that

00:01:10.320 --> 00:01:12.860
will vote, so we'll call that
mean one, is equal to P1.

00:01:18.220 --> 00:01:19.470
I should do everything
in yellow.

00:01:21.990 --> 00:01:27.740
So the mean of this distribution
is P1.

00:01:27.740 --> 00:01:30.410
The variance of this
distribution, we'll call that

00:01:30.410 --> 00:01:35.590
variance one, is just these two
proportions multiplied by

00:01:35.590 --> 00:01:36.030
each other.

00:01:36.030 --> 00:01:39.110
So it's P1 times 1 minus P1.

00:01:39.110 --> 00:01:41.220
And we saw this many many videos
ago when we learned

00:01:41.220 --> 00:01:43.180
about Bernoulli distributions.

00:01:43.180 --> 00:01:44.430
And we're going to see
the exact same

00:01:44.430 --> 00:01:46.130
thing with the women.

00:01:46.130 --> 00:01:48.890
The mean of this Bernoulli
distribution

00:01:48.890 --> 00:01:50.460
is going to be P2.

00:01:50.460 --> 00:01:56.040
And then the variance of this
Bernoulli distribution is

00:01:56.040 --> 00:01:58.750
going to be these two
proportions multiplied.

00:01:58.750 --> 00:02:03.530
So P2 times 1 minus P2.

00:02:03.530 --> 00:02:06.370
Now, what I want to do, and
I think I said this at the

00:02:06.370 --> 00:02:08.190
beginning of the video, is I
want to figure out if there's

00:02:08.190 --> 00:02:10.820
a meaningful difference between
the way that the men

00:02:10.820 --> 00:02:12.470
will vote and the
women will vote.

00:02:12.470 --> 00:02:19.750
I want to figure out, let
me write this, is this

00:02:19.750 --> 00:02:21.500
meaningful?

00:02:21.500 --> 00:02:24.640
So is there a meaningful
difference here?

00:02:24.640 --> 00:02:26.760
And what we're going to do in
this video is try to come up

00:02:26.760 --> 00:02:31.660
with a 95% confidence interval
for this parameter.

00:02:31.660 --> 00:02:33.840
This difference of parameters
is still a parameter.

00:02:33.840 --> 00:02:36.590
We don't know what the true
difference of these two

00:02:36.590 --> 00:02:39.830
population parameters are.

00:02:39.830 --> 00:02:41.750
Or these two population
proportions.

00:02:41.750 --> 00:02:48.890
But we're going to try to come
up with a 95% confidence

00:02:48.890 --> 00:02:53.930
interval for that difference.

00:02:53.930 --> 00:02:59.070
And the way we do that, we go
out and we find 1,000 men

00:02:59.070 --> 00:02:59.720
likely to vote.

00:02:59.720 --> 00:03:01.790
And 1,000 women likely
to vote.

00:03:01.790 --> 00:03:02.980
So let's write this down.

00:03:02.980 --> 00:03:05.880
So we get 1,000 men.

00:03:05.880 --> 00:03:10.340
When we survey the 1,000 men,
let's say 642 say that they

00:03:10.340 --> 00:03:11.990
will vote for the candidate.

00:03:11.990 --> 00:03:13.060
So they are ones.

00:03:13.060 --> 00:03:18.840
And then the remainder, 358,
I'll just say the remainder.

00:03:18.840 --> 00:03:21.540
So the rest are zeros.

00:03:21.540 --> 00:03:23.610
That we do the same
thing with women.

00:03:23.610 --> 00:03:27.160
We survey 1,000 women who
are likely to vote.

00:03:27.160 --> 00:03:29.320
But we survey them randomly.

00:03:29.320 --> 00:03:32.500
And let's say 591 say
that they will

00:03:32.500 --> 00:03:33.740
vote for the candidate.

00:03:33.740 --> 00:03:36.120
And the rest say that
they will not

00:03:36.120 --> 00:03:39.140
vote for the candidate.

00:03:39.140 --> 00:03:42.130
So just here based on our sample
proportions, or our

00:03:42.130 --> 00:03:44.650
sample means, it looks like
there is a difference.

00:03:44.650 --> 00:03:46.915
But we still have to come up
with our confidence interval.

00:03:46.915 --> 00:03:51.730
And let's just make sure we
understand what we just did.

00:03:51.730 --> 00:03:54.280
So we could figure out a sample
proportion over here

00:03:54.280 --> 00:03:55.530
for the men.

00:03:58.180 --> 00:04:01.290
Which is really just the sample
mean of this sample

00:04:01.290 --> 00:04:02.200
right over here.

00:04:02.200 --> 00:04:04.600
We have 642 ones, the
rest are zero.

00:04:04.600 --> 00:04:06.620
So we have 642 in
the numerator.

00:04:06.620 --> 00:04:07.970
We have 1,000 samples.

00:04:07.970 --> 00:04:12.840
642 divided by 1,000 is 0.642.

00:04:12.840 --> 00:04:15.340
So you could view this is a
sample mean or as a sample

00:04:15.340 --> 00:04:16.380
proportion.

00:04:16.380 --> 00:04:19.370
If you do the same thing for
the women, the sample

00:04:19.370 --> 00:04:23.570
proportion is going
to be 0.591.

00:04:23.570 --> 00:04:26.070
Or you could even just view this
as the sample mean of the

00:04:26.070 --> 00:04:27.550
sample of 1,000 women.

00:04:27.550 --> 00:04:31.210
Where the ones voting for it
are one, the rest are zero.

00:04:31.210 --> 00:04:33.720
And just to visualize it
properly, let me draw the

00:04:33.720 --> 00:04:36.975
sampling distribution for
the sample proportions.

00:04:40.120 --> 00:04:41.910
We have a large sample size.

00:04:44.630 --> 00:04:46.950
And especially because the
proportions that we're dealing

00:04:46.950 --> 00:04:49.610
with aren't close to one or
zero, and we have a large

00:04:49.610 --> 00:04:51.990
sample size, the sampling
distribution will be

00:04:51.990 --> 00:04:53.240
approximately normal.

00:04:56.990 --> 00:04:58.240
Let me write this.

00:05:05.560 --> 00:05:09.930
So it's going to have
some mean over here.

00:05:09.930 --> 00:05:13.710
So the mean of the sampling
distribution of the sample

00:05:13.710 --> 00:05:14.360
proportion.

00:05:14.360 --> 00:05:15.730
And we've seen in
multiple times.

00:05:15.730 --> 00:05:17.800
It's going to be the same
thing as the mean of the

00:05:17.800 --> 00:05:18.870
population.

00:05:18.870 --> 00:05:21.440
And the mean of the population
is actually the true

00:05:21.440 --> 00:05:22.950
population proportion.

00:05:22.950 --> 00:05:25.960
So this is going to
be equal to P1.

00:05:25.960 --> 00:05:28.710
This is something that we
don't to know about.

00:05:28.710 --> 00:05:32.460
And then the variance of this,
and we've seen this several

00:05:32.460 --> 00:05:38.360
times already, the variance of
this distribution, I have to

00:05:38.360 --> 00:05:40.660
put a one here, we're dealing
with the men.

00:05:40.660 --> 00:05:43.480
The variance of this
distribution by the central

00:05:43.480 --> 00:05:45.930
limit theorem is going to
be the variance of this

00:05:45.930 --> 00:05:51.870
distribution up here, which is
P1 times 1 minus P1 over our

00:05:51.870 --> 00:05:55.800
sample size, over 1,000.

00:05:55.800 --> 00:05:57.906
And we can do the exact same
thing for the women.

00:06:02.040 --> 00:06:03.570
So this is the sampling
distribution.

00:06:09.230 --> 00:06:15.750
This is for P2 bar, or this
sample mean over here.

00:06:15.750 --> 00:06:17.130
Let me put a one over here.

00:06:17.130 --> 00:06:20.540
Remember, this is
all for the men.

00:06:20.540 --> 00:06:22.870
And then this over here
is all for the women.

00:06:22.870 --> 00:06:24.510
Can't forget those
twos over there.

00:06:24.510 --> 00:06:27.190
And so this distribution is
going to have some mean.

00:06:30.790 --> 00:06:32.720
Let me draw it right
over here.

00:06:32.720 --> 00:06:36.130
So mu sub P2 with
a bar over it.

00:06:36.130 --> 00:06:38.910
So the mean of the sampling
distribution for this sample

00:06:38.910 --> 00:06:41.590
proportion, for the women, which
is going to be the same

00:06:41.590 --> 00:06:43.680
thing as the mean of the
population, which we already

00:06:43.680 --> 00:06:46.930
saw is going to be
equal to P2.

00:06:46.930 --> 00:06:51.770
And then the variance for this
distribution, for this

00:06:51.770 --> 00:06:56.920
sampling and distribution over
here, is going to be this

00:06:56.920 --> 00:07:00.450
variance over here divided
by our sample size.

00:07:00.450 --> 00:07:03.410
So P2 times 1 minus P2.

00:07:03.410 --> 00:07:06.330
All of that over n.

00:07:06.330 --> 00:07:09.970
Now, our whole goal is to
get a 95% confidence

00:07:09.970 --> 00:07:11.140
interval for that.

00:07:11.140 --> 00:07:13.310
And so what we're going to do is
we're going to think about

00:07:13.310 --> 00:07:16.260
the sampling distribution, not
for this, and not the sampling

00:07:16.260 --> 00:07:17.190
distribution for this.

00:07:17.190 --> 00:07:18.980
But we're going to think about
the sampling distribution for

00:07:18.980 --> 00:07:25.460
the difference of this sample
proportion and this sample

00:07:25.460 --> 00:07:25.950
proportion.

00:07:25.950 --> 00:07:27.860
We've seen it already.

00:07:27.860 --> 00:07:29.620
We're talking about proportions,
but it's really

00:07:29.620 --> 00:07:32.460
the same exact ideas that we
did when we just compared

00:07:32.460 --> 00:07:34.660
sample means generally.

00:07:34.660 --> 00:07:35.910
So let's look at that.

00:07:38.160 --> 00:07:40.190
Let's look at this
distribution.

00:07:40.190 --> 00:07:44.260
And just to be clear, when we
got this sample mean here,

00:07:44.260 --> 00:07:46.590
this sample proportion,
we just sampled it.

00:07:46.590 --> 00:07:49.060
You could view it as taking
a sample from this

00:07:49.060 --> 00:07:50.030
distribution over here.

00:07:50.030 --> 00:07:52.610
When we got this sample
proportion, it was like taking

00:07:52.610 --> 00:07:56.340
a sample from this over here.

00:07:56.340 --> 00:07:59.390
We took 1,000 samples from this,
when we took their mean.

00:07:59.390 --> 00:08:01.780
Where it's equivalent to taking
a sample from the

00:08:01.780 --> 00:08:03.300
sampling distribution.

00:08:03.300 --> 00:08:07.270
Now, this distribution over
here is going to be the

00:08:07.270 --> 00:08:10.270
distribution of all of the
differences of the sampling

00:08:10.270 --> 00:08:12.730
proportions, or of the
sample proportions.

00:08:12.730 --> 00:08:16.350
So it will look like this.

00:08:16.350 --> 00:08:19.790
It will have some mean value.

00:08:19.790 --> 00:08:21.470
I should do this in
a different color.

00:08:21.470 --> 00:08:22.210
I'll do it in green.

00:08:22.210 --> 00:08:23.460
Yellow and blue make green.

00:08:28.280 --> 00:08:36.039
So I'll call this the sampling
distribution of this

00:08:36.039 --> 00:08:41.120
statistic, of P1 minus P2.

00:08:41.120 --> 00:08:42.990
And so it has some
mean over here.

00:08:46.740 --> 00:08:50.000
The sample of P1 minus the
sample mean, or the sample

00:08:50.000 --> 00:08:51.790
proportion, of P2.

00:08:51.790 --> 00:08:55.200
And we know, from things that
we've done in the last several

00:08:55.200 --> 00:08:58.290
videos, that this is going to
be the exact same thing as

00:08:58.290 --> 00:09:00.890
this mean minus this mean.

00:09:00.890 --> 00:09:05.100
Which is the exact same
thing as P1 minus P2.

00:09:05.100 --> 00:09:09.400
So this is going to be
equal to P1 minus P2.

00:09:12.450 --> 00:09:26.430
And the variance of this
distribution, P1 minus P2,

00:09:26.430 --> 00:09:29.520
just like this, is going to be
the sum of the variances of

00:09:29.520 --> 00:09:31.060
these two distributions.

00:09:31.060 --> 00:09:34.210
So it's going to be this thing
over here, I'll just copy and

00:09:34.210 --> 00:09:40.940
paste it, plus this variance
over here.

00:09:40.940 --> 00:09:42.520
There's no radical sign, because
we're not taking the

00:09:42.520 --> 00:09:43.390
standard deviation.

00:09:43.390 --> 00:09:45.190
We're focused on the
variance right now.

00:09:45.190 --> 00:09:48.110
So plus this thing
right over here.

00:09:48.110 --> 00:09:51.165
So let me copy and
let me paste it.

00:09:55.680 --> 00:09:57.925
So that's going to
be the variance.

00:10:00.800 --> 00:10:05.100
And if you want the standard
deviation, you can literally

00:10:05.100 --> 00:10:06.060
just get rid of this.

00:10:06.060 --> 00:10:08.530
You're taking the square
root of both sides.

00:10:08.530 --> 00:10:10.040
So you take the square root of
the variance, you get the

00:10:10.040 --> 00:10:12.180
standard deviation, that's why
I got rid of that to the

00:10:12.180 --> 00:10:12.875
second power.

00:10:12.875 --> 00:10:16.440
And you want to take a square
root of the right-hand side

00:10:16.440 --> 00:10:17.720
just like that.

00:10:17.720 --> 00:10:20.900
Now, all I did right now was
just to kind of conceptually

00:10:20.900 --> 00:10:23.000
set things up in our brain.

00:10:23.000 --> 00:10:25.350
What we now need to do
is actually tackle

00:10:25.350 --> 00:10:26.380
the confidence interval.

00:10:26.380 --> 00:10:29.860
We actually need to come up with
a 95% confidence interval

00:10:29.860 --> 00:10:31.750
for P1 minus P2.

00:10:31.750 --> 00:10:36.360
Or a 95% confidence interval for
this mean right over here.

00:10:36.360 --> 00:10:38.830
And because I'm trying to make
my best effort not to make

00:10:38.830 --> 00:10:43.370
videos too long, I'll do part
two in the next video, where

00:10:43.370 --> 00:10:46.250
we actually solve the
confidence interval.


Clarification of confidence interval of difference of means

WEBVTT
Kind: captions
Language: en

00:00:00.650 --> 00:00:03.110
Near the end of the last video,
I wasn't as articulate

00:00:03.110 --> 00:00:04.710
as I would like to be.

00:00:04.710 --> 00:00:07.430
Mainly because I think 15
minutes into a video my brain

00:00:07.430 --> 00:00:10.590
starts to really warm
up too much.

00:00:10.590 --> 00:00:12.060
But what I want to do
is restate what I

00:00:12.060 --> 00:00:12.820
was trying to say.

00:00:12.820 --> 00:00:16.750
We got this confidence
interval.

00:00:16.750 --> 00:00:18.000
I'll rewrite it here.

00:00:23.150 --> 00:00:25.020
I'll just restate the
confidence interval.

00:00:25.020 --> 00:00:31.620
So there's the 95% confidence
interval for the mean of this

00:00:31.620 --> 00:00:32.870
distribution.

00:00:39.045 --> 00:00:46.620
So, the mean of that
distribution, we got as being

00:00:46.620 --> 00:00:51.990
1.91 plus or minus 1.21.

00:00:51.990 --> 00:00:53.460
And near the end of the
video I tried to

00:00:53.460 --> 00:00:54.780
explain why that is neat.

00:00:54.780 --> 00:00:57.450
Because here we have this
confidence interval for this

00:00:57.450 --> 00:01:01.870
weird mean of the difference
between the sampling means.

00:01:01.870 --> 00:01:03.260
So it seems kind of confusing.

00:01:03.260 --> 00:01:04.450
But I just want to
restate what we

00:01:04.450 --> 00:01:06.220
saw in previous videos.

00:01:06.220 --> 00:01:10.370
This thing right over here, the
mean of the difference of

00:01:10.370 --> 00:01:17.220
the sampling means, we saw
two or three videos ago.

00:01:17.220 --> 00:01:22.170
It's the same thing as the mean
of the difference of the

00:01:22.170 --> 00:01:23.715
means of the sampling
distributions.

00:01:28.330 --> 00:01:31.910
And we know that the mean
of each of the sampling

00:01:31.910 --> 00:01:34.160
distributions is actually the
same as the mean of the

00:01:34.160 --> 00:01:36.170
population distributions.

00:01:36.170 --> 00:01:41.570
So this is the same thing as
the mean of Population One

00:01:41.570 --> 00:01:43.860
minus the mean of
Population Two.

00:01:43.860 --> 00:01:47.350
And this was the neat result
about the last video.

00:01:47.350 --> 00:01:51.730
This isn't just a 95% confidence
interval for this

00:01:51.730 --> 00:01:53.130
parameter right here.

00:01:53.130 --> 00:01:57.600
It's actually a 95% confidence
interval for this parameter

00:01:57.600 --> 00:01:58.200
right here.

00:01:58.200 --> 00:02:00.910
And this is the parameter that
we really care about.

00:02:00.910 --> 00:02:08.180
The true difference in weight
loss between going on the

00:02:08.180 --> 00:02:10.930
low-fat diet and not going
on the low-fat diet.

00:02:10.930 --> 00:02:14.390
And we have a 95% confidence
interval that that difference

00:02:14.390 --> 00:02:18.250
is between 0.7 and
3.12 pounds.

00:02:18.250 --> 00:02:21.320
Which tells us that we have a
95% confidence interval that

00:02:21.320 --> 00:02:23.300
you're definitely going
to lose some weight.

00:02:23.300 --> 00:02:26.410
We're not 100% sure.

00:02:26.410 --> 00:02:30.210
We're confident that there's
a 95% probability of that.

00:02:30.210 --> 00:02:32.230
Anyway, hopefully that clarifies
it a little bit.

00:02:32.230 --> 00:02:37.490
I didn't want to confuse you
too much with that bungled

00:02:37.490 --> 00:02:40.620
language that I had at the
end of the last video.


Confidence interval of difference of means

WEBVTT
Kind: captions
Language: en

00:00:00.650 --> 00:00:03.650
We're trying to test whether
a new low-fat diet actually

00:00:03.650 --> 00:00:05.940
helps obese people
lose weight.

00:00:05.940 --> 00:00:10.790
100 randomly assigned people are
assigned to group one and

00:00:10.790 --> 00:00:12.410
put on the low-fat diet.

00:00:12.410 --> 00:00:16.280
Another 100 randomly assigned
obese people are assigned to

00:00:16.280 --> 00:00:19.770
group two and put on a diet of
approximately the same amount

00:00:19.770 --> 00:00:22.610
of food, but not
as low in fat.

00:00:22.610 --> 00:00:25.010
So group two is the control,
just the no diet.

00:00:25.010 --> 00:00:26.660
Group one is the low
fat group, to see

00:00:26.660 --> 00:00:27.870
if it actually works.

00:00:27.870 --> 00:00:31.740
After four months, the mean
weight loss was 9.31 pounds

00:00:31.740 --> 00:00:32.540
for group one.

00:00:32.540 --> 00:00:35.960
Let me write this down.

00:00:35.960 --> 00:00:37.310
Let me make it very clear.

00:00:37.310 --> 00:00:46.590
So the low fat group, the mean
weight loss was 9.31 pounds.

00:00:46.590 --> 00:00:52.140
So our sample mean for group
one is 9.31 pounds, with a

00:00:52.140 --> 00:00:56.120
sample standard deviation
of 4.67.

00:00:56.120 --> 00:00:57.840
And both of these are obviously
very easy to

00:00:57.840 --> 00:00:59.650
calculate from the
actual data.

00:00:59.650 --> 00:01:08.310
And then for our control group,
the sample mean, 7.40

00:01:08.310 --> 00:01:09.560
pounds for group two.

00:01:14.280 --> 00:01:20.800
With a sample standard deviation
of 4.04 pounds.

00:01:20.800 --> 00:01:24.100
And now, if we just look at it
superficially, it looks like

00:01:24.100 --> 00:01:27.670
the low-fat group lost more
weight, just based on our

00:01:27.670 --> 00:01:29.820
samples, than the
control group.

00:01:29.820 --> 00:01:32.040
If we take the difference
of them.

00:01:32.040 --> 00:01:36.910
So if we take the difference
between the low-fat group and

00:01:36.910 --> 00:01:50.250
the control group, we get 9.31
minus 7.40 is equal to, let's

00:01:50.250 --> 00:02:01.860
get the calculator out, 1.91.

00:02:01.860 --> 00:02:06.070
So the difference of our
samples is 1.91.

00:02:06.070 --> 00:02:09.639
So just based on what we see,
maybe you lose an incremental

00:02:09.639 --> 00:02:14.210
1.91 pounds every four months
if you are on this diet.

00:02:14.210 --> 00:02:18.180
And what we want to do in this
video is to get a 95%

00:02:18.180 --> 00:02:20.700
confidence interval around
this number.

00:02:20.700 --> 00:02:25.910
To see that in that 95%
confidence interval, maybe, do

00:02:25.910 --> 00:02:27.610
we always lose weight?

00:02:27.610 --> 00:02:30.480
Or is there a chance that we can
actually go the other way

00:02:30.480 --> 00:02:31.630
with the low-fat diet?

00:02:31.630 --> 00:02:33.850
So in this video, 95%
confidence interval.

00:02:33.850 --> 00:02:36.190
In the next video, we'll
actually do a hypothesis test

00:02:36.190 --> 00:02:38.650
using this same data.

00:02:38.650 --> 00:02:42.770
And now to do a 95% confidence
interval, let's think about

00:02:42.770 --> 00:02:45.020
the distribution that we're
thinking about.

00:02:45.020 --> 00:02:47.350
So let's look at the
distribution.

00:02:47.350 --> 00:02:49.190
Of course we're going to think
about the distribution that

00:02:49.190 --> 00:02:50.860
we're thinking about.

00:02:50.860 --> 00:02:55.500
We want to think about the
distribution of the difference

00:02:55.500 --> 00:02:57.390
of the means.

00:02:57.390 --> 00:03:00.600
So it's going to have
some true mean here.

00:03:06.950 --> 00:03:10.030
Which is the mean of
the difference

00:03:10.030 --> 00:03:12.370
of the sample means.

00:03:12.370 --> 00:03:13.490
Let me write that.

00:03:13.490 --> 00:03:15.330
It's not a y, it's
an x1 and x2.

00:03:15.330 --> 00:03:19.980
So it's the sample mean of x1
minus the sample mean of x2.

00:03:19.980 --> 00:03:23.830
And then this distribution right
here is going to have

00:03:23.830 --> 00:03:25.165
some standard deviation.

00:03:28.270 --> 00:03:31.330
So it's the standard deviation
of the distribution of the

00:03:31.330 --> 00:03:36.110
mean of x1 minus the
sample mean of x2.

00:03:36.110 --> 00:03:37.900
It's going to have some standard
deviation here.

00:03:37.900 --> 00:03:39.960
And we want to make an
inference about this.

00:03:39.960 --> 00:03:42.030
Or I guess, the best way to
think about it, we want to get

00:03:42.030 --> 00:03:44.360
a 95% confidence interval.

00:03:44.360 --> 00:03:47.230
Based on our sample, we want to
create an interval around

00:03:47.230 --> 00:03:51.630
this, where we're confident that
there's a 95% chance that

00:03:51.630 --> 00:03:56.780
this true mean, the true mean
of the differences, lies

00:03:56.780 --> 00:03:59.010
within that interval.

00:03:59.010 --> 00:04:03.200
And to do that let's just think
of it the other way.

00:04:03.200 --> 00:04:14.220
How can we construct an interval
around this where we

00:04:14.220 --> 00:04:17.990
are 95% sure that any sample
from this distribution, and

00:04:17.990 --> 00:04:22.950
this is one of those samples,
that there is a 95% chance

00:04:22.950 --> 00:04:25.470
that we will select from this
region right over here.

00:04:25.470 --> 00:04:30.800
So we care about a 95% region
right over here.

00:04:30.800 --> 00:04:32.960
So how many standard deviations
do we have to go in

00:04:32.960 --> 00:04:34.370
each direction?

00:04:34.370 --> 00:04:36.980
And to do that we just have
to look at a Z table.

00:04:36.980 --> 00:04:39.740
And just remember, if we have
95% in the middle right over

00:04:39.740 --> 00:04:43.940
here, we're going to have 2.5%
over here and we're going to

00:04:43.940 --> 00:04:45.930
have 2.5% over here.

00:04:45.930 --> 00:04:48.020
We have to have 5% split
between these

00:04:48.020 --> 00:04:49.900
two symmetric tails.

00:04:49.900 --> 00:04:54.140
So when we look at a Z table,
we want the critical Z value

00:04:54.140 --> 00:04:56.120
that they give right
over here.

00:04:56.120 --> 00:04:57.300
And we have to be
careful here.

00:04:57.300 --> 00:05:00.245
We're not going to look up 95%,
because a Z table gives

00:05:00.245 --> 00:05:03.640
us the cumulative probability
up to that critical Z value.

00:05:03.640 --> 00:05:07.480
So the Z table is going to
be interpreted like this.

00:05:07.480 --> 00:05:10.400
So there's going to be some Z
value right over here where we

00:05:10.400 --> 00:05:13.940
have 2.5% above it.

00:05:13.940 --> 00:05:18.190
The probability of getting a
more extreme result or Z score

00:05:18.190 --> 00:05:20.080
above that is 2.5%.

00:05:20.080 --> 00:05:22.040
And the probability of getting
one below that

00:05:22.040 --> 00:05:27.620
is going to be 97.5%.

00:05:27.620 --> 00:05:30.640
But if we can find whatever Z
value this is right over here,

00:05:30.640 --> 00:05:32.335
it's going to be the same
Z value as that.

00:05:32.335 --> 00:05:34.930
And instead of thinking about
it in terms of a one tail

00:05:34.930 --> 00:05:37.450
scenario, we're going to think
of it in a two tail scenario.

00:05:37.450 --> 00:05:46.760
So let's look it up for
97.5% on our Z table.

00:05:46.760 --> 00:05:47.920
Right here.

00:05:47.920 --> 00:05:51.450
This is 0.975, or 97.5.

00:05:51.450 --> 00:05:56.760
And this gives us
Z value of 1.96.

00:05:56.760 --> 00:06:00.760
So Z is equal to 1.96.

00:06:00.760 --> 00:06:09.380
Or 2.5% of the samples from this
population are going to

00:06:09.380 --> 00:06:14.050
be more than 1.96 standard
deviations away from the mean.

00:06:14.050 --> 00:06:18.550
So this critical Z value right
here is 1.96 standard

00:06:18.550 --> 00:06:20.260
deviations.

00:06:20.260 --> 00:06:23.450
This is 1.96 times the standard

00:06:23.450 --> 00:06:28.460
deviation of x1 minus x2.

00:06:28.460 --> 00:06:32.700
And then this right here is
going to be negative 1.96

00:06:32.700 --> 00:06:33.840
times the same thing.

00:06:33.840 --> 00:06:34.870
Let me write that.

00:06:34.870 --> 00:06:37.010
So this right here,
it's symmetric.

00:06:37.010 --> 00:06:39.550
This distance is going to be
the same as that distance.

00:06:39.550 --> 00:06:44.900
So this is negative 1.96 times
the standard deviation of this

00:06:44.900 --> 00:06:46.150
distribution.

00:06:48.900 --> 00:07:03.110
So let's put it this way,
there's a 95% chance that our

00:07:03.110 --> 00:07:05.590
sample that we got from our
distribution-- this is the

00:07:05.590 --> 00:07:08.080
sample as a difference of
these other samples.

00:07:08.080 --> 00:07:28.730
There's a 95% chance that 1.91
lies within 1.96 times the

00:07:28.730 --> 00:07:31.940
standard deviation of
that distribution.

00:07:31.940 --> 00:07:33.210
So you could view
it as a standard

00:07:33.210 --> 00:07:36.380
error of this statistic.

00:07:36.380 --> 00:07:37.760
So x1 minus x2.

00:07:42.370 --> 00:07:43.370
Let me finish that sentence.

00:07:43.370 --> 00:07:48.360
There's a 95% chance that 1.91,
which is the sample

00:07:48.360 --> 00:07:52.470
statistic, or the statistic that
we got, is within 1.96

00:07:52.470 --> 00:08:00.380
times the standard deviation
of this distribution of the

00:08:00.380 --> 00:08:03.090
true mean of of the
distribution.

00:08:03.090 --> 00:08:04.680
Or we could say it the
other way around.

00:08:04.680 --> 00:08:15.830
There's a 95% chance that the
true mean of the distribution

00:08:15.830 --> 00:08:24.090
is within 1.96 times the
standard deviation of the

00:08:24.090 --> 00:08:28.800
distribution of 1.91.

00:08:28.800 --> 00:08:29.900
These are equivalent
statements.

00:08:29.900 --> 00:08:32.429
If I say I'm within three feet
of you, that's equivalent to

00:08:32.429 --> 00:08:34.480
saying you're within
three feet of me.

00:08:34.480 --> 00:08:35.549
That's all that's saying.

00:08:35.549 --> 00:08:37.760
But when we construct it this
way, it becomes pretty clear,

00:08:37.760 --> 00:08:41.679
how do we actually construct
the confidence interval?

00:08:41.679 --> 00:08:46.340
We just have to figure out
what this distance

00:08:46.340 --> 00:08:47.750
right over here is.

00:08:47.750 --> 00:08:49.730
And to figure out what that
distance is, we're going to

00:08:49.730 --> 00:08:52.010
have to figure out what the
standard deviation of this

00:08:52.010 --> 00:08:53.310
distribution is.

00:08:53.310 --> 00:08:56.460
Well the standard deviation of
the differences of the sample

00:08:56.460 --> 00:08:59.980
means is going to be equal to,
and we saw this in the last

00:08:59.980 --> 00:09:02.820
video-- in fact, I think I have
it right at the bottom

00:09:02.820 --> 00:09:09.050
here-- it's going to be equal
to the square root of the

00:09:09.050 --> 00:09:13.255
variances of each of those
distributions.

00:09:18.960 --> 00:09:22.550
Let me write it this way.

00:09:22.550 --> 00:09:30.270
So the variance, I'll
kind of re-prove it.

00:09:30.270 --> 00:09:35.570
The variance of our distribution
is going to be

00:09:35.570 --> 00:09:38.690
equal to the sum of the
variances of each of these

00:09:38.690 --> 00:09:39.940
sampling distributions.

00:09:46.100 --> 00:09:48.730
And we know that the variance
of each of these sampling

00:09:48.730 --> 00:09:52.120
distributions is equal to the
variance of this sampling

00:09:52.120 --> 00:09:55.870
distribution, is equal to the
variance of the population

00:09:55.870 --> 00:10:02.290
distribution, divided
by our sample size.

00:10:02.290 --> 00:10:04.880
And our sample size in
this case is 100.

00:10:04.880 --> 00:10:08.880
And the variance of this
sampling distribution, for our

00:10:08.880 --> 00:10:15.010
control, is going to be equal
to the variance of the

00:10:15.010 --> 00:10:20.840
population distribution for
the control divided by its

00:10:20.840 --> 00:10:22.270
sample size.

00:10:22.270 --> 00:10:25.250
And since we don't know
what these are, we

00:10:25.250 --> 00:10:26.480
can approximate them.

00:10:26.480 --> 00:10:29.520
Especially, because our n is
greater than 30 for both

00:10:29.520 --> 00:10:31.190
circumstances.

00:10:31.190 --> 00:10:37.180
We can approximate these with
our sample variances for each

00:10:37.180 --> 00:10:38.780
of these distributions.

00:10:38.780 --> 00:10:39.920
So let me make this clear.

00:10:39.920 --> 00:10:42.480
Our sample variances for each
of these distributions.

00:10:42.480 --> 00:10:48.950
So this is going to be our
sample standard deviation one

00:10:48.950 --> 00:10:51.630
squared, which is the sample
variance for that

00:10:51.630 --> 00:10:54.770
distribution, over 100.

00:10:54.770 --> 00:11:00.540
Plus my sample standard
deviation for the control

00:11:00.540 --> 00:11:03.190
squared, which is the
sample variance.

00:11:03.190 --> 00:11:04.590
Standard deviation squared
is just the

00:11:04.590 --> 00:11:06.760
variance divided by 100.

00:11:06.760 --> 00:11:14.080
And this will give us the
variance for this

00:11:14.080 --> 00:11:15.220
distribution.

00:11:15.220 --> 00:11:18.920
And if we want the standard
deviation, we just take the

00:11:18.920 --> 00:11:21.970
square roots of both sides.

00:11:21.970 --> 00:11:25.620
If we want the standard
deviation of this distribution

00:11:25.620 --> 00:11:28.110
right here, this is the variance
right now, so we just

00:11:28.110 --> 00:11:31.620
need to take the square roots.

00:11:31.620 --> 00:11:32.430
Let's calculate this.

00:11:32.430 --> 00:11:34.160
We actually know these values.

00:11:34.160 --> 00:11:37.695
S1, our sample standard
deviation for

00:11:37.695 --> 00:11:39.830
group one is 4.67.

00:11:39.830 --> 00:11:41.070
We wrote it right
here, as well.

00:11:41.070 --> 00:11:51.000
It's 4.76 and 4.04.

00:11:51.000 --> 00:11:53.620
The S is 4.67, we're going
to have to square it.

00:11:53.620 --> 00:11:56.300
And the S2 is 4.04, we're going
to have to square it.

00:11:56.300 --> 00:11:59.580
So let's calculate that.

00:11:59.580 --> 00:12:09.040
So we're going to take the
square root of 4.67 squared

00:12:09.040 --> 00:12:18.440
divided by 100 plus 4.04
squared, divided by 100.

00:12:18.440 --> 00:12:20.072
And then close the
parentheses.

00:12:23.030 --> 00:12:29.940
And we get 0.617.

00:12:29.940 --> 00:12:31.390
Let me write it right here.

00:12:31.390 --> 00:12:36.330
This is going to be
equal to 0.617.

00:12:36.330 --> 00:12:39.720
So if we go back up over here,
we calculated the standard

00:12:39.720 --> 00:12:44.220
deviation of this distribution
to be 0.617.

00:12:44.220 --> 00:12:46.720
So now we can actually calculate
our interval.

00:12:46.720 --> 00:12:49.700
Because this is going
to be 0.617.

00:12:49.700 --> 00:12:58.150
So if you want 1.96 times that,
we get 1.96 times that

00:12:58.150 --> 00:13:02.240
0.617, I'll just write the
answer we just got.

00:13:02.240 --> 00:13:11.770
So we get 1.21.

00:13:11.770 --> 00:13:18.660
So the 95% confidence interval
is going to be the difference

00:13:18.660 --> 00:13:27.190
of our means, 1.91, plus or
minus this number, 1.21.

00:13:27.190 --> 00:13:30.040
So what's our confidence
interval?

00:13:30.040 --> 00:13:32.620
So the low end of our confidence
interval, and I'm

00:13:32.620 --> 00:13:40.130
running out of space, 1.91 minus
1.21, that's just 0.7.

00:13:40.130 --> 00:13:42.360
So the low end is 0.7.

00:13:42.360 --> 00:13:51.630
And then the high end, 1.91
plus 1.21, that's 2.12.

00:13:51.630 --> 00:13:52.770
let me just make sure of that.

00:13:52.770 --> 00:13:56.710
My brain sometimes doesn't work
properly when I'm making

00:13:56.710 --> 00:13:58.200
these videos.

00:13:58.200 --> 00:14:08.450
3.12.

00:14:08.450 --> 00:14:14.110
So just to be clear, there's not
a pure 95% chance that the

00:14:14.110 --> 00:14:19.000
true difference of the true
means lies in this.

00:14:19.000 --> 00:14:21.680
We're just confident that
there's a 95% chance.

00:14:21.680 --> 00:14:23.280
And we always have to put a
little confidence there,

00:14:23.280 --> 00:14:28.110
because remember, we didn't
actually know the population

00:14:28.110 --> 00:14:30.640
standard deviations, or the
population variances.

00:14:30.640 --> 00:14:32.930
We estimated them
with our sample.

00:14:32.930 --> 00:14:35.330
And because of that, we don't
know that it's an exact

00:14:35.330 --> 00:14:35.850
probability.

00:14:35.850 --> 00:14:39.300
We just have say we're confident
that it is a 95%

00:14:39.300 --> 00:14:40.040
probability.

00:14:40.040 --> 00:14:42.510
And that's why we just say it's
a confidence interval.

00:14:42.510 --> 00:14:44.760
It's not a pure probability.

00:14:44.760 --> 00:14:46.115
But it's a pretty neat result.

00:14:49.510 --> 00:14:52.600
So we're confident that there's
a 95% chance that the

00:14:52.600 --> 00:15:00.820
true difference of these two
samples-- and remember, let me

00:15:00.820 --> 00:15:10.720
make it very clear, the expected
value of the sample

00:15:10.720 --> 00:15:13.990
means is actually the same thing
as the expected value of

00:15:13.990 --> 00:15:15.130
the populations.

00:15:15.130 --> 00:15:18.720
And so, what this is giving us
is actually a confidence

00:15:18.720 --> 00:15:21.530
interval for the true difference
between the

00:15:21.530 --> 00:15:22.280
populations.

00:15:22.280 --> 00:15:24.630
If you were to give everyone,
every possible

00:15:24.630 --> 00:15:26.080
person, diet one.

00:15:26.080 --> 00:15:28.500
And every possible
person diet two.

00:15:28.500 --> 00:15:31.120
This is giving us a confidence
interval for the true

00:15:31.120 --> 00:15:32.610
population means.

00:15:32.610 --> 00:15:34.790
And so when you look at this,
it looks like diet one

00:15:34.790 --> 00:15:36.080
actually does do something.

00:15:36.080 --> 00:15:38.450
Because in any case, even at the
low end of the confidence

00:15:38.450 --> 00:15:40.650
interval, you still have
a greater weight

00:15:40.650 --> 00:15:42.400
loss than diet two.

00:15:42.400 --> 00:15:44.070
Hopefully, that doesn't
confuse you too much.

00:15:44.070 --> 00:15:45.430
In the next video, we're
actually going to do a

00:15:45.430 --> 00:15:48.400
hypothesis test with
the same data.