Lecture 2: Simple Linear Regression: Estimation

Lecture 2

Simple Linear Regression: Estimation

This lecture estimates \(\beta_0\), \(\beta_1\), and \(\sigma^2\) in the simple linear regression model with least squares and maximum likelihood (Lecture 2 · p.1–38).

Unit 01Recap: mean, variance, covariance, and correlation

Plan · Slides p.1–8

Slides p.1–3: title, section, housekeeping.

Slides p.4: mean, expectation, linearity.

Slides p.5: variance, two properties.

Slides p.6: covariance, three properties.

Slides p.7: correlation, \(S_{xy},S_{xx},S_{yy}\).

Slides p.8: goals and notation.

Data for this unit · Added

The first five people of the brainhead data (Slides p.10).

\(x_i\): head size (cm³). \(y_i\): brain weight (g).

\(x_1,\dots,x_5\): 4512, 3738, 4261, 3777, 4177.

\(y_1,\dots,y_5\): 1530, 1297, 1335, 1282, 1590.

01.1Title, section, housekeeping Slides p.1–3

Page 1: Lecture 2: Simple Linear Regression: Estimation.
Page 2: section "Recap" (pages 3 to 8).
Page 3: review the course outline. Assignment 1 is due on September 25.
Ask questions on Piazza. Office hours: Wednesdays, 8:30–9:30 and 11:30–12:30.

01.2Mean and expectation Slides p.4

What Slides p.4

Review: Mean · Lecture 2 · p.4 Mean/Expectation: \[E[Y]=\int y f(y)\,dy\] Linearity of expectation: For random variables \(Y_1,\dots,Y_m\) and constants \(a_i,b_i\) for \(i=1,\dots,m\): \[E\left[\sum_{i=1}^m (a_iY_i+b_i)\right]=\sum_{i=1}^m a_iE[Y_i]+\sum_{i=1}^m b_i\] For observations \(y_1,\dots,y_n\), the sample mean is: \[\bar y=\frac1n\sum_i y_i\]
A random variable \(Y\) is a quantity whose value comes from chance. \(y\) is one value of \(Y\).
The probability density function (PDF) \(f(y)\) shows how probable values near \(y\) are. It is not negative, and \(\int f(y)\,dy=1\).
The expectation \(E[Y]\) is the population mean of \(Y\).
A constant, such as \(a_i\) or \(b_i\), is a fixed number.
Linearity: constant factors move outside \(E\), sums split, and \(E\) of a constant is the constant.
The observations \(y_1,\dots,y_n\) are the data. \(n\) is the sample size.
The sample mean \(\bar y\) ("y bar") estimates \(E[Y]\) from the data.

How Added

Calculate the sample mean \(\bar y\)
  1. Add the \(n\) observations.
  2. Divide the sum by \(n\).

Self-check: \(\bar y\) is between the smallest and largest observation. It has the unit of \(y_i\).

Use linearity to simplify \(E[\cdot]\)
  1. Write the expression as \(\sum (a_iY_i+b_i)\).
  2. Replace each \(a_iY_i\) with \(a_iE[Y_i]\).
  3. Keep each constant \(b_i\).

Self-check: The result has no random variable.

Example Added

1
\(\bar y=\frac15(1530+1297+1335+1282+1590)\)
2
\(\bar y=\frac15(7034)\)
3
\(\bar y=1406.8\)
Check: 1406.8 g is between 1282 and 1590.
1
\(\bar x=\frac15(4512+3738+4261+3777+4177)\)
2
\(\bar x=\frac15(20465)\)
3
\(\bar x=4093\)

Grams to kilograms is \(Y/1000\):

1
\(E[Y/1000]=\frac{1}{1000}E[Y]+0\)
linearity, \(a=1/1000,\ b=0\)
2
\(\text{sample version: }1406.8/1000=1.4068\text{ kg}\)

Why Added

Proof for one term \(aY+b\). A sum repeats it for each term.

1
\(E[aY+b]=\int (ay+b)f(y)\,dy\)
definition of expectation
2
\(=\int ay f(y)\,dy+\int b f(y)\,dy\)
3
\(=a\int y f(y)\,dy+b\int f(y)\,dy\)
4
\(=aE[Y]+b\int f(y)\,dy\)
definition of expectation
5
\(=aE[Y]+b\)
a PDF integrates to 1

01.3Variance Slides p.5

What Slides p.5

Review: Variance · Lecture 2 · p.5 Variance \[\mathrm{Var}[Y]=E\left[(Y-E[Y])^2\right]=E[Y^2]-E[Y]^2\] Properties:
• \(\mathrm{Var}(aY+b)=a^2\mathrm{Var}(Y)\)
• For independent random variables \(X\) and \(Y\): \(\mathrm{Var}(X+Y)=\mathrm{Var}(X)+\mathrm{var}(Y)\)
For observations \(y_1,\dots,y_n\), the sample variance is: \[s_y^2=\frac{1}{n-1}\sum_i (y_i-\bar y)^2\]
The variance \(\mathrm{Var}[Y]\) measures the spread of \(Y\) around its mean. \(\mathrm{Var}\) and \(\mathrm{var}\) mean the same.
A deviation \(Y-E[Y]\) is the distance from the mean. It can be negative.
The standard deviation is the square root of the variance. It has the unit of \(Y\).
\(X\) and \(Y\) are independent when the value of one does not change the distribution of the other.

How Added

Calculate the sample variance \(s_y^2\)
  1. Calculate \(\bar y\).
  2. Calculate each deviation \(y_i-\bar y\).
  3. Square the deviations and add them.
  4. Divide the sum by \(n-1\).

Self-check: The deviations add to 0. \(s_y^2\) is not negative. Its unit is the unit of \(y\), squared.

Example Added

1
\(y_i-\bar y:\ 1530-1406.8,\ 1297-1406.8,\ 1335-1406.8,\ 1282-1406.8,\ 1590-1406.8\)
2
\(y_i-\bar y:\ 123.2,\ -109.8,\ -71.8,\ -124.8,\ 183.2\)
3
\(\sum_i (y_i-\bar y)=123.2-109.8-71.8-124.8+183.2=0\)
self-check
4
\((y_i-\bar y)^2:\ 15178.24,\ 12056.04,\ 5155.24,\ 15575.04,\ 33562.24\)
5
\(\sum_i (y_i-\bar y)^2=15178.24+12056.04+5155.24+15575.04+33562.24\)
6
\(\sum_i (y_i-\bar y)^2=81526.8\)
7
\(s_y^2=\frac{81526.8}{5-1}\)
8
\(s_y^2=20381.7\ \text{g}^2\)
\(s_y=\sqrt{20381.7}=142.76\) g.

Head size (Sections 01.4 and 01.5 use these numbers):

1
\(x_i-\bar x:\ 4512-4093,\ 3738-4093,\ 4261-4093,\ 3777-4093,\ 4177-4093\)
2
\(x_i-\bar x:\ 419,\ -355,\ 168,\ -316,\ 84\)
3
\((x_i-\bar x)^2:\ 175561,\ 126025,\ 28224,\ 99856,\ 7056\)
4
\(\sum_i (x_i-\bar x)^2=436722\)
5
\(s_x^2=\frac{436722}{4}=109180.5\ (\text{cm}^3)^2\)

\(\mathrm{Var}(aY+b)=a^2\mathrm{Var}(Y)\) also holds for the sample variance. For kg, \(a=1/1000\):

1
\(s^2_{y/1000}=\left(\frac{1}{1000}\right)^2(20381.7)\)
Slides p.5, \(a=1/1000,\ b=0\)
2
\(s^2_{y/1000}=0.0203817\ \text{kg}^2\)

Why Added

Proof of \(E[Y^2]-E[Y]^2\). The constant \(\mu=E[Y]\).

1
\(\mathrm{Var}[Y]=E[(Y-\mu)^2]\)
2
\(=E[Y^2-2\mu Y+\mu^2]\)
3
\(=E[Y^2]-2\mu E[Y]+\mu^2\)
linearity
4
\(=E[Y^2]-2\mu^2+\mu^2\)
substitute \(E[Y]=\mu\)
5
\(=E[Y^2]-\mu^2\)
6
\(=E[Y^2]-E[Y]^2\)

Proof of \(\mathrm{Var}(aY+b)=a^2\mathrm{Var}(Y)\). Linearity gives \(E[aY+b]=a\mu+b\).

1
\(\mathrm{Var}(aY+b)=E[(aY+b-(a\mu+b))^2]\)
definition of variance
2
\(=E[(aY-a\mu)^2]\)
3
\(=E[a^2(Y-\mu)^2]\)
4
\(=a^2E[(Y-\mu)^2]\)
linearity
5
\(=a^2\mathrm{Var}(Y)\)

Section 01.4 proves the independence property.

01.4Covariance Slides p.6

What Slides p.6

Review: Covariance · Lecture 2 · p.6 Covariance \[\mathrm{cov}[X,Y]=E[(X-E[X])(Y-E[Y])]=E[XY]-E[X]E[Y]\] Properties:
• \(\mathrm{cov}(X,X)=\mathrm{Var}(X)\)
• \(\mathrm{cov}(aY+c,bX+d)=ab\,\mathrm{cov}(X,Y)\)
• \(\mathrm{cov}(U+V,X+Y)=\mathrm{cov}(U,X)+\mathrm{cov}(U,Y)+\mathrm{cov}(V,X)+\mathrm{cov}(V,Y)\)
For observations \((y_1,x_1),\dots,(y_n,x_n)\), the sample covariance is: \[\frac{1}{n-1}\sum_i (y_i-\bar y)(x_i-\bar x)\]
The covariance \(\mathrm{cov}[X,Y]\) shows whether \(X\) and \(Y\) move together.
Positive: when \(X\) is above its mean, \(Y\) is usually above its mean.
Negative: when \(X\) is above its mean, \(Y\) is usually below its mean.
A pair \((y_i,x_i)\) is two values from the same person.
Added constants do not change the covariance. Constant factors multiply it.
\(\mathrm{cov}(X,Y)=\mathrm{cov}(Y,X)\). Added

How Added

Calculate the sample covariance
  1. Calculate the deviations \(y_i-\bar y\) and \(x_i-\bar x\).
  2. Multiply the two deviations of each pair.
  3. Add the products.
  4. Divide the sum by \(n-1\).

Self-check: Use \(y\) deviations for both factors. The result must be \(s_y^2\). The unit is the unit of \(x\) times the unit of \(y\).

Example Added

1
\(\bar x=4093,\quad \bar y=1406.8\)
Section 01.2
2
\(\sum_i (y_i-\bar y)(x_i-\bar x)=(123.2)(419)+(-109.8)(-355)+(-71.8)(168)+(-124.8)(-316)+(183.2)(84)\)
3
\(=51620.8+38979.0-12062.4+39436.8+15388.8\)
4
\(=133363\)
5
\(\text{sample covariance}=\frac{133363}{5-1}\)
6
\(\text{sample covariance}=33340.75\ \text{cm}^3\cdot\text{g}\)
3800 4000 4200 4400 1300 1400 1500 1600 x̄ = 4093 ȳ = 1406.8 1 2 3 4 5 head size x (cm³) brain weight y (g)
Figure 1-1 (Added) · Slides p.10 data. Point labels are \(i\). Orange dashed lines: \(\bar x\), \(\bar y\). Blue points have a positive product \((y_i-\bar y)(x_i-\bar x)\). Purple point 3 has a negative product.
33340.75 cm³·g is positive: people with larger heads usually have heavier brains.

Why Added

Proof of the second form. The constants are \(\mu_X=E[X]\) and \(\mu_Y=E[Y]\).

1
\(\mathrm{cov}[X,Y]=E[(X-\mu_X)(Y-\mu_Y)]\)
2
\(=E[XY-\mu_YX-\mu_XY+\mu_X\mu_Y]\)
3
\(=E[XY]-\mu_YE[X]-\mu_XE[Y]+\mu_X\mu_Y\)
linearity
4
\(=E[XY]-\mu_Y\mu_X-\mu_X\mu_Y+\mu_X\mu_Y\)
substitute \(E[X]=\mu_X,\ E[Y]=\mu_Y\)
5
\(=E[XY]-\mu_X\mu_Y\)
6
\(=E[XY]-E[X]E[Y]\)

Proof of \(\mathrm{cov}(aY+c,bX+d)=ab\,\mathrm{cov}(X,Y)\). Linearity gives \(E[aY+c]=a\mu_Y+c\) and \(E[bX+d]=b\mu_X+d\).

1
\(\mathrm{cov}(aY+c,bX+d)=E[(aY+c-a\mu_Y-c)(bX+d-b\mu_X-d)]\)
definition of covariance
2
\(=E[a(Y-\mu_Y)\,b(X-\mu_X)]\)
3
\(=ab\,E[(Y-\mu_Y)(X-\mu_X)]\)
linearity
4
\(=ab\,\mathrm{cov}(Y,X)\)
5
\(=ab\,\mathrm{cov}(X,Y)\)

Proof of the independence property (Slides p.5):

1
\(\mathrm{Var}(X+Y)=\mathrm{cov}(X+Y,X+Y)\)
property \(\mathrm{cov}(X,X)=\mathrm{Var}(X)\)
2
\(=\mathrm{cov}(X,X)+\mathrm{cov}(X,Y)+\mathrm{cov}(Y,X)+\mathrm{cov}(Y,Y)\)
four-term property
3
\(=\mathrm{Var}(X)+2\,\mathrm{cov}(X,Y)+\mathrm{Var}(Y)\)
4
\(=\mathrm{Var}(X)+0+\mathrm{Var}(Y)\)
independence: \(E[XY]=E[X]E[Y]\), \(\mathrm{cov}(X,Y)=0\)
5
\(=\mathrm{Var}(X)+\mathrm{Var}(Y)\)

The size of the covariance depends on the units.

01.5Correlation Slides p.7

What Slides p.7

Correlation · Lecture 2 · p.7 Correlation coefficient: \[\rho=\frac{\mathrm{cov}(X,Y)}{\sqrt{\mathrm{var}(X)}\sqrt{\mathrm{var}(Y)}}\] Correlation quantifies strength of linear relationship
Sample correlation: \[r=\frac{\frac{1}{n-1}\sum_{i=1}^n (y_i-\bar y)(x_i-\bar x)}{\sqrt{\frac{1}{n-1}\sum_{i=1}^n (y_i-\bar y)^2}\sqrt{\frac{1}{n-1}\sum_{i=1}^n (x_i-\bar x)^2}}=\frac{S_{xy}}{\sqrt{S_{xx}S_{yy}}}\]
The correlation coefficient \(\rho\) ("rho") is the covariance divided by both standard deviations. It has no unit.
A linear relationship follows a straight line.
The sample correlation \(r\) puts sample quantities into \(\rho\).
\(S_{xy}=\sum_{i=1}^n (y_i-\bar y)(x_i-\bar x)\) is the sum of cross-products: the sample covariance without \(\frac{1}{n-1}\).
\(S_{xx}=\sum_{i=1}^n (x_i-\bar x)^2\) is the sum of squares of \(x\), the numerator of \(s_x^2\).
\(S_{yy}=\sum_{i=1}^n (y_i-\bar y)^2\) is the sum of squares of \(y\), the numerator of \(s_y^2\).

How Added

Calculate the sample correlation \(r\)
  1. Calculate \(\bar x\) and \(\bar y\).
  2. Calculate \(S_{xx}=\sum (x_i-\bar x)^2\).
  3. Calculate \(S_{yy}=\sum (y_i-\bar y)^2\).
  4. Calculate \(S_{xy}=\sum (y_i-\bar y)(x_i-\bar x)\).
  5. Calculate \(r=S_{xy}/\sqrt{S_{xx}S_{yy}}\).

Self-check: \(S_{xx}>0\) and \(S_{yy}>0\). \(r\) has the sign of \(S_{xy}\). \(r\) is between −1 and 1.

Example 1 · \(r\) for the five people Added

1
\(\bar x=4093,\quad \bar y=1406.8\)
Section 01.2
2
\(S_{xx}=436722\)
Section 01.3
3
\(S_{yy}=81526.8\)
Section 01.3
4
\(S_{xy}=133363\)
Section 01.4
5
\(r=\frac{133363}{\sqrt{436722\times 81526.8}}\)
6
\(r=\frac{133363}{\sqrt{35604547149.6}}\)
7
\(r=\frac{133363}{188691.67}\)
8
\(r=0.7068\)
Check: \(S_{xy}>0\) and \(r>0\). 0.7068 is between −1 and 1.
Second path: \(33340.75/(330.4247\times 142.7645)=0.7068\), with \(s_x=\sqrt{109180.5}\) and \(s_y=\sqrt{20381.7}\).

Head size and brain weight have a positive linear relationship.

Example 2 · Scale \(y\) by 2 Added

Let \(y_i^*=2y_i\): 3060, 2594, 2670, 2564, 3180.

1
\(\bar y^*=2\bar y=2(1406.8)=2813.6\)
linearity, Slides p.4
2
\(y_i^*-\bar y^*=2(y_i-\bar y)\)
3
\(S_{xy^*}=2S_{xy}=2(133363)=266726\)
4
\(S_{y^*y^*}=2^2S_{yy}=4(81526.8)=326107.2\)
5
\(r^*=\frac{266726}{\sqrt{436722\times 326107.2}}\)
6
\(r^*=\frac{266726}{377383.34}\)
7
\(r^*=0.7068\)
Step 3 uses \(\mathrm{cov}(aY+c,bX+d)=ab\,\mathrm{cov}(X,Y)\) with \(a=2,\ c=0,\ b=1,\ d=0\). Slides p.6
Step 4 uses \(\mathrm{Var}(aY+b)=a^2\mathrm{Var}(Y)\) with \(a=2,\ b=0\). Slides p.5
The square root of 4 is 2. The two factors of 2 cancel, and \(r^*=r\).

Why Added

For each \(a>0\), \(aY\) has the same \(\rho\) as \(Y\):

1
\(\rho(aY,X)=\frac{\mathrm{cov}(aY,X)}{\sqrt{\mathrm{var}(X)}\sqrt{\mathrm{var}(aY)}}\)
definition of correlation
2
\(=\frac{a\,\mathrm{cov}(Y,X)}{\sqrt{\mathrm{var}(X)}\sqrt{\mathrm{var}(aY)}}\)
Slides p.6, \(b=1,\ c=d=0\)
3
\(=\frac{a\,\mathrm{cov}(Y,X)}{\sqrt{\mathrm{var}(X)}\sqrt{a^2\mathrm{var}(Y)}}\)
Slides p.5, \(\mathrm{Var}(aY+b)=a^2\mathrm{Var}(Y)\)
4
\(=\frac{a\,\mathrm{cov}(Y,X)}{\sqrt{\mathrm{var}(X)}\,a\sqrt{\mathrm{var}(Y)}}\)
\(a>0\)
5
\(=\frac{\mathrm{cov}(Y,X)}{\sqrt{\mathrm{var}(X)}\sqrt{\mathrm{var}(Y)}}\)
6
\(=\rho(Y,X)\)

The factors \(\frac{1}{n-1}\) cancel in the sample formula:

1
\(r=\frac{\frac{1}{n-1}S_{xy}}{\sqrt{\frac{1}{n-1}S_{yy}}\sqrt{\frac{1}{n-1}S_{xx}}}\)
definitions of \(S_{xy},S_{xx},S_{yy}\)
2
\(=\frac{\frac{1}{n-1}S_{xy}}{\frac{1}{n-1}\sqrt{S_{yy}}\sqrt{S_{xx}}}\)
3
\(=\frac{S_{xy}}{\sqrt{S_{yy}}\sqrt{S_{xx}}}\)
4
\(=\frac{S_{xy}}{\sqrt{S_{xx}S_{yy}}}\)

01.6Goals and notation Slides p.8

What Slides p.8

Recap: Goals and Notation · Lecture 2 · p.8 Possible goals:
• Characterize the relationship between outcome \(y\) and covariate \(x\)
• Predict \(y\) given \(x\)
For the \(i\)th observation:
\(y_i\) is the outcome
\(x_i\) is a covariate
\(i=1,\dots,n\) indexes the observations in the sample
The outcome \(y_i\) is the quantity to explain or predict.
We use the covariate \(x_i\) to explain or predict \(y_i\).
To characterize the relationship is to describe how \(y\) changes with \(x\).

How Added

Match a data set to the notation
  1. Call the quantity to explain or predict \(y\).
  2. Call the quantity that explains it \(x\).
  3. Count the rows to get \(n\). Each row is one \(i\).

Self-check: Each \(i\) has one \(y_i\) and one \(x_i\), from the same person.

Example Added

\(y\): brain weight (g). \(x\): head size (cm³).
\(n=5\). Row 1 is \(i=1\): \(y_1=1530\) and \(x_1=4512\).

Why Added

Notation only. No derivation.

01.7Practice Added

Q1. Change brain weight to kilograms: \(y^*=y/1000\). Use \(S_{xy}=133363\) and \(r=0.7068\). Find \(S_{xy^*}\) and \(r^*\) for \((y^*,x)\).

Answer

\(y_i^*-\bar y^*=(y_i-\bar y)/1000\). Then \(S_{xy^*}=S_{xy}/1000=133363/1000=133.363\).

The numerator and the denominator both get the factor \(1/1000\) (Slides p.5, p.6). They cancel: \(r^*=r=0.7068\).

Q2. For the five people, \(s_x^2=109180.5\), \(s_y^2=20381.7\), and the sample covariance is 33340.75. Use Slides p.6. Find the sample variance of \(x+y\).

Answer
1
\(\mathrm{Var}(x+y)=\mathrm{cov}(x+y,x+y)\)
2
\(=\mathrm{Var}(x)+2\,\mathrm{cov}(x,y)+\mathrm{Var}(y)\)
four-term property
3
\(=109180.5+2(33340.75)+20381.7\)
4
\(=109180.5+66681.5+20381.7\)
5
\(=196243.7\)

\(x\) and \(y\) are not independent. Keep the covariance term.

Q3. Let \(\mathrm{Var}(X)=4\), \(\mathrm{Var}(Y)=9\), and \(\mathrm{cov}(X,Y)=3\). Find \(\rho\) and \(\mathrm{cov}(2Y+1,\,3X-5)\).

Answer

\(\rho=\frac{3}{\sqrt4\sqrt9}=\frac{3}{2\times3}=0.5\).

Use \(\mathrm{cov}(aY+c,bX+d)=ab\,\mathrm{cov}(X,Y)\) with \(a=2,\ c=1,\ b=3,\ d=-5\).

\(\mathrm{cov}(2Y+1,3X-5)=2\times3\times3=18\).

Unit 02The simple linear regression model and its coefficients

Plan · Slides p.9–18

Slides p.10: first 6 rows of the data.

Slides p.11: histograms of \(x\) and \(y\).

Slides p.12: scatterplot of \(y\) against \(x\).

Slides p.13: the model: parameters, errors, data.

Slides p.14–16: meaning of \(\beta_0\) and \(\beta_1\).

Slides p.17: the model as one picture (figure Added).

Slides p.18: four assumptions and the estimation question.

02.1Title page Slides p.9

Title: Lecture 2: Simple Linear Regression: Estimation.
Slides p.1–8 are a review (Unit 01). New material starts at Slides p.10.

02.2Data example: the brainhead data Slides p.10

What Slides p.10

Data Example · Lecture 2 · p.10 The slide gives two columns of the brainhead data: \(x\) = head size, \(y\) = brain weight. It prints the first 6 rows:
row \(i\)\(x\)\(y\)
145121530
237381297
342611335
437771282
541771590
635851300
An observation is one row of the data: one person.
A variable is one column of the data: one type of measurement.
Head size \(x\): head volume, in cubic centimetres (cm³).
Brain weight \(y\): in grams (g).
The brainhead data has \(n=236\) rows (Lecture 1 · p.4).

How Added

Read one row of the data
  1. Call the column that explains \(x\).
  2. Call the column to explain \(y\).
  3. Select a row \(i\).
  4. Read \(x_i\) and \(y_i\), with units.

Self-check: The \(x\) and \(y\) columns both have \(n\) rows.

Example · Rows 1 and 2 Added

Steps 1–2: \(x\) is head size. \(y\) is brain weight.
Steps 3–4, row 1: \(x_1=4512\) cm³ and \(y_1=1530\) g.
Steps 3–4, row 2: \(x_2=3738\) cm³ and \(y_2=1297\) g.

Why · The names \(x\) and \(y\) Added

Each formula symbol refers to one column. For example, \(x_1=4512\) is the first value in the \(x\) column.

02.3Exploratory data analysis: histograms Slides p.11

What Slides p.11

Exploratory Data Analysis · Lecture 2 · p.11 Two histograms: "Head Size (cm^3)" and "Brain Weight (grams)". The vertical axis is "Frequency".
Exploratory data analysis (EDA) uses plots and simple summaries to look at the data before modelling.
A histogram divides the number line into equal intervals (bins). Each bin has one bar.
Frequency: the number of observations in a bin. It is the height of the bar.

How Added

Read a histogram
  1. Read the variable and its unit on the horizontal axis.
  2. Read the bin width.
  3. Read the height of each bar.
  4. Find the highest bar.
  5. Compare the two sides of the highest bar.

Self-check: The bar heights add to \(n=236\).

Example · The brainhead data Added

The bar heights come from a count of the 236 rows in the data file.

Head Size (cm³) 0 10 20 30 40 50 3000 3500 4000 4500 Brain Weight (grams) 0 10 20 30 40 50 1000 1200 1400 1600 Frequency x y
Figure 2-1 (Slides p.11, redrawn from the data) · Left: head size \(x\), bin width 200 cm³. Right: brain weight \(y\), bin width 50 g.
Head size, bar heights from left to right: 1, 6, 19, 41, 48, 45, 36, 24, 8, 7, 1.
Brain weight, bar heights from left to right: 3, 10, 17, 25, 45, 37, 40, 22, 18, 6, 7, 4, 2.
Head size: the highest bar, 3400 to 3600 cm³, has 48 people. Range: 2773 to 4747 cm³ (Lecture 1 · p.23).
Brain weight: the highest bar, 1200 to 1250 g, has 45 people. Range: 1012 to 1635 g (Lecture 1 · p.23).
Shape: both are high in the middle and low at the sides. Both are approximately symmetric.

Why · The sum of the bar heights is \(n\) Added

Each observation is in exactly one bin. The bar heights count each person one time.

1
\[\text{sum for } x=(1+6+19+41)+(48+45+36)+(24+8+7+1)\]
2
\[=67+129+40\]
3
\[=236=n\]
4
\[\text{sum for } y=(3+10+17+25)+(45+37+40)+(22+18+6+7+4+2)\]
5
\[=55+122+59\]
6
\[=236=n\]

02.4Exploratory data analysis: scatterplot Slides p.12

What Slides p.12

EDA · Lecture 2 · p.12 Scatterplot: Brain Weight (grams) against Head Size (cm^3).
A scatterplot has one point \((x_i,y_i)\) for each observation. The brainhead data gives 236 points.
"\(y\) against \(x\)": \(y\) is on the vertical axis, \(x\) on the horizontal axis.

How Added

Draw and read a scatterplot
  1. Put \(x\) on the horizontal axis and \(y\) on the vertical axis.
  2. Draw observation \(i\) at \((x_i,y_i)\).
  3. Find the direction from left to right: up, down, or none.
  4. Find if the points follow approximately a straight line.
  5. Compare the vertical spread at the left and at the right.

Self-check: Find row 1, \((4512,1530)\), on the plot.

Example · The brainhead data Added

3000 3500 4000 4500 Head Size (cm³) 100011001200 1300140015001600 Brain Weight (grams) 1 2 3 4 5 6
Figure 2-2 (Slides p.12, redrawn from the data) · All 236 observations. Orange points 1–6 are the rows of Slides p.10. For example, point 1 is \((4512,1530)\), and point 2 is \((3738,1297)\).
Step 3: the points go up from bottom left to top right. Larger heads usually have heavier brains.
Step 4: the points follow approximately a straight line. There is no clear curve.
Step 5: at one head size, brain weights spread above and below. Point 5 has a smaller head than point 1, but a heavier brain.
Points 1 and 5: \(4512-4177=335\) cm³ for \(x\), and \(1590-1530=60\) g for \(y\).

Why · The next step uses a straight-line model Added

The points follow a line, with random spread above and below it. The model writes the line as \(\beta_0+\beta_1x_i\) and the spread as the random error \(\epsilon_i\).

02.5The simple linear regression model Slides p.13

What Slides p.13

Simple Linear Regression · Lecture 2 · p.13 \[y_i=\beta_0+\beta_1x_i+\epsilon_i,\qquad \epsilon_i\overset{iid}{\sim}N(0,\sigma^2)\] Or: \[y_i\overset{indep}{\sim}N(\beta_0+\beta_1x_i,\ \sigma^2)\] • \(\beta_0,\beta_1,\sigma^2\): fixed, unknown parameters
• \(\epsilon_i\) is unobserved random error term
• \(y_i,x_i\) are the observed data
  • Treat \(x_i\) as fixed
Simple linear regression (SLR) describes the mean of \(y\) with a straight line in one covariate \(x\).
A parameter is a fixed, unknown number of the population.
The error term \(\epsilon_i\) is the random distance of \(y_i\) from the line \(\beta_0+\beta_1x_i\). We cannot observe it.
\(\sigma^2\) is the variance of \(\epsilon_i\).
The normal distribution \(N(\mu,\sigma^2)\) is a continuous, bell-shaped distribution with mean \(\mu\) and variance \(\sigma^2\).
\(\overset{iid}{\sim}\): independent and identically distributed. All \(\epsilon_i\) are independent and have the same distribution \(N(0,\sigma^2)\).
\(\overset{indep}{\sim}\): independent only. The means \(\beta_0+\beta_1x_i\) change with \(i\).
"Treat \(x_i\) as fixed": \(x_i\) is a known constant. Only \(\epsilon_i\) and \(y_i\) are random.

How Added

Write a data set as an SLR model
  1. Call the outcome \(y\).
  2. Call the covariate \(x\).
  3. Count the observations: \(n\).
  4. Write \(y_i=\beta_0+\beta_1x_i+\epsilon_i,\ \epsilon_i\overset{iid}{\sim}N(0,\sigma^2),\ i=1,\dots,n\).
  5. Write the second form \(y_i\overset{indep}{\sim}N(\beta_0+\beta_1x_i,\sigma^2)\).
  6. Sort each symbol: parameter (fixed, unknown), error (random, not observed), or data (observed).

Self-check: There are three parameters: \(\beta_0,\beta_1,\sigma^2\). \(\epsilon_i\) is not a parameter and not data.

Example · The brainhead data Added

1

Outcome and covariate How steps 1–3

\[y_i=\text{brain weight (g)},\quad x_i=\text{head size (cm}^3),\quad n=236\]
2

Model How step 4

\[y_i=\beta_0+\beta_1x_i+\epsilon_i,\quad \epsilon_i\overset{iid}{\sim}N(0,\sigma^2),\quad i=1,\dots,236\]
3

Row 1, \((x_1,y_1)=(4512,1530)\) Slides p.10

\[1530=\beta_0+\beta_1(4512)+\epsilon_1\]
4

Second form How step 5

\[y_1\sim N(\beta_0+4512\beta_1,\ \sigma^2)\]
5

Row 2, \((x_2,y_2)=(3738,1297)\)

\[1297=\beta_0+\beta_1(3738)+\epsilon_2,\qquad y_2\sim N(\beta_0+3738\beta_1,\ \sigma^2)\]
Sort the symbols How step 6

Parameters (fixed, unknown): \(\beta_0,\beta_1,\sigma^2\), the same for all 236 people.

Errors (random, not observed): \(\epsilon_1,\dots,\epsilon_{236}\).

Data (observed): \(x_1=4512,\dots\) and \(y_1=1530,\dots\), 236 pairs.

Rows 1 and 2 have different centres, \(\beta_0+4512\beta_1\) and \(\beta_0+3738\beta_1\). For this reason, the second form writes "indep", not "iid".

Why · The two forms are the same model Added

Start from the first form. \(x_i\) is a constant.

1
\[E[y_i]=E[\beta_0+\beta_1x_i+\epsilon_i]\]
2
\[=\beta_0+\beta_1x_i+E[\epsilon_i]\]
3
\[=\beta_0+\beta_1x_i+0\]
4
\[\mathrm{Var}[y_i]=\mathrm{Var}[\beta_0+\beta_1x_i+\epsilon_i]\]
5
\[=\mathrm{Var}[\epsilon_i]\]
6
\[=\sigma^2\]
7
\[y_i\sim N(\beta_0+\beta_1x_i,\ \sigma^2)\]
8
\[y_i\overset{indep}{\sim}N(\beta_0+\beta_1x_i,\ \sigma^2)\]

02.6The meaning of \(\beta_0,\beta_1\) Slides p.14–16

Slides p.14–16 are three build steps of one slide (footer 12/27).

What Slides p.14–16

Regression Coefficients \((\beta_0,\beta_1)\) · Lecture 2 · p.14–16 \[y_i=\beta_0+\beta_1x_i+\epsilon_i,\qquad \epsilon_i\overset{iid}{\sim}N(0,\sigma^2)\] \[E[y_i|x_i]=\beta_0+\beta_1x_i\] • \(\beta_0\) is an intercept
  • \(E[y_i|x_i=0]=\beta_0+\beta_1(0)=\beta_0\)
• \(\beta_1\) is a slope
  • \(E[y_i|x_i=x^*]=\beta_0+\beta_1(x^*)\)
  • \(E[y_i|x_i=x^*+1]=\beta_0+\beta_1(x^*+1)\) \[\Longrightarrow E[y_i|x_i=x^*+1]-E[y_i|x_i=x^*]=\beta_0+\beta_1(x^*+1)-[\beta_0+\beta_1(x^*)]=\beta_1\]
The conditional expectation \(E[y_i|x_i]\) is the mean of \(y_i\) at a given \(x_i\). Read "|" as "given".
The regression coefficients are \(\beta_0\) and \(\beta_1\).
The intercept \(\beta_0\) is the mean of \(y\) at \(x=0\): the height of the line at the vertical axis.
The slope \(\beta_1\) is the change in the mean of \(y\) when \(x\) increases by 1 unit.
\(x^*\) is any one fixed value of \(x\).
(0, β₀): mean at x = 0 +1 unit mean changes by β₁ x* x*+1 0 E[yᵢ|xᵢ] = β₀ + β₁xᵢ x E[y | x]
Figure 2-3 (Added) · Blue: the mean line. Green: height \(\beta_0\) at \(x=0\). Orange: \(x\) increases by 1. Purple: the mean increases by \(\beta_1\).

How Added

Say what \(\beta_0\) and \(\beta_1\) mean
  1. Write the mean line \(E[y_i|x_i]=\beta_0+\beta_1x_i\).
  2. Put \(x_i=0\). Write: "When \(x\) is 0, the expected \(y\) is \(\beta_0\)."
  3. Put \(x^*\) and \(x^*+1\) into the line. Subtract the first result from the second.
  4. Write: "When \(x\) increases by 1 unit, the expected \(y\) changes by \(\beta_1\)."
  5. Replace "\(x\)" and "\(y\)" with the variable names and units.
  6. For an increase of \(d\) units in \(x\), the change is \(d\beta_1\). Added

Self-check: Each sentence says "expected" or "mean": the coefficients describe \(E[y_i|x_i]\), not one \(y_i\). \(\beta_1\) has the unit "unit of \(y\) per unit of \(x\)".

Example · The brainhead data Added

We have no estimates yet. The sentences have no number for \(\beta_1\).

1

Mean line How step 1

\[E[\text{brain weight}_i\,|\,\text{head size}_i]=\beta_0+\beta_1\,\text{head size}_i\]
2

\(\beta_0\) How step 2

\[E[y_i|x_i=0]=\beta_0+\beta_1(0)=\beta_0\]

Basis: Slides p.15. At a head size of 0 cm³, the expected brain weight is \(\beta_0\) g.

3

\(\beta_1\), with \(x^*=3738\) (row 2, Slides p.10) How step 3

\[E[y_i|x_i=3739]-E[y_i|x_i=3738]=\beta_0+\beta_1(3739)-[\beta_0+\beta_1(3738)]\]
4
\[=\beta_1(3739)-\beta_1(3738)\]
5
\[=\beta_1\]

Basis: Slides p.16, with \(x^*=3738\).

6

Names and units How steps 4–5

When head size increases by 1 cm³, the expected brain weight changes by \(\beta_1\) g.

7

Rows 1 and 2: \(d=4512-3738=774\) How step 6 · Added

\[E[y_i|x_i=4512]-E[y_i|x_i=3738]=\beta_0+\beta_1(4512)-[\beta_0+\beta_1(3738)]\]
8
\[=\beta_1(4512-3738)\]
9
\[=774\beta_1\]

\(\beta_0\) cancels. The result does not depend on \(x^*\).

Optional — not on the slides

Head size goes from 2773 to 4747 cm³ (Lecture 1 · p.23). \(x=0\) is outside this range. Here \(\beta_0\) does not describe a real person.

Why · Derivation Slides p.14–16

1
\[E[y_i|x_i]=\beta_0+\beta_1x_i\]
2
\[E[y_i|x_i=0]=\beta_0+\beta_1(0)\]
3
\[=\beta_0\]
4
\[E[y_i|x_i=x^*]=\beta_0+\beta_1(x^*)\]
5
\[E[y_i|x_i=x^*+1]=\beta_0+\beta_1(x^*+1)\]
6
\[E[y_i|x_i=x^*+1]-E[y_i|x_i=x^*]=\beta_0+\beta_1(x^*+1)-[\beta_0+\beta_1(x^*)]\]
7
\[=\beta_0+\beta_1x^*+\beta_1-\beta_0-\beta_1x^*\]
8
\[=\beta_1\]

02.7A picture of the model Slides p.17 · figure Added

Slides p.17 has only the title "Simple Linear Regression".

E[yᵢ|xᵢ] = β₀ + β₁xᵢ x₁ x₂ x₃ N(β₀+β₁x₁, σ²) y x
Figure 2-4 (Added) · Orange bell curves (rotated by 90°) show the distribution of \(y\) at three values of \(x\). Purple points are possible observed values of \(y\).
Blue line: the mean line \(E[y_i|x_i]=\beta_0+\beta_1x_i\).
Orange bell curve: \(y_i\sim N(\beta_0+\beta_1x_i,\sigma^2)\) at a fixed \(x_i\). Its centre is on the line.
Vertical distance from a purple point to the orange centre: the error \(\epsilon_i=y_i-(\beta_0+\beta_1x_i)\).
All bell curves have the same width: the same variance \(\sigma^2\) at each \(x\).

Figure 2-2 has the same pattern: a line, with spread above and below it.

02.8The four assumptions Slides p.18

What Slides p.18

Simple Linear Regression · Lecture 2 · p.18 \[y_i=\beta_0+\beta_1x_i+\epsilon_i,\qquad \epsilon_i\overset{iid}{\sim}N(0,\sigma^2)\] Or: \[y_i\overset{indep}{\sim}N(\beta_0+\beta_1x_i,\ \sigma^2)\] Assumptions:
1. Linearity
2. Independence
3. Normality
4. Equal variance (homoskedasticity)
How to estimate \(\beta_0\) and \(\beta_1\)?
An assumption is a condition that the model accepts as true. The data do not prove it.
1. Linearity

\(E[y_i|x_i]=\beta_0+\beta_1x_i\) is a straight line in \(x_i\).

2. Independence

The errors \(\epsilon_i\) are independent. Then the \(y_i\) are independent.

3. Normality

Each \(\epsilon_i\) has a normal distribution.

4. Equal variance (homoskedasticity)

Each \(\epsilon_i\) has the same variance \(\sigma^2\) at each \(x_i\). "Homoskedasticity" means "same variance".

How Added

Find each assumption in the model formula
  1. \(\beta_0+\beta_1x_i\) is a straight line: assumption 1.
  2. The first "i" in \(\overset{iid}{\sim}\) means "independent": assumption 2.
  3. The name \(N\): assumption 3.
  4. \(\sigma^2\) has no index \(i\): assumption 4.

Self-check: Each assumption matches one symbol in \(\epsilon_i\overset{iid}{\sim}N(0,\sigma^2)\) or in \(\beta_0+\beta_1x_i\).

Example · The brainhead data Added

1. Linearity: at head size \(x\) cm³, the mean brain weight is \(\beta_0+\beta_1x\) g.
2. Independence: the error of \(y_1=1530\) does not affect the error of \(y_2=1297\).
3. Normality: at one head size, brain weights are bell-shaped around their mean.
4. Equal variance: at 3738 cm³ and at 4512 cm³, brain weights have the same variance \(\sigma^2\).

Figure 2-2 agrees with assumptions 1 and 4.

Why · The four assumptions together give the model Added

1
\[y_i=\beta_0+\beta_1x_i+\epsilon_i,\quad E[\epsilon_i]=0\]
2
\[\mathrm{Var}[\epsilon_i]=\sigma^2\ \text{ for all } i\]
3
\[\epsilon_i\sim N(0,\sigma^2)\]
4
\[\epsilon_i\overset{iid}{\sim}N(0,\sigma^2)\]

Lines 1 and 4 together are the first line of Slides p.18.

We know only the 236 pairs \((x_i,y_i)\), not \(\beta_0\) and \(\beta_1\). An estimate is a number from the data that replaces an unknown parameter.

02.9Practice Added

Q1. Use row 3 of the brainhead data on Slides p.10. Write the model for observation 3 in both forms. Which quantities are observed, and which are unknown?

Answer
Row 3: \((x_3,y_3)=(4261,1335)\).
First form: \(1335=\beta_0+\beta_1(4261)+\epsilon_3,\ \epsilon_3\sim N(0,\sigma^2)\).
Second form: \(y_3\sim N(\beta_0+4261\beta_1,\ \sigma^2)\).
Observed: \(x_3=4261\) and \(y_3=1335\). Unknown: \(\beta_0,\beta_1,\sigma^2\) and \(\epsilon_3\).

Q2. Use the SLR model for brain weight (g) on head size (cm³). Show that \(E[y_i|x_i=4261]-E[y_i|x_i=3738]\) depends only on \(\beta_1\). Then say what \(\beta_1\) means for these data.

Answer
1
\[E[y_i|x_i=4261]-E[y_i|x_i=3738]=\beta_0+\beta_1(4261)-[\beta_0+\beta_1(3738)]\]
2
\[=\beta_1(4261-3738)\]
3
\[=523\beta_1\]

\(\beta_0\) cancels. Meaning: when head size increases by 1 cm³, the expected brain weight changes by \(\beta_1\) g.

Q3. Name the model assumption that each statement describes.
(a) \(\mathrm{Var}[\epsilon_i]=\sigma^2\) for each \(i\).
(b) \(E[y_i|x_i]=\beta_0+\beta_1x_i\).
(c) The error of person 1 gives no information about the error of person 2.
(d) \(\epsilon_i\) has a bell-shaped \(N\) distribution.

Answer
(a) Equal variance (homoskedasticity): \(\sigma^2\) has no index \(i\).
(b) Linearity.
(c) Independence.
(d) Normality.

Unit 03Least squares estimation

Plan · Slides p.19–26

Slides p.19–20: many lines fit one scatterplot. Select the best line.

Slides p.21: make the sum of squares \(S(\beta_0,\beta_1)\) a minimum. Set both partial derivatives to 0.

Slides p.22–23: get \(\hat\beta_0=\bar y-\hat\beta_1\bar x\).

Slides p.24–25: get a formula for \(\hat\beta_1\).

Slides p.26: write \(\hat\beta_1\) as \(S_{xy}/S_{xx}\).

Symbols Added

\(\sum_{i=1}^n a_i\) is \(a_1+a_2+\dots+a_n\). A \(\sum\) without limits means \(\sum_{i=1}^n\).
The sample mean gives \(\sum x_i=n\bar x\) and \(\sum y_i=n\bar y\).
An estimator is a formula that gives a value for a parameter from the data. A hat marks it: \(\hat\beta_0\) estimates \(\beta_0\).

Data Slides p.10

The examples use the first 6 brainhead observations: \(n=6\).
\(i\)123456
\(x_i\) (cm³)451237384261377741773585
\(y_i\) (g)153012971335128215901300

\(\sum x_i=4512+3738+4261+3777+4177+3585=24050\) and \(\sum y_i=1530+1297+1335+1282+1590+1300=8334\).

03.1Section page and the line of best fit Slides p.19–20

Slides p.19: section page "Estimating \(\beta_0,\beta_1\)" (Slides p.20–26).
Slides p.20: title "Line of Best Fit" only.
The line of best fit is the line nearest to the points, by a stated rule.

Three candidate lines Added

3000 3500 4000 4500 1100 1200 1300 1400 1500 1600 head size x (cm³) brain weight y (g)
Figure 3-1 (Added) · 236 brainhead points. Orange dashed: the mean brain weight, approximately 1284 g (Lecture 1 p.23). Purple dashed: \(y=385.4323+0.2608207x\). Green: \(y=335.4323+0.2608207x\).

All three lines are near the points. We need a rule that gives a number for each line.

03.2The least squares rule Slides p.21

What Slides p.21

Least Squares Estimation · Lecture 2 · p.21 Minimize the sum of squares: \[S(\beta_0,\beta_1)=\sum_{i=1}^n (y_i-\beta_0-\beta_1x_i)^2\] \[\Longrightarrow\quad \frac{\partial S(\beta_0,\beta_1)}{\partial\beta_0}=0,\qquad \frac{\partial S(\beta_0,\beta_1)}{\partial\beta_1}=0\]
\(\beta_0+\beta_1x_i\) is the height of the line at \(x_i\).
\(y_i-\beta_0-\beta_1x_i\) is the vertical distance from point \(i\) to the line. It is negative below the line.
Squares are never negative. Distances above and below the line do not cancel.
The sum of squares \(S(\beta_0,\beta_1)\) is a function of the line. A different line gives a different \(S\).
Least squares (LS) selects the \((\beta_0,\beta_1)\) with the smallest \(S\). These values, \(\hat\beta_0,\hat\beta_1\), are the least squares estimators.
The partial derivative \(\partial S/\partial\beta_0\) is the rate of change of \(S\) in \(\beta_0\), with \(\beta_1\) constant. \(\partial S/\partial\beta_1\) keeps \(\beta_0\) constant.

How Added

Calculate \(S\) for a given line
  1. For each point, calculate the height \(\beta_0+\beta_1x_i\).
  2. Calculate each distance \(y_i-\beta_0-\beta_1x_i\).
  3. Square each distance. Add the \(n\) squares to get \(S\).
  4. The line with the smallest \(S\) is the best by least squares.

Self-check: \(S\ge0\). \(S\) has the unit g².

Example · 6 observations from Slides p.10 Added

Line A: \(\beta_0=1389,\ \beta_1=0\), a horizontal line at \(\bar y=8334/6=1389\).
Line B: \(\beta_0=300,\ \beta_1=0.27\).
Line C: \(\beta_0=100,\ \beta_1=0.32\).

Line A:

Distances: \(1530-1389=141\), \(1297-1389=-92\), \(1335-1389=-54\), \(1282-1389=-107\), \(1590-1389=201\), \(1300-1389=-89\).
Squares: \(19881,\ 8464,\ 2916,\ 11449,\ 40401,\ 7921\).
\(S(1389,0)=19881+8464+2916+11449+40401+7921=91032\).

Line B, height \(300+0.27x_i\):

\(i\)\(0.27x_i\)heightdistancesquare
11218.241518.2411.76138.2976
21009.261309.26−12.26150.3076
31150.471450.47−115.4713333.3209
41019.791319.79−37.791428.0841
51127.791427.79162.2126312.0841
6967.951267.9532.051027.2025
\(S(300,0.27)=138.2976+150.3076+13333.3209+1428.0841+26312.0841+1027.2025=42389.2968\).

Line C, height \(100+0.32x_i\):

\(i\)\(0.32x_i\)heightdistancesquare
11443.841543.84−13.84191.5456
21196.161296.160.840.7056
31363.521463.52−128.5216517.3904
41208.641308.64−26.64709.6896
51336.641436.64153.3623519.2896
61147.201247.2052.802787.8400
\(S(100,0.32)=191.5456+0.7056+16517.3904+709.6896+23519.2896+2787.84=43726.4608\).

Line B has the smallest \(S\) of the three. Section 03.5 finds the smallest \(S\) of all lines.

3000 3500 4000 4500 1100 1200 1300 1400 1500 1600 head size x (cm³) brain weight y (g)
Figure 3-2 (Added) · 236 points, the green line \(y=335.4323+0.2608207x\), and each vertical distance (orange). \(S\) is the sum of the squared orange lengths.

Why · The partial derivatives are 0 at the minimum Added

\(S(\beta_0,\beta_1)\) is a smooth polynomial of degree 2 in \(\beta_0\) and \(\beta_1\).
At the minimum, a small change in \(\beta_0\) alone cannot make \(S\) smaller: \(\partial S/\partial\beta_0=0\).
The same is true for \(\beta_1\): \(\partial S/\partial\beta_1=0\).

This gives two equations in two unknowns.

03.3The derivative for \(\beta_0\): solve for \(\hat\beta_0\) Slides p.22–23

What Slides p.22–23

Least Squares Estimation · Lecture 2 · p.23 \[\frac{\partial S(\beta_0,\beta_1)}{\partial\beta_0}=\sum_{i=1}^n 2(y_i-\beta_0-\beta_1x_i)(-1),\quad\text{set to 0 and solve:}\] \[0=\sum_{i=1}^n(y_i-\hat\beta_0-\hat\beta_1x_i)\] \[0=\sum_{i=1}^n y_i-n\hat\beta_0-\hat\beta_1\sum_{i=1}^n x_i\] \[\hat\beta_0=\left(\frac1n\sum_{i=1}^n y_i\right)-\hat\beta_1\left(\frac1n\sum_{i=1}^n x_i\right)=\bar y-\hat\beta_1\bar x\]

Why the hat appears on line 2: before "set to 0", \(\beta_0,\beta_1\) can have any value. "Set to 0" keeps only the values that make \(S\) a minimum. These values are the estimates, so they get a hat.

When you know \(\hat\beta_1\), the two sample means give \(\hat\beta_0\). The same equation, \(\bar y=\hat\beta_0+\hat\beta_1\bar x\), puts \((\bar x,\bar y)\) on the least squares line.

Slides p.22 shows only the first line. Slides p.23 shows the full slide.

How Added

Calculate \(\hat\beta_0\) from \(\hat\beta_1\)
  1. Calculate \(\bar x\) and \(\bar y\).
  2. Calculate \(\hat\beta_1\bar x\).
  3. Calculate \(\hat\beta_0=\bar y-\hat\beta_1\bar x\).

Self-check: \(\hat\beta_0+\hat\beta_1\bar x=\bar y\).

Example · 6 observations from Slides p.10 Added

\(\hat\beta_1=0.2739824\) comes from Section 03.4.

Step 1: \(\bar x=24050/6=4008.333\), \(\bar y=8334/6=1389\).
Step 2: \(\hat\beta_1\bar x=0.2739824\times4008.333=1098.213\).
Step 3: \(\hat\beta_0=1389-1098.213=290.787\) g.
Check: \(290.787+1098.213=1389.000=\bar y\).

All 236 observations: Slides p.38 · Lecture 1 p.23

Slides p.38: \(\hat\beta_0=335.4323150\) and \(\hat\beta_1=0.2608207\).
Lecture 1 p.23, rounded: \(\bar x\approx3638\) and \(\bar y\approx1284\).
\(\hat\beta_1\bar x\approx0.2608207\times3638=948.866\).
\(\hat\beta_0+\hat\beta_1\bar x\approx335.432+948.866=1284.298\approx\bar y\). The rounded means cause the small difference.

Why · Derivation Slides p.22–23

1
\[S(\beta_0,\beta_1)=\sum_{i=1}^n (y_i-\beta_0-\beta_1x_i)^2\]
2
\[\frac{\partial S(\beta_0,\beta_1)}{\partial\beta_0}=\sum_{i=1}^n \frac{\partial}{\partial\beta_0}(y_i-\beta_0-\beta_1x_i)^2\]
Derivative of a sum is the sum of derivatives.
3
\[=\sum_{i=1}^n 2(y_i-\beta_0-\beta_1x_i)\cdot\frac{\partial}{\partial\beta_0}(y_i-\beta_0-\beta_1x_i)\]
Chain rule: \(u^2\) gives \(2u\) times the derivative of \(u\).
4
\[=\sum_{i=1}^n 2(y_i-\beta_0-\beta_1x_i)(-1)\]
Derivative of \(-\beta_0\) is \(-1\). Slides p.23, line 1.
5
\[0=\sum_{i=1}^n 2(y_i-\hat\beta_0-\hat\beta_1x_i)(-1)\]
Set to 0. Solutions get a hat.
6
\[0=-2\sum_{i=1}^n (y_i-\hat\beta_0-\hat\beta_1x_i)\]
7
\[0=\sum_{i=1}^n (y_i-\hat\beta_0-\hat\beta_1x_i)\]
Slides p.23, line 2.
8
\[0=\sum_{i=1}^n y_i-\sum_{i=1}^n\hat\beta_0-\sum_{i=1}^n\hat\beta_1x_i\]
9
\[0=\sum_{i=1}^n y_i-n\hat\beta_0-\hat\beta_1\sum_{i=1}^n x_i\]
\(n\) copies of \(\hat\beta_0\) add to \(n\hat\beta_0\). Slides p.23, line 3.
10
\[n\hat\beta_0=\sum_{i=1}^n y_i-\hat\beta_1\sum_{i=1}^n x_i\]
11
\[\hat\beta_0=\left(\frac1n\sum_{i=1}^n y_i\right)-\hat\beta_1\left(\frac1n\sum_{i=1}^n x_i\right)\]
12
\[\hat\beta_0=\bar y-\hat\beta_1\bar x\]
Sample mean. Slides p.23, last line. ∎

03.4The derivative for \(\beta_1\): solve for \(\hat\beta_1\) Slides p.24–25

What Slides p.24–25

Least Squares Estimation · Lecture 2 · p.25 \[\frac{\partial S(\beta_0,\beta_1)}{\partial\beta_1}=\sum_{i=1}^n 2(y_i-\beta_0-\beta_1x_i)(-x_i),\quad\text{set to 0 and solve:}\] \[0=\sum_{i=1}^n y_ix_i-\hat\beta_0n\bar x-\hat\beta_1\sum_{i=1}^n x_i^2\] \[0=\sum_{i=1}^n y_ix_i-(\bar y-\hat\beta_1\bar x)n\bar x-\hat\beta_1\sum_{i=1}^n x_i^2\] \[0=\sum_{i=1}^n y_ix_i-n\bar y\bar x+\hat\beta_1n\bar x^2-\hat\beta_1\sum_{i=1}^n x_i^2\] \[0=\sum_{i=1}^n y_ix_i-n\bar y\bar x+\hat\beta_1\left(n\bar x^2-\sum_{i=1}^n x_i^2\right)\] \[\hat\beta_1=\frac{\sum_{i=1}^n y_ix_i-n\bar y\bar x}{\sum_{i=1}^n x_i^2-n\bar x^2}\]

Slides p.24 shows only the first line. Slides p.25 shows the full slide.

How Added

Calculate \(\hat\beta_1\) with the formula on Slides p.25
  1. Calculate \(n\), \(\bar x\), and \(\bar y\).
  2. Calculate \(\sum y_ix_i\).
  3. Calculate \(\sum x_i^2\).
  4. Calculate the numerator \(\sum y_ix_i-n\bar y\bar x\).
  5. Calculate the denominator \(\sum x_i^2-n\bar x^2\).
  6. Divide the numerator by the denominator.

Self-check: The denominator is positive when the \(x_i\) are not all equal. \(\hat\beta_1\) has the unit of \(y\) per unit of \(x\).

Example · 6 observations from Slides p.10 Added

Step 1: \(n=6\), \(\bar x=24050/6=4008.333\), \(\bar y=8334/6=1389\).
Step 2: \(4512\times1530=6903360\), \(3738\times1297=4848186\), \(4261\times1335=5688435\), \(3777\times1282=4842114\), \(4177\times1590=6641430\), \(3585\times1300=4660500\).
\(\sum y_ix_i=33584025\).
Step 3: \(x_i^2\): \(20358144\), \(13972644\), \(18156121\), \(14265729\), \(17447329\), \(12852225\).
\(\sum x_i^2=97052192\).
Step 4: \(n\bar y\bar x=\bar y\,(n\bar x)=1389\times24050=33405450\). Numerator: \(33584025-33405450=178575\).
Step 5: \(n\bar x^2=(n\bar x)^2/n=24050^2/6=578402500/6=96400416.667\). Denominator: \(97052192-96400416.667=651775.333\).
Step 6: \(\hat\beta_1=178575/651775.333=0.2739824\) g/cm³.

Why · Derivation Slides p.24–25

1
\[S(\beta_0,\beta_1)=\sum_{i=1}^n (y_i-\beta_0-\beta_1x_i)^2\]
2
\[\frac{\partial S(\beta_0,\beta_1)}{\partial\beta_1}=\sum_{i=1}^n 2(y_i-\beta_0-\beta_1x_i)\cdot\frac{\partial}{\partial\beta_1}(y_i-\beta_0-\beta_1x_i)\]
Sum rule and chain rule.
3
\[=\sum_{i=1}^n 2(y_i-\beta_0-\beta_1x_i)(-x_i)\]
Derivative of \(-\beta_1x_i\) is \(-x_i\). Slides p.25, line 1.
4
\[0=\sum_{i=1}^n 2(y_i-\hat\beta_0-\hat\beta_1x_i)(-x_i)\]
Set to 0.
5
\[0=\sum_{i=1}^n (y_i-\hat\beta_0-\hat\beta_1x_i)x_i\]
6
\[0=\sum_{i=1}^n (y_ix_i-\hat\beta_0x_i-\hat\beta_1x_i^2)\]
7
\[0=\sum_{i=1}^n y_ix_i-\hat\beta_0\sum_{i=1}^n x_i-\hat\beta_1\sum_{i=1}^n x_i^2\]
8
\[0=\sum_{i=1}^n y_ix_i-\hat\beta_0n\bar x-\hat\beta_1\sum_{i=1}^n x_i^2\]
Substitute \(\sum x_i=n\bar x\). Slides p.25, line 2.
9
\[0=\sum_{i=1}^n y_ix_i-(\bar y-\hat\beta_1\bar x)n\bar x-\hat\beta_1\sum_{i=1}^n x_i^2\]
Substitute \(\hat\beta_0=\bar y-\hat\beta_1\bar x\). Slides p.25, line 3.
10
\[0=\sum_{i=1}^n y_ix_i-n\bar y\bar x+\hat\beta_1n\bar x^2-\hat\beta_1\sum_{i=1}^n x_i^2\]
Slides p.25, line 4.
11
\[0=\sum_{i=1}^n y_ix_i-n\bar y\bar x+\hat\beta_1\left(n\bar x^2-\sum_{i=1}^n x_i^2\right)\]
Slides p.25, line 5.
12
\[\hat\beta_1\left(\sum_{i=1}^n x_i^2-n\bar x^2\right)=\sum_{i=1}^n y_ix_i-n\bar y\bar x\]
13
\[\hat\beta_1=\frac{\sum_{i=1}^n y_ix_i-n\bar y\bar x}{\sum_{i=1}^n x_i^2-n\bar x^2}\]
Slides p.25, last line. ∎

03.5The short form: \(\hat\beta_1^{LS}=S_{xy}/S_{xx}\) Slides p.26

What Slides p.26

Continued · Lecture 2 · p.26 \[\hat\beta_1^{LS}=\frac{\sum y_ix_i-\frac1n\sum y_i\sum x_i}{\sum x_i^2-n\bar x^2}=\frac{\sum y_i(x_i-\bar x)}{\sum x_i(x_i-\bar x)}=\frac{\sum(y_i-\bar y)(x_i-\bar x)}{\sum(x_i-\bar x)^2}\] because \(\sum\bar y(x_i-\bar x)=\bar y\sum(x_i-\bar x)=\bar y(\sum x_i-n\bar x)=0\).
So the least squares estimators are: \[\hat\beta_1^{LS}=\frac{S_{xy}}{S_{xx}},\qquad \hat\beta_0^{LS}=\bar y-\hat\beta_1^{LS}\bar x.\]
The superscript \(LS\) marks a least squares estimator. \(\hat\beta_1^{LS}\) is \(\hat\beta_1\) of Section 03.4.

How Added

Calculate \(\hat\beta_0^{LS},\hat\beta_1^{LS}\)
  1. Calculate \(n\), \(\bar x\), and \(\bar y\).
  2. Calculate each deviation \(x_i-\bar x\) and \(y_i-\bar y\).
  3. Calculate \(S_{xy}=\sum(y_i-\bar y)(x_i-\bar x)\).
  4. Calculate \(S_{xx}=\sum(x_i-\bar x)^2\).
  5. Calculate \(\hat\beta_1^{LS}=S_{xy}/S_{xx}\).
  6. Calculate \(\hat\beta_0^{LS}=\bar y-\hat\beta_1^{LS}\bar x\).

Self-check: Each set of deviations adds to 0. \(S_{xx}>0\). \(\hat\beta_1^{LS}\) has the sign of \(S_{xy}\). \((\bar x,\bar y)\) is on the line.

Example · 6 observations from Slides p.10 Added

Step 1: \(n=6\), \(\bar x=4008.333\), \(\bar y=1389\).
Step 2: \(x_i-\bar x\): \(503.667,\ -270.333,\ 252.667,\ -231.333,\ 168.667,\ -423.333\). Sum: 0.
\(y_i-\bar y\): \(141,\ -92,\ -54,\ -107,\ 201,\ -89\). Sum: 0.
Step 3: \((y_i-\bar y)(x_i-\bar x)\): \(71017,\ 24870.667,\ -13644,\ 24752.667,\ 33902,\ 37676.667\).
\(S_{xy}=71017+24870.667-13644+24752.667+33902+37676.667=178575\), the numerator of Section 03.4.
Step 4: \((x_i-\bar x)^2\): \(253680.111,\ 73080.111,\ 63840.444,\ 53515.111,\ 28448.444,\ 179211.111\).
\(S_{xx}=651775.333\), the denominator of Section 03.4. The rounded squares add to 651775.332.
Step 5: \(\hat\beta_1^{LS}=178575/651775.333=0.2739824\).
Step 6: \(\hat\beta_0^{LS}=1389-0.2739824\times4008.333=1389-1098.213=290.787\).

Compare with the three lines of Section 03.2. The least squares line is \(y=290.787+0.2739824x\).

Heights \(\hat\beta_0+\hat\beta_1x_i\): \(1526.996,\ 1314.933,\ 1458.226,\ 1325.619,\ 1435.212,\ 1273.014\).
Distances: \(3.004,\ -17.933,\ -123.226,\ -43.619,\ 154.788,\ 26.986\).
Squares: \(9.03,\ 321.61,\ 15184.70,\ 1902.59,\ 23959.42,\ 728.24\).
\(S(290.787,\,0.2739824)=42105.59\). It is smaller than 91032 (Line A), 42389.2968 (Line B), and 43726.4608 (Line C).

All 236 observations: \(\hat\beta_0=335.4323150\) and \(\hat\beta_1=0.2608207\). Slides p.38

3000 3500 4000 4500 1100 1200 1300 1400 1500 1600 head size x (cm³) brain weight y (g)
Figure 3-3 (Added) · 236 points and the least squares line \(\hat y=335.432+0.2608x\) (green). The orange point \((\bar x,\bar y)\), approximately \((3638,\ 1284)\), is on the line.

Meaning (Unit 02): 1 cm³ more head size gives approximately 0.261 g more expected brain weight.

Why · Derivation Slides p.26

Numerator:

1
\[\sum y_ix_i-n\bar y\bar x\]
Numerator on Slides p.25.
2
\[=\sum y_ix_i-n\left(\frac1n\sum y_i\right)\left(\frac1n\sum x_i\right)\]
Sample mean.
3
\[=\sum y_ix_i-\frac1n\sum y_i\sum x_i\]
First numerator on Slides p.26.
4
\[=\sum y_ix_i-\bar x\sum y_i\]
\(\frac1n\sum x_i=\bar x\).
5
\[=\sum (y_ix_i-y_i\bar x)\]
6
\[=\sum y_i(x_i-\bar x)\]
Second numerator on Slides p.26.
7
\[=\sum y_i(x_i-\bar x)-\sum\bar y(x_i-\bar x)\]
\(\sum\bar y(x_i-\bar x)=\bar y(\sum x_i-n\bar x)=0\): the "because" line, Slides p.26.
8
\[=\sum (y_i-\bar y)(x_i-\bar x)\]
9
\[=S_{xy}\]
Definition of \(S_{xy}\).

Denominator, with \(x\) in place of \(y\):

1
\[\sum x_i^2-n\bar x^2\]
Denominator on Slides p.25.
2
\[=\sum x_i^2-\bar x\,(n\bar x)\]
3
\[=\sum x_i^2-\bar x\sum x_i\]
Substitute \(n\bar x=\sum x_i\).
4
\[=\sum (x_ix_i-x_i\bar x)\]
5
\[=\sum x_i(x_i-\bar x)\]
Second denominator on Slides p.26.
6
\[=\sum x_i(x_i-\bar x)-\sum\bar x(x_i-\bar x)\]
\(\sum\bar x(x_i-\bar x)=\bar x(\sum x_i-n\bar x)=0\). (Added)
7
\[=\sum (x_i-\bar x)(x_i-\bar x)\]
8
\[=\sum (x_i-\bar x)^2=S_{xx}\]
Definition of \(S_{xx}\).

Together:

1
\[\hat\beta_1^{LS}=\frac{\sum y_ix_i-n\bar y\bar x}{\sum x_i^2-n\bar x^2}\]
Section 03.4.
2
\[=\frac{\sum(y_i-\bar y)(x_i-\bar x)}{\sum(x_i-\bar x)^2}\]
The two chains above.
3
\[=\frac{S_{xy}}{S_{xx}}\]
With Section 03.3: \(\hat\beta_0^{LS}=\bar y-\hat\beta_1^{LS}\bar x\). ∎

03.6The open question: why least squares Slides p.26

Lecture 2 · p.26 But why minimize least squares? Why not some other objective function?
An objective function is the function that we make a minimum or a maximum. Here it is \(S(\beta_0,\beta_1)\).

Unit 04 answers it. With normal errors, maximum likelihood estimation gives the same \(\hat\beta_0,\hat\beta_1\) as least squares.

03.7Practice Added

Q1. Data \((x_i,y_i)\): (1, 2), (2, 4), (3, 5), (4, 4), (5, 5). Calculate \(\hat\beta_0^{LS}\) and \(\hat\beta_1^{LS}\) with \(\hat\beta_1^{LS}=S_{xy}/S_{xx}\).

Answer
Step 1: \(n=5\), \(\bar x=15/5=3\), \(\bar y=20/5=4\).
Step 2: \(x_i-\bar x\): \(-2,-1,0,1,2\). \(y_i-\bar y\): \(-2,0,1,0,1\).
Step 3: \(S_{xy}=(-2)(-2)+(-1)(0)+(0)(1)+(1)(0)+(2)(1)=4+0+0+0+2=6\).
Step 4: \(S_{xx}=4+1+0+1+4=10\).
Step 5: \(\hat\beta_1^{LS}=6/10=0.6\).
Step 6: \(\hat\beta_0^{LS}=4-0.6\times3=4-1.8=2.2\).
Check: \(2.2+0.6\times3=4=\bar y\).

Q2. For the same data, calculate \(\hat\beta_1\) with \(\hat\beta_1=\dfrac{\sum y_ix_i-n\bar y\bar x}{\sum x_i^2-n\bar x^2}\). Check that it agrees with Q1.

Answer
Step 1: \(\sum y_ix_i=2+8+15+16+25=66\).
Step 2: \(\sum x_i^2=1+4+9+16+25=55\).
Step 3: numerator \(66-5\times4\times3=66-60=6\).
Step 4: denominator \(55-5\times3^2=55-45=10\).
Step 5: \(\hat\beta_1=6/10=0.6\), as in Q1. The numerator is \(S_{xy}\), and the denominator is \(S_{xx}\).

Q3. Show that \(\sum_{i=1}^n (x_i-\bar x)=0\). Use it to show that \(\sum_{i=1}^n x_i(x_i-\bar x)=\sum_{i=1}^n (x_i-\bar x)^2\).

Answer
1
\[\sum (x_i-\bar x)=\sum x_i-n\bar x\]
\(n\) copies of \(\bar x\) add to \(n\bar x\).
2
\[=n\bar x-n\bar x=0\]
Substitute \(\sum x_i=n\bar x\).
3
\[\sum (x_i-\bar x)^2=\sum (x_i-\bar x)x_i-\sum (x_i-\bar x)\bar x\]
Split one factor \(x_i-\bar x\).
4
\[=\sum x_i(x_i-\bar x)-\bar x\sum (x_i-\bar x)\]
5
\[=\sum x_i(x_i-\bar x)-\bar x\cdot0=\sum x_i(x_i-\bar x)\]
Line 2. ∎

This identity makes the two denominators on Slides p.26 equal.

Unit 04Maximum likelihood estimation and its equality to least squares

Plan · Slides p.27–29

Slides p.27: write the likelihood \(L\). Take the log to get \(\ell\).

Slides p.28: differentiate \(\ell\) for \(\beta_0\), \(\beta_1\), \(\sigma^2\): (⋆), (⋆⋆), and a third equation.

Slides p.29: (⋆) = 0 and (⋆⋆) = 0 is the same as "minimize the sum of squares": \(\hat\beta^{LS}=\hat\beta^{ML}\).

Start point (results of Units 02–03) · Added

Model: \(y_i=\beta_0+\beta_1x_i+\epsilon_i\), with \(\epsilon_i\overset{iid}{\sim}N(0,\sigma^2)\). Same as \(y_i\overset{indep}{\sim}N(\beta_0+\beta_1x_i,\sigma^2)\).

Least squares (LS) minimizes \(S(\beta_0,\beta_1)=\sum_{i=1}^n(y_i-\beta_0-\beta_1x_i)^2\). Result: \(\hat\beta_1^{LS}=S_{xy}/S_{xx}\) and \(\hat\beta_0^{LS}=\bar y-\hat\beta_1^{LS}\bar x\) (Slides p.26).

Brainhead: \((x_1,y_1)=(4512,1530)\) and \((x_2,y_2)=(3738,1297)\) (Slides p.10). Slides p.38: \(\hat\beta_0=335.4323150\), \(\hat\beta_1=0.2608207\), fitted values 1512.255 and 1310.380 for observations 1 and 2.

Small data set (Added): \((x_i,y_i)\) = (1, 2), (2, 3), (3, 5), (4, 6), \(n=4\).

04.1Likelihood and log-likelihood Slides p.27

What Slides p.27

Maximum Likelihood Estimation · Lecture 2 · p.27 Recall: \(y_i\overset{indep}{\sim}N(\beta_0+\beta_1x_i,\sigma^2)\)
We can write the likelihood: \[L(\beta_0,\beta_1,\sigma^2|y)=\prod_{i=1}^n\frac{1}{\sqrt{2\pi\sigma^2}}\exp\left(-\frac{(y_i-[\beta_0+\beta_1x_i])^2}{2\sigma^2}\right)=(2\pi\sigma^2)^{-n/2}\exp\left(-\sum_{i=1}^n\frac{(y_i-[\beta_0+\beta_1x_i])^2}{2\sigma^2}\right)\] It's more convenient to work with the log-likelihood: \[\ell(\beta_0,\beta_1,\sigma^2|y)=-\frac n2\log(2\pi)-\frac n2\log(\sigma^2)-\frac{1}{2\sigma^2}\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])^2\]

Normal density: the PDF of \(N(\mu,\sigma^2)\), \(f(y)=\dfrac{1}{\sqrt{2\pi\sigma^2}}\exp\left(-\dfrac{(y-\mu)^2}{2\sigma^2}\right)\). It is largest at \(y=\mu\).

\(\exp(a)=e^a\), with \(e\approx2.718\). \(\log\) is the natural log (base \(e\)).

\(\prod_{i=1}^n a_i=a_1\times a_2\times\cdots\times a_n\) is a product.

The likelihood \(L(\beta_0,\beta_1,\sigma^2|y)\) is the joint density of the data, as a function of the parameters. "\(|y\)": the data \(y=(y_1,\dots,y_n)\) are fixed.

The log-likelihood is \(\ell=\log L\).

Maximum likelihood estimation (MLE) uses the parameter values that make \(L\) largest: \(\hat\beta_0^{ML},\hat\beta_1^{ML}\).

The \(y_i\) are independent. Their joint density is the product of the single densities. The log is increasing: \(L\) and \(\ell\) have their maximum at the same point. The log changes the product into a sum, which is easier to differentiate.

How Added

Write \(\ell\) and calculate its value
  1. Write one density. Replace \(\mu\) with \(\beta_0+\beta_1x_i\) in the normal density.
  2. Multiply to get \(L\). The \(y_i\) are independent.
  3. Take the log to get \(\ell\). It has three terms: \(-\frac n2\log(2\pi)\), \(-\frac n2\log(\sigma^2)\), and \(-\frac{1}{2\sigma^2}\sum(y_i-[\beta_0+\beta_1x_i])^2\).
  4. Find each difference \(y_i-[\beta_0+\beta_1x_i]\).
  5. Square the differences and add them.
  6. Calculate the three terms with \(n\), \(\sigma^2\), and the sum of squares.
  7. Add the three terms.

Self-check: ① The first term uses only \(n\). ② The second uses only \(n\) and \(\sigma^2\). ③ The third term is always \(\le0\). ④ One observation contributes the log of its density.

Example 1 · Density of one brainhead observation Added

Observation 1, with \(\beta_0=335.4323150\), \(\beta_1=0.2608207\) (Slides p.38) and \(\sigma^2=5000\).

The value 5000 is only for this example. Unit 06 estimates \(\sigma^2\).

1

Mean of observation 1 How step 1

\[x_1=4512,\quad y_1=1530\]
\[\beta_0+\beta_1x_1=335.4323150+0.2608207\times4512=335.4323150+1176.8230=1512.255\]
\[y_1-[\beta_0+\beta_1x_1]=1530-1512.255=17.745\]

Slides p.10: \(x_1,y_1\). Slides p.38: 1512.255.

2

Constant in front of the exponential How step 1

\[\frac{1}{\sqrt{2\pi\sigma^2}}=\frac{1}{\sqrt{2\pi\times5000}}=\frac{1}{\sqrt{31415.93}}=\frac{1}{177.2454}=0.005641896\]
3

Exponential part How step 1

\[\frac{(17.745)^2}{2\times5000}=\frac{314.8850}{10000}=0.03148850\]
\[\exp(-0.03148850)=0.9690021\]
4

Density How step 1

\[f(y_1)=0.005641896\times0.9690021=0.005467009\]
5

Contribution to \(\ell\) How steps 6–7

\[-\frac12\log(2\pi)-\frac12\log(5000)-0.03148850\]
\[=-0.9189385-4.2585966-0.0314885=-5.2090236\]

Check: \(\log(0.005467009)=-5.209024\) (self-check ④). ▲

\(L\) multiplies \(n\) densities such as 0.005467 and becomes very small for large \(n\). \(\ell\) adds terms such as \(-5.21\).

Example 2 · \(\ell\) for the small data set Added

\(\beta_0=0.5\), \(\beta_1=1.4\), \(\sigma^2=1\). These are the LS estimates (Example 3, Section 04.3).

1

Line heights How step 4

\[0.5+1.4\times1=1.9,\quad0.5+1.4\times2=3.3,\quad0.5+1.4\times3=4.7,\quad0.5+1.4\times4=6.1\]
2

Differences \(y_i-[\beta_0+\beta_1x_i]\) How step 4

\[2-1.9=0.1,\quad3-3.3=-0.3,\quad5-4.7=0.3,\quad6-6.1=-0.1\]
3

Sum of squares How step 5

\[0.1^2+(-0.3)^2+0.3^2+(-0.1)^2=0.01+0.09+0.09+0.01=0.2\]
4

Three terms How step 6

\[-\frac42\log(2\pi)=-2\times1.837877=-3.675754\]
\[-\frac42\log(1)=-2\times0=0\]
\[-\frac{1}{2\times1}\times0.2=-0.1\]
5

Add How step 7

\[\ell(0.5,\,1.4,\,1\,|\,y)=-3.675754+0-0.1=-3.775754\]

▲

Why · From \(L\) to \(\ell\) Slides p.27

1
\[L=\prod_{i=1}^n\frac{1}{\sqrt{2\pi\sigma^2}}\exp\left(-\frac{(y_i-[\beta_0+\beta_1x_i])^2}{2\sigma^2}\right)\]
2
\[=\left(\prod_{i=1}^n\frac{1}{\sqrt{2\pi\sigma^2}}\right)\left(\prod_{i=1}^n\exp\left(-\frac{(y_i-[\beta_0+\beta_1x_i])^2}{2\sigma^2}\right)\right)\]
3
\[=\left(\frac{1}{\sqrt{2\pi\sigma^2}}\right)^n\prod_{i=1}^n\exp\left(-\frac{(y_i-[\beta_0+\beta_1x_i])^2}{2\sigma^2}\right)\]
4
\[=(2\pi\sigma^2)^{-n/2}\prod_{i=1}^n\exp\left(-\frac{(y_i-[\beta_0+\beta_1x_i])^2}{2\sigma^2}\right)\]
5
\[=(2\pi\sigma^2)^{-n/2}\exp\left(-\sum_{i=1}^n\frac{(y_i-[\beta_0+\beta_1x_i])^2}{2\sigma^2}\right)\]
6
\[\ell=\log L=\log\left[(2\pi\sigma^2)^{-n/2}\right]+\log\left[\exp\left(-\sum_{i=1}^n\frac{(y_i-[\beta_0+\beta_1x_i])^2}{2\sigma^2}\right)\right]\]
7
\[=-\frac n2\log(2\pi\sigma^2)-\sum_{i=1}^n\frac{(y_i-[\beta_0+\beta_1x_i])^2}{2\sigma^2}\]
8
\[=-\frac n2\left[\log(2\pi)+\log(\sigma^2)\right]-\sum_{i=1}^n\frac{(y_i-[\beta_0+\beta_1x_i])^2}{2\sigma^2}\]
9
\[=-\frac n2\log(2\pi)-\frac n2\log(\sigma^2)-\sum_{i=1}^n\frac{(y_i-[\beta_0+\beta_1x_i])^2}{2\sigma^2}\]
10
\[=-\frac n2\log(2\pi)-\frac n2\log(\sigma^2)-\frac{1}{2\sigma^2}\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])^2\]

\(\frac{1}{2\sigma^2}\) moves out of the sum. Slides p.27. ∎

Only the third term contains \(\beta_0\) and \(\beta_1\). It is \(-\frac{1}{2\sigma^2}\) times the sum of squares.

04.2The three partial derivatives of \(\ell\) Slides p.28

What Slides p.28

Maximum Likelihood Estimation · Lecture 2 · p.28 \[\max\left[-\frac n2\log(2\pi)-\frac n2\log(\sigma^2)-\frac{1}{2\sigma^2}\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])^2\right]\] \[\frac{\partial\ell}{\partial\beta_0}=\frac{1}{\sigma^2}\left(\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])\right)\qquad(\star)\] \[\frac{\partial\ell}{\partial\beta_1}=\frac{1}{\sigma^2}\left(\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])x_i\right)\qquad(\star\star)\] \[\frac{\partial\ell}{\partial\sigma^2}=-\frac{n}{2\sigma^2}+\frac{1}{2(\sigma^2)^2}\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])^2\] Setting \((\star)\) and \((\star\star)\) to 0 and solving

\(\partial\ell/\partial\beta_0\) keeps \(\beta_1\) and \(\sigma^2\) constant.

\(\partial\ell/\partial\sigma^2\) treats \(\sigma^2\) as one variable, not \(\sigma\).

"max": find the parameter values that make the bracket largest. There, all partial derivatives are 0.

This unit uses only (⋆) and (⋆⋆). Unit 06 solves the third equation for \(\sigma^2\) (Slides p.34).

How Added

Calculate (⋆) and (⋆⋆) at given parameters
  1. Calculate each difference \(y_i-[\beta_0+\beta_1x_i]\).
  2. (⋆): add the differences. Divide by \(\sigma^2\).
  3. (⋆⋆): multiply each difference by its \(x_i\). Add. Divide by \(\sigma^2\).
  4. If both are 0, the point is a stationary point of \(\ell\). A stationary point is a point where the partial derivatives are 0.

Self-check: \(\sigma^2>0\). Only the sum in the bracket decides if (⋆) = 0.

Example · (⋆) and (⋆⋆) for the small data set Added

\(\sigma^2=1\). Line A: \(\beta_0=0.5,\ \beta_1=1.2\). Line B: \(\beta_0=0.5,\ \beta_1=1.4\).

1

Line A: differences How step 1

\[0.5+1.2\times1=1.7,\quad0.5+1.2\times2=2.9,\quad0.5+1.2\times3=4.1,\quad0.5+1.2\times4=5.3\]
\[2-1.7=0.3,\quad3-2.9=0.1,\quad5-4.1=0.9,\quad6-5.3=0.7\]
2

Line A: (⋆) and (⋆⋆) How steps 2–3

\[(\star)=\frac{0.3+0.1+0.9+0.7}{1}=2\]
\[(\star\star)=\frac{0.3\times1+0.1\times2+0.9\times3+0.7\times4}{1}=\frac{0.3+0.2+2.7+2.8}{1}=6\]

Not 0: line A is not the maximum.

3

Line B: differences How step 1

\[0.1,\quad-0.3,\quad0.3,\quad-0.1\]

Example 2, step 2.

4

Line B: (⋆) and (⋆⋆) How steps 2–4

\[(\star)=\frac{0.1-0.3+0.3-0.1}{1}=0\]
\[(\star\star)=\frac{0.1\times1-0.3\times2+0.3\times3-0.1\times4}{1}=\frac{0.1-0.6+0.9-0.4}{1}=0\]

Both 0: line B is a stationary point. ▲

Why · Derivation of the three partial derivatives Slides p.28

Chain rule: \(\frac{d}{du}g(h(u))=g'(h(u))\,h'(u)\).

(a) For \(\beta_0\):

1
\[\frac{\partial\ell}{\partial\beta_0}=\frac{\partial}{\partial\beta_0}\left[-\frac n2\log(2\pi)\right]+\frac{\partial}{\partial\beta_0}\left[-\frac n2\log(\sigma^2)\right]+\frac{\partial}{\partial\beta_0}\left[-\frac{1}{2\sigma^2}\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])^2\right]\]
2
\[=0+0-\frac{1}{2\sigma^2}\sum_{i=1}^n\frac{\partial}{\partial\beta_0}(y_i-[\beta_0+\beta_1x_i])^2\]
3
\[=-\frac{1}{2\sigma^2}\sum_{i=1}^n2(y_i-[\beta_0+\beta_1x_i])(-1)\]
4
\[=\frac{2}{2\sigma^2}\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])\]
5
\[=\frac{1}{\sigma^2}\left(\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])\right)\qquad(\star)\]

∎

(b) For \(\beta_1\):

1
\[\frac{\partial\ell}{\partial\beta_1}=0+0-\frac{1}{2\sigma^2}\sum_{i=1}^n\frac{\partial}{\partial\beta_1}(y_i-[\beta_0+\beta_1x_i])^2\]
2
\[=-\frac{1}{2\sigma^2}\sum_{i=1}^n2(y_i-[\beta_0+\beta_1x_i])(-x_i)\]
3
\[=\frac{2}{2\sigma^2}\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])x_i\]
4
\[=\frac{1}{\sigma^2}\left(\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])x_i\right)\qquad(\star\star)\]

∎

(c) For \(\sigma^2\), as one variable. Only the second and third terms contain \(\sigma^2\).

1
\[\frac{\partial\ell}{\partial\sigma^2}=0-\frac n2\cdot\frac{1}{\sigma^2}-\frac{\partial}{\partial\sigma^2}\left(\frac{1}{2\sigma^2}\right)\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])^2\]
2
\[=-\frac{n}{2\sigma^2}-\left(-\frac{1}{2(\sigma^2)^2}\right)\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])^2\]
3
\[\frac{\partial\ell}{\partial\sigma^2}=-\frac{n}{2\sigma^2}+\frac{1}{2(\sigma^2)^2}\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])^2\]

Slides p.28, third line. Unit 06 sets it to 0. ∎

(⋆) and (⋆⋆) both start with the positive constant \(1/\sigma^2\).

04.3MLE and LS give the same estimates (\(\hat\beta^{LS}=\hat\beta^{ML}\)) Slides p.29

What Slides p.29

Maximum Likelihood Estimation · Lecture 2 · p.29 Setting \((\star)\) and \((\star\star)\) to 0 and solving is equivalent to minimizing the sum of squares!
• That is \(\hat\beta_0^{LS}=\hat\beta_0^{ML}\) and \(\hat\beta_1^{LS}=\hat\beta_1^{ML}\)
• Here on out we will call the LS/MLE estimators \(\hat\beta\).

Equivalent: the two problems have the same solution.

\(\hat\beta\): from here, \(\hat\beta_0\) and \(\hat\beta_1\) are both the LS estimators and the MLE.

In \(\ell\), \(\beta_0\) and \(\beta_1\) occur only in \(-\frac{1}{2\sigma^2}S(\beta_0,\beta_1)\). This factor is negative. A smaller \(S\) gives a larger \(\ell\).

This answers Slides p.26: in the normal model, least squares gives the MLE.

How Added

Find the MLE of \(\beta_0\) and \(\beta_1\)
  1. Check the model: \(y_i\overset{indep}{\sim}N(\beta_0+\beta_1x_i,\sigma^2)\).
  2. Calculate \(\bar x\), \(\bar y\), \(S_{xx}\), and \(S_{xy}\).
  3. Calculate \(\hat\beta_1=S_{xy}/S_{xx}\).
  4. Calculate \(\hat\beta_0=\bar y-\hat\beta_1\bar x\).
  5. These are the MLE: \(\hat\beta_0^{ML}=\hat\beta_0^{LS}\) and \(\hat\beta_1^{ML}=\hat\beta_1^{LS}\).

Self-check: ① \(\sum(y_i-[\hat\beta_0+\hat\beta_1x_i])=0\): (⋆) = 0. ② \(\sum(y_i-[\hat\beta_0+\hat\beta_1x_i])x_i=0\): (⋆⋆) = 0. ③ \(\ell\) at \(\hat\beta\) is larger than at another line, for each \(\sigma^2\).

Example 3 · MLE for the small data set Added

1

Check the model How step 1

Use \(y_i\overset{indep}{\sim}N(\beta_0+\beta_1x_i,\sigma^2)\).

2

Means How step 2

\[\bar x=\frac{1+2+3+4}{4}=\frac{10}{4}=2.5,\qquad\bar y=\frac{2+3+5+6}{4}=\frac{16}{4}=4\]
3

\(S_{xx}\) and \(S_{xy}\) How step 2

\[x_i-\bar x:\ -1.5,\ -0.5,\ 0.5,\ 1.5\qquad y_i-\bar y:\ -2,\ -1,\ 1,\ 2\]
\[S_{xx}=(-1.5)^2+(-0.5)^2+0.5^2+1.5^2=2.25+0.25+0.25+2.25=5\]
\[S_{xy}=(-1.5)(-2)+(-0.5)(-1)+(0.5)(1)+(1.5)(2)=3+0.5+0.5+3=7\]
4

Estimates How steps 3–5

\[\hat\beta_1=\frac{S_{xy}}{S_{xx}}=\frac75=1.4\]
\[\hat\beta_0=\bar y-\hat\beta_1\bar x=4-1.4\times2.5=4-3.5=0.5\]
\[\hat\beta_0^{ML}=\hat\beta_0^{LS}=0.5,\qquad\hat\beta_1^{ML}=\hat\beta_1^{LS}=1.4\]
5

Self-checks ① and ② Section 04.2 example, step 4

Section 04.2: (⋆) = 0 and (⋆⋆) = 0 at \((0.5,1.4)\).

6

Self-check ③ with \(\sigma^2=1\) How steps 4–7 of Section 04.1

\[S(0.5,1.4)=0.2\quad\Rightarrow\quad\ell=-3.675754-0-\frac{0.2}{2}=-3.775754\]
\[S(0.5,1.2)=0.3^2+0.1^2+0.9^2+0.7^2=0.09+0.01+0.81+0.49=1.4\]
\[\ell(0.5,1.2,1\,|\,y)=-3.675754-0-\frac{1.4}{2}=-4.375754\]

\(-3.775754>-4.375754\): the LS line has the larger \(\ell\). ▲

02.55 −4−5−6 1.0 1.2 1.4 1.6 1.8 β₁ S(0.5, β₁): smaller is better ℓ(0.5, β₁, σ² = 1): larger is better β̂₁ = 1.4 line A

Figure 4-1 (Added) · Small data set, \(\beta_0\) fixed at \(\hat\beta_0=0.5\). Top (blue): \(S\), minimum \(S=0.2\) at \(\hat\beta_1=1.4\). Bottom (green): \(\ell\) with \(\sigma^2=1\), maximum \(\ell=-3.775754\) at the same \(\hat\beta_1=1.4\). Purple: line A (\(\beta_1=1.2\)), \(S=1.4\), \(\ell=-4.375754\).

The bottom curve is the top curve times \(-\frac12\), plus a constant.

Why · (⋆) = 0 and (⋆⋆) = 0 are the same as "minimize \(S\)" Slides p.29

(a) Objective functions:

1
\[\ell(\beta_0,\beta_1,\sigma^2|y)=-\frac n2\log(2\pi)-\frac n2\log(\sigma^2)-\frac{1}{2\sigma^2}\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])^2\]

Slides p.27.

2
\[=-\frac n2\log(2\pi)-\frac n2\log(\sigma^2)-\frac{1}{2\sigma^2}S(\beta_0,\beta_1)\]
3
\[=c-k\,S(\beta_0,\beta_1),\qquad c=-\frac n2\log(2\pi)-\frac n2\log(\sigma^2),\quad k=\frac{1}{2\sigma^2}>0\]

\(k>0\): the minimum of \(S\) is the maximum of \(\ell\). ∎

(b) Equations (Slides p.23, p.25):

1
\[\frac{\partial S}{\partial\beta_0}=\sum_{i=1}^n2(y_i-\beta_0-\beta_1x_i)(-1)=-2\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])\]

Slides p.23.

2
\[(\star)=\frac{1}{\sigma^2}\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])=-\frac{1}{2\sigma^2}\cdot\frac{\partial S}{\partial\beta_0}\]
3
\[\frac{\partial S}{\partial\beta_1}=\sum_{i=1}^n2(y_i-\beta_0-\beta_1x_i)(-x_i)=-2\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])x_i\]

Slides p.25.

4
\[(\star\star)=\frac{1}{\sigma^2}\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])x_i=-\frac{1}{2\sigma^2}\cdot\frac{\partial S}{\partial\beta_1}\]
5
\[(\star)=0\iff\frac{\partial S}{\partial\beta_0}=0,\qquad(\star\star)=0\iff\frac{\partial S}{\partial\beta_1}=0\]

\(-\frac{1}{2\sigma^2}\neq0\). Same solution: \(\hat\beta_0^{ML}=\bar y-\hat\beta_1\bar x=\hat\beta_0^{LS}\), \(\hat\beta_1^{ML}=S_{xy}/S_{xx}=\hat\beta_1^{LS}\). ∎

04.4Practice Added

Q1. Brainhead observation 2 has \(x_2=3738\) and \(y_2=1297\) (Slides p.10). Its fitted value is 1310.380 (Slides p.38). Use \(\sigma^2=5000\). Calculate (a) the normal density of \(y_2\), and (b) its contribution to \(\ell\).

Answer

(a) Fitted value: \(335.4323150+0.2608207\times3738=335.4323150+974.9478=1310.380\). Difference: \(1297-1310.380=-13.380\). Square: \((-13.380)^2=179.0244\).

Exponent: \(179.0244/(2\times5000)=0.01790244\). \(\exp(-0.01790244)=0.9822569\).

Constant: \(1/\sqrt{2\pi\times5000}=0.005641896\) (Example 1, step 2).

Density: \(0.005641896\times0.9822569=0.005541791\).

(b) Contribution: \(-\frac12\log(2\pi)-\frac12\log(\sigma^2)-\frac{(y_2-[\beta_0+\beta_1x_2])^2}{2\sigma^2}\):

\[-0.9189385-4.2585966-0.0179024=-5.1954375\]

Check: \(\log(0.005541791)=-5.195438\).

Q2. Start from \((\star)\). Show that \(\partial\ell/\partial\beta_0=0\) gives \(\hat\beta_0=\bar y-\hat\beta_1\bar x\).

Answer
1
\[0=\frac{1}{\sigma^2}\left(\sum_{i=1}^n(y_i-[\hat\beta_0+\hat\beta_1x_i])\right)\]

Set (⋆) = 0.

2
\[0=\sum_{i=1}^n(y_i-\hat\beta_0-\hat\beta_1x_i)\]
3
\[0=\sum_{i=1}^ny_i-n\hat\beta_0-\hat\beta_1\sum_{i=1}^nx_i\]
4
\[n\hat\beta_0=\sum_{i=1}^ny_i-\hat\beta_1\sum_{i=1}^nx_i\]
5
\[\hat\beta_0=\frac1n\sum_{i=1}^ny_i-\hat\beta_1\frac1n\sum_{i=1}^nx_i=\bar y-\hat\beta_1\bar x\]

The LS result on Slides p.23. ∎

Q3. True or false: under \(y_i\overset{indep}{\sim}N(\beta_0+\beta_1x_i,\sigma^2)\), the maximum likelihood estimates of \(\beta_0\) and \(\beta_1\) depend on \(\sigma^2\). Use the log-likelihood to justify your answer.

Answer

False.

\(\ell=-\frac n2\log(2\pi)-\frac n2\log(\sigma^2)-\frac{1}{2\sigma^2}S(\beta_0,\beta_1)\). For each fixed \(\sigma^2>0\), the first two terms do not contain \(\beta_0,\beta_1\), and \(-\frac{1}{2\sigma^2}\) is negative. The \(\beta_0,\beta_1\) that make \(\ell\) largest always make \(S\) smallest.

Small data set with \(\sigma^2=2\): \(-\frac42\log(2)=-2\times0.693147=-1.386294\).

At \((0.5,1.4)\): \(\ell=-3.675754-1.386294-\frac{0.2}{4}=-5.112048\).

At \((0.5,1.2)\): \(\ell=-3.675754-1.386294-\frac{1.4}{4}=-5.412048\).

The least squares line \((0.5,1.4)\) again has the larger \(\ell\).

Unit 05Fitted values and residuals

Plan · Slides p.30–32

Slides p.30: section page.

Slides p.31: fitted values \(\hat y_i\), residuals \(e_i\), errors \(\epsilon_i\).

Slides p.32: data, fitted line, and residuals in one figure.

Data for this unit · Added

Small data set: \(x=(1,2,3,4,5)\), \(y=(2,4,5,4,5)\), \(n=5\). Unit 03, Practice Q1: \(\hat\beta_0=2.2\), \(\hat\beta_1=0.6\).

Brainhead (236 observations), Slides p.38: \(\hat\beta_0=335.4323150\), \(\hat\beta_1=0.2608207\). Slides p.10: the first six pairs \((x_i,y_i)\).

05.1Section page Slides p.30

Slides p.30: section page "Fitted Values & Residuals" (Slides p.31–32).

05.2Fitted values Slides p.31

What Slides p.31

Fitted Values and Residuals · Lecture 2 · p.31 Define the fitted values: \[\hat y_i=\hat\beta_0+\hat\beta_1x_i\]
The fitted line \(\hat\beta_0+\hat\beta_1x\) is the least squares line.
The fitted value \(\hat y_i\) ("y hat i") is the height of the fitted line at \(x_i\).

How Added

Calculate the fitted value \(\hat y_i\)
  1. Calculate \(\hat\beta_0\) and \(\hat\beta_1\).
  2. Take \(x_i\). Do not use \(y_i\).
  3. Calculate \(\hat\beta_0+\hat\beta_1x_i\).

Self-check: \(\hat y_i\) has the unit of \(y\). \((x_i,\hat y_i)\) is on the fitted line.

Example 1 · The small data set Added

1
\(\hat\beta_0=2.2,\quad \hat\beta_1=0.6\)
Unit 03, Practice Q1
2
\(\hat\beta_1x_i:\ 0.6(1),\ 0.6(2),\ 0.6(3),\ 0.6(4),\ 0.6(5)=0.6,\ 1.2,\ 1.8,\ 2.4,\ 3.0\)
3
\(\hat y_i:\ 2.2+0.6,\ 2.2+1.2,\ 2.2+1.8,\ 2.2+2.4,\ 2.2+3.0\)
4
\(\hat y_i:\ 2.8,\ 3.4,\ 4.0,\ 4.6,\ 5.2\)

Example 2 · Observation 4 of the brainhead data Added

Slides p.10: \((x_4,y_4)=(3777,1282)\).

1
\(\hat\beta_0=335.4323150,\quad \hat\beta_1=0.2608207\)
Slides p.38
2
\(\hat\beta_1x_4=0.2608207\times3777=985.1198\)
3
\(\hat y_4=335.4323150+985.1198\)
4
\(\hat y_4=1320.5521\)
Check: \(\hat y_4=1320.552\) g is the fourth fitted value on Slides p.38.

Why Added

1
\(E[y_i|x_i]=\beta_0+\beta_1x_i\)
Section 02.5; \(E[\epsilon_i]=0\)
2
\(\hat\beta_0+\hat\beta_1x_i\)
replace \(\beta_0,\beta_1\) with the estimates
3
\(=\hat y_i\)
definition, Slides p.31

\(\hat y_i\) estimates the mean \(E[y_i|x_i]\).

05.3Residuals Slides p.31

What Slides p.31

Fitted Values and Residuals · Lecture 2 · p.31 Define the residuals: \[e_i=y_i-\hat y_i=y_i-(\hat\beta_0+\hat\beta_1x_i)\]
The residual \(e_i\) is the signed vertical distance from point \(i\) to the fitted line.
\(e_i>0\): the point is above the line. \(e_i<0\): the point is below the line.

How Added

Calculate the residual \(e_i\)
  1. Calculate \(\hat y_i\).
  2. Calculate \(e_i=y_i-\hat y_i\).
  3. Read the sign: plus is above the line, minus is below.

Self-check: \(\hat y_i+e_i=y_i\).

Example 1 · The small data set Added

1
\(e_i:\ 2-2.8,\ 4-3.4,\ 5-4.0,\ 4-4.6,\ 5-5.2\)
2
\(e_i:\ -0.8,\ 0.6,\ 1.0,\ -0.6,\ -0.2\)
Check: \(2.8+(-0.8)=2\), \(3.4+0.6=4\), \(4.0+1.0=5\), \(4.6+(-0.6)=4\), \(5.2+(-0.2)=5\).
Points 2 and 3 are above the fitted line. Points 1, 4, and 5 are below it.

Example 2 · Observations 4 and 5 of the brainhead data Added

1
\(e_4=y_4-\hat y_4=1282-1320.552\)
\(\hat y_4\) from Section 05.2, Example 2
2
\(e_4=-38.552\)
3
\(e_5=y_5-\hat y_5=1590-1424.880\)
\(y_5\): Slides p.10; \(\hat y_5\): Slides p.38
4
\(e_5=165.120\)
Person 4: 38.552 g below the fitted line.
Person 5: 165.120 g above the fitted line.
4000 4177 1300 1400 1500 1600 ŷ = β̂₀ + β̂₁x y₅ = 1590 ŷ₅ = 1424.880 e₅ = 165.120 head size x (cm³)brain weight y (g)
Figure 5-1 (Added) · Purple: \((x_5,y_5)=(4177,1590)\). Blue line: the fitted line. Open blue point: \(\hat y_5=1424.880\) at \(x_5=4177\). Orange: \(e_5=165.120\), positive.

Why Added

1
\(S(\beta_0,\beta_1)=\sum_{i=1}^n(y_i-\beta_0-\beta_1x_i)^2\)
Slides p.21
2
\(S(\hat\beta_0,\hat\beta_1)=\sum_{i=1}^n(y_i-\hat\beta_0-\hat\beta_1x_i)^2\)
substitute the estimates
3
\(=\sum_{i=1}^n\big(y_i-(\hat\beta_0+\hat\beta_1x_i)\big)^2\)
4
\(=\sum_{i=1}^n(y_i-\hat y_i)^2\)
definition of \(\hat y_i\)
5
\(=\sum_{i=1}^n e_i^2\)
definition of \(e_i\)

The least squares line has the smallest sum of squared residuals \(\sum e_i^2\).

05.4Residuals and errors Slides p.31

What Slides p.31

Fitted Values and Residuals · Lecture 2 · p.31 Note the residuals \(e_i\) are different from the errors: \(\epsilon_i=y_i-(\beta_0+\beta_1x_i)\)
The error \(\epsilon_i\) subtracts the true line \(\beta_0+\beta_1x_i\). We cannot observe it (Slides p.13).
The residual \(e_i\) subtracts the fitted line. It uses only data and estimates: we can calculate it.

We use \(e_i\) in place of \(\epsilon_i\).

How Added

Identify a residual or an error
  1. Look at the coefficients of the subtracted line.
  2. Hats (\(\hat\beta_0,\hat\beta_1\)): a residual \(e_i\).
  3. No hats (\(\beta_0,\beta_1\)): an error \(\epsilon_i\).
  4. For a number, calculate \(e_i\). \(\beta_0,\beta_1\) are unknown.

Self-check: A quantity with a numeric value is a residual.

Example · Observation 4 of the brainhead data Added

\((x_4,y_4)=(3777,1282)\), Slides p.10.

1
\(e_4=1282-(\hat\beta_0+\hat\beta_1\times3777)\)
How step 2: hats
2
\(e_4=1282-1320.552\)
Section 05.2, Example 2
3
\(e_4=-38.552\)
1
\(\epsilon_4=1282-(\beta_0+\beta_1\times3777)\)
How step 3: \(\beta_0,\beta_1\) unknown; the chain stops

Why Added

1
\(\epsilon_i-e_i=\big[y_i-(\beta_0+\beta_1x_i)\big]-\big[y_i-(\hat\beta_0+\hat\beta_1x_i)\big]\)
the two definitions, Slides p.31
2
\(=y_i-\beta_0-\beta_1x_i-y_i+\hat\beta_0+\hat\beta_1x_i\)
3
\(=-\beta_0-\beta_1x_i+\hat\beta_0+\hat\beta_1x_i\)
4
\(=(\hat\beta_0-\beta_0)+(\hat\beta_1-\beta_1)x_i\)

The difference comes only from \(\hat\beta_0-\beta_0\) and \(\hat\beta_1-\beta_1\). Both are unknown.

05.5A picture of the fitted values and residuals Slides p.32

Slides p.32 has only the title "Fitted Values and Residuals". Figure 5-2 is Added.

Gray points: observations 7 to 236.
Purple points 1–6: the six observations of Slides p.10.
Blue line: \(\hat\beta_0+\hat\beta_1x=335.4323150+0.2608207x\) (Slides p.38).
Open blue points: the fitted values \((x_i,\hat y_i)\).
Orange segments: the residuals \(e_i\), from \(\hat y_i\) to \(y_i\).
3000 3500 4000 4500 1000 1100 1200 1300 1400 1500 1600 head size xᵢ (cm³) brain weight yᵢ (g) 1 2 3 4 5 6
Figure 5-2 (Added) · Points 1, 5, and 6 are above the line: \(e_1,e_5,e_6\) are positive. Points 2, 3, and 4 are below: \(e_2,e_3,e_4\) are negative.

The fitted line makes \(\sum_{i=1}^{236}e_i^2\) as small as possible.

05.6Practice Added

Q1. Use \(\hat\beta_0=335.4323150\) and \(\hat\beta_1=0.2608207\) (Slides p.38). Observation 6 has \(x_6=3585\) and \(y_6=1300\) (Slides p.10). Calculate \(\hat y_6\) and \(e_6\). Is point 6 above or below the fitted line?

Answer
1
\(\hat y_6=335.4323150+0.2608207\times3585\)
2
\(\hat y_6=335.4323150+935.0422\)
3
\(\hat y_6=1270.4745\approx1270.475\)
sixth value on Slides p.38
4
\(e_6=1300-1270.475=29.525\)

\(e_6>0\): point 6 is above the fitted line.

Q2. The data are \((x_i,y_i)\): (1, 1), (2, 3), (3, 2). Calculate \(\hat\beta_0\), \(\hat\beta_1\), the three fitted values, and the three residuals.

Answer
Step 1: \(\bar x=6/3=2\) and \(\bar y=6/3=2\).
Step 2: \(x_i-\bar x=(-1,0,1)\) and \(y_i-\bar y=(-1,1,0)\).
Step 3: \(S_{xy}=(-1)(-1)+(0)(1)+(1)(0)=1\) and \(S_{xx}=1+0+1=2\).
Step 4: \(\hat\beta_1=1/2=0.5\) and \(\hat\beta_0=2-0.5\times2=1\).
Step 5: \(\hat y_i=1+0.5x_i\): 1.5, 2.0, 2.5.
Step 6: \(e_i=y_i-\hat y_i\): \(1-1.5=-0.5\), \(3-2.0=1.0\), \(2-2.5=-0.5\).

Point 2 is above the fitted line. Points 1 and 3 are below it.

Q3. Use the second line of Slides p.23, \(0=\sum_{i=1}^n(y_i-\hat\beta_0-\hat\beta_1x_i)\). Show that the residuals add to 0. Check the result with the small data set.

Answer
1
\(0=\sum_{i=1}^n(y_i-\hat\beta_0-\hat\beta_1x_i)\)
Slides p.23
2
\(0=\sum_{i=1}^n\big(y_i-(\hat\beta_0+\hat\beta_1x_i)\big)\)
3
\(0=\sum_{i=1}^n(y_i-\hat y_i)\)
definition of \(\hat y_i\)
4
\(0=\sum_{i=1}^n e_i\)
definition of \(e_i\)

Check: \(-0.8+0.6+1.0-0.6-0.2=0\).

Unit 06Estimating \(\sigma^2\): the MLE and the unbiased estimator

Plan · Slides p.33–38

Slides p.33: section page.

Slides p.34: solve \(\partial\ell/\partial\sigma^2=0\) for \(\hat\sigma^2_{ML}\).

Slides p.35: the course estimator \(\hat\sigma^2=\sum e_i^2/(n-2)\).

Slides p.36: \(\hat\sigma^2\) is unbiased (chi-squared result).

Slides p.37: calculate \(\hat\beta_0\), \(\hat\beta_1\), and \(\hat\sigma\) in order.

Slides p.38: brainhead estimates and fitted values.

Start point (results of Units 02–05) · Added

Model: \(y_i=\beta_0+\beta_1x_i+\epsilon_i\), with \(\epsilon_i\overset{iid}{\sim}N(0,\sigma^2)\). Same as \(y_i\overset{indep}{\sim}N(\beta_0+\beta_1x_i,\ \sigma^2)\).

The error variance \(\sigma^2=\mathrm{Var}[\epsilon_i]\) is the spread of the points around \(\beta_0+\beta_1x_i\). \(\sigma\) is the standard deviation of the errors, in the unit of \(y\).

\(\hat\beta_1=S_{xy}/S_{xx}\) and \(\hat\beta_0=\bar y-\hat\beta_1\bar x\). Least squares and maximum likelihood give the same values (Slides p.26–29).

\(\hat y_i=\hat\beta_0+\hat\beta_1x_i\) and \(e_i=y_i-\hat y_i\) (Slides p.31).

\(\sum e_i^2\) is the sum of squared residuals. \(\sum\) without limits means \(\sum_{i=1}^n\).

06.1Section page Slides p.33

Slides p.33: section page "Estimating \(\sigma^2\)" (Slides p.34–38).

\(\sigma^2\) is the last unknown parameter of the model.

06.2The maximum likelihood estimate of \(\sigma^2\) Slides p.34

What Slides p.34

Maximum Likelihood Estimation Continued · Lecture 2 · p.34 \[\frac{\partial\ell}{\partial\sigma^2}=0\] \[-\frac{n}{2\sigma^2}+\frac{1}{2(\sigma^2)^2}\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])^2=0\] \[\frac{\sum_{i=1}^n(y_i-[\hat\beta_0+\hat\beta_1x_i])^2}{n}=\hat\sigma^2_{ML}\] or equivalently \[\hat\sigma^2_{ML}=\frac{\sum_{i=1}^n e_i^2}{n}\]
The subscript \(ML\) marks a maximum likelihood estimate.

\(\hat\sigma^2_{ML}\) is the mean of the squared residuals.

How Added

Calculate \(\hat\sigma^2_{ML}\) from data
  1. Calculate \(\hat\beta_1=S_{xy}/S_{xx}\) and \(\hat\beta_0=\bar y-\hat\beta_1\bar x\).
  2. Calculate each fitted value \(\hat y_i=\hat\beta_0+\hat\beta_1x_i\).
  3. Calculate each residual \(e_i=y_i-\hat y_i\).
  4. Square each \(e_i\). Add the squares to get \(\sum e_i^2\).
  5. Divide by \(n\): \(\hat\sigma^2_{ML}=\sum e_i^2/n\).

Self-check: \(\hat\sigma^2_{ML}\ge0\). Its unit is the unit of \(y\), squared. The residuals add to 0. If not, an estimate \(\hat\beta\) is wrong.

Example · The small data set of Unit 05 Added

\(x=(1,2,3,4,5)\), \(y=(2,4,5,4,5)\), \(n=5\).

Step 1: \(\hat\beta_0=2.2\) and \(\hat\beta_1=0.6\) (Unit 03, Practice Q1).
Step 2: fitted values 2.8, 3.4, 4.0, 4.6, 5.2 (Section 05.2, Example 1).
Step 3: residuals \(-0.8,\ 0.6,\ 1.0,\ -0.6,\ -0.2\) (Section 05.3, Example 1).
Step 4: squares 0.64, 0.36, 1.00, 0.36, 0.04. \(\sum e_i^2=0.64+0.36+1.00+0.36+0.04=2.4\).
Step 5: \(\hat\sigma^2_{ML}=2.4/5=0.48\). \(\hat\sigma_{ML}=\sqrt{0.48}=0.693\).
Check: \(-0.8+0.6+1.0-0.6-0.2=0\).

Residuals at their \(x\) positions Added. An estimate of \(\sigma\) measures their usual distance from \(e=0\).

1 2 3 4 5 −1 0 1 −0.8 0.6 1.0 −0.6 −0.2 +0.894 −0.894 e = 0 covariate x residual e
Figure 6-1 (Added) · Orange: the five residuals \(e_i\). Blue: \(e=0\). Green band: \(\pm\hat\sigma=\pm0.894\) (Section 06.3). Four of the five residuals are in the band.

Why Slides p.34

1
\[\ell(\beta_0,\beta_1,\sigma^2|y)=-\frac n2\log(2\pi)-\frac n2\log(\sigma^2)-\frac{1}{2\sigma^2}\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])^2\]
log-likelihood, Slides p.27
2
\[\frac{\partial\ell}{\partial\sigma^2}=-\frac{n}{2\sigma^2}+\frac{1}{2(\sigma^2)^2}\sum_{i=1}^n(y_i-[\beta_0+\beta_1x_i])^2\]
Section 04.2 (c); Slides p.28, third line
3
\[-\frac{n}{2\hat\sigma^2_{ML}}+\frac{1}{2(\hat\sigma^2_{ML})^2}\sum_{i=1}^n(y_i-[\hat\beta_0+\hat\beta_1x_i])^2=0\]
set to 0 (Slides p.34); \(\hat\beta_0,\hat\beta_1\) from Slides p.29
4
\[-n\hat\sigma^2_{ML}+\sum_{i=1}^n(y_i-[\hat\beta_0+\hat\beta_1x_i])^2=0\]
5
\[n\hat\sigma^2_{ML}=\sum_{i=1}^n(y_i-[\hat\beta_0+\hat\beta_1x_i])^2\]
6
\[\hat\sigma^2_{ML}=\frac{\sum_{i=1}^n(y_i-[\hat\beta_0+\hat\beta_1x_i])^2}{n}\]
Slides p.34, third line
7
\[\hat\sigma^2_{ML}=\frac{\sum_{i=1}^n e_i^2}{n}\]
substitute \(e_i=y_i-(\hat\beta_0+\hat\beta_1x_i)\); Slides p.34, last line ∎

06.3The estimator \(\hat\sigma^2\) that the course uses Slides p.35

What Slides p.35

Maximum Likelihood Estimation Continued · Lecture 2 · p.35 However we typically adopt a different estimator: \[\hat\sigma^2=\frac{\sum_{i=1}^n e_i^2}{n-2}\qquad\text{Why?}\]

Only the denominator changes: \(n-2\), not \(n\).

From here, \(\hat\sigma^2\) (no subscript) always means this estimator. \(\hat\sigma=\sqrt{\hat\sigma^2}\) estimates \(\sigma\). Slides p.36 answers "Why?".

How Added

Calculate \(\hat\sigma^2\) and \(\hat\sigma\) from data
  1. Do steps 1–4 of Section 06.2 to get \(\sum e_i^2\).
  2. Calculate \(n-2\).
  3. Divide: \(\hat\sigma^2=\sum e_i^2/(n-2)\).
  4. Take the square root: \(\hat\sigma=\sqrt{\hat\sigma^2}\).

Self-check: \(\hat\sigma^2\) is larger than \(\hat\sigma^2_{ML}\). The ratio \(\hat\sigma^2/\hat\sigma^2_{ML}\) is exactly \(n/(n-2)\).

Example · The same small data set Added

Section 06.2: \(\sum e_i^2=2.4\), \(n=5\).

Step 2: \(n-2=5-2=3\).
Step 3: \(\hat\sigma^2=2.4/3=0.8\).
Step 4: \(\hat\sigma=\sqrt{0.8}=0.894\).
Check: \(\hat\sigma^2/\hat\sigma^2_{ML}=0.8/0.48=1.667\) and \(n/(n-2)=5/3=1.667\).

06.4The unbiased estimator Slides p.36

The slide gives only the intuition. It uses a chi-squared result without proof.

What Slides p.36

Unbiased Estimator · Lecture 2 · p.36 Why do we use this \(\hat\sigma^2\) instead of \(\hat\sigma^2_{ML}\)? \[E\left[\frac{\sum_{i=1}^n e_i^2}{n-2}\right]=\sigma^2\] Intuition: \[\frac{1}{\sigma^2}\sum_{i=1}^n e_i^2\sim\chi^2_{(n-2)}\quad\text{and}\quad E[\chi^2_\nu]=\nu\] \[\Longrightarrow E\left[\frac{\sum_{i=1}^n e_i^2}{n-2}\right]=\sigma^2E\left[\frac{1}{\sigma^2}\frac{\sum_{i=1}^n e_i^2}{n-2}\right]=\frac{\sigma^2}{(n-2)}E\left[\frac{1}{\sigma^2}\sum_{i=1}^n e_i^2\right]=\sigma^2\] Often doesn't matter when \(n\ge50\)
An estimator is unbiased when its expectation equals the parameter: \(E[\hat\sigma^2]=\sigma^2\).
In words: over many new data sets, the mean of the \(\hat\sigma^2\) values is \(\sigma^2\).
The chi-squared distribution \(\chi^2_\nu\) has only positive values. Lecture 1 p.26: if \(Z_1,\dots,Z_\nu\overset{iid}{\sim}N(0,1)\), then \(\sum Z_i^2\sim\chi^2_\nu\), and \(E[\chi^2_\nu]=\nu\).
The degrees of freedom \(\nu\) is the parameter of \(\chi^2_\nu\). Here \(\nu=n-2\).
\(\sim\): "has the distribution".

\(\frac{1}{\sigma^2}\sum e_i^2\) has mean \(n-2\). The division by \(n-2\) cancels it. For \(n\ge50\), \(n\) and \(n-2\) are almost equal, and the choice seldom changes a conclusion.

The \(\chi^2_3\) density and its mean Added:

0 2 4 6 8 10 12 0.0 0.1 0.2 mean = ν = 3 density of χ² with ν = 3 value
Figure 6-2 (Added) · Blue: the \(\chi^2_3\) density, above 0 only for positive values. Purple dashed: the mean \(E[\chi^2_3]=3\).

The right tail is long, but the mean is exactly the degrees of freedom.

How Added

Find if an estimator of \(\sigma^2\) is unbiased, and if the denominator is important
  1. Write the estimator as \(c\cdot\sum e_i^2\). Find \(c\).
  2. Use \(E\left[\frac{1}{\sigma^2}\sum e_i^2\right]=n-2\). This gives \(E\left[\sum e_i^2\right]=(n-2)\sigma^2\).
  3. Calculate \(E[c\sum e_i^2]=c(n-2)\sigma^2\).
  4. If \(c(n-2)=1\), the estimator is unbiased.
  5. If \(n\ge50\), \(n/(n-2)\) is near 1. The difference is usually small.

Self-check: Only \(c=1/(n-2)\) gives \(c(n-2)=1\).

Example · Two sample sizes Added

The small data set (\(n=5\)) and \(n=50\).

Step 1: for \(\hat\sigma^2\), \(c=1/(n-2)\). For \(\hat\sigma^2_{ML}\), \(c=1/n\).
Steps 2–3 with \(n=5\): \(E[\hat\sigma^2]=\frac13\cdot3\sigma^2=\sigma^2\). \(E[\hat\sigma^2_{ML}]=\frac15\cdot3\sigma^2=0.6\sigma^2\).
Step 4: \(\hat\sigma^2\) is unbiased. With \(n=5\), \(\hat\sigma^2_{ML}\) is 40% too low on average.
Step 5 with \(n=50\): \(E[\hat\sigma^2_{ML}]=\frac{1}{50}\cdot48\sigma^2=0.96\sigma^2\). The ratio \(n/(n-2)=50/48=1.042\): only 4%.

Why Slides p.36

The only input without proof is \(\frac{1}{\sigma^2}\sum e_i^2\sim\chi^2_{(n-2)}\).

1
\[E\left[\frac{\sum_{i=1}^n e_i^2}{n-2}\right]\]
2
\[=E\left[\sigma^2\cdot\frac{1}{\sigma^2}\frac{\sum_{i=1}^n e_i^2}{n-2}\right]\]
\(\sigma^2\cdot\frac{1}{\sigma^2}=1\)
3
\[=\sigma^2E\left[\frac{1}{\sigma^2}\frac{\sum_{i=1}^n e_i^2}{n-2}\right]\]
linearity of \(E\); \(\sigma^2\) is a constant
4
\[=\frac{\sigma^2}{(n-2)}E\left[\frac{1}{\sigma^2}\sum_{i=1}^n e_i^2\right]\]
linearity of \(E\); \(\frac{1}{n-2}\) is a constant
5
\[=\frac{\sigma^2}{(n-2)}\cdot(n-2)\]
\(\frac{1}{\sigma^2}\sum e_i^2\sim\chi^2_{(n-2)}\) and \(E[\chi^2_\nu]=\nu\)
6
\[=\sigma^2\]
∎

06.5Data example: all three estimates in order Slides p.37

Slides p.37 shows this order as code. Only the statistical steps are here.

What Slides p.37

Data Example · Lecture 2 · p.37 (statistical content of the slide) Prepare \(\bar x\), \(\bar y\), \(S_{xy}=\sum(y_i-\bar y)(x_i-\bar x)\), \(S_{xx}=\sum(x_i-\bar x)^2\), and \(n\) (number of observations).
\(\beta_1\) estimate (MLE): \(\hat\beta_1=S_{xy}/S_{xx}\).
\(\beta_0\) estimate (MLE): \(\hat\beta_0=\bar y-\hat\beta_1\bar x\).
Fitted values: \(\hat y_i=\hat\beta_0+\hat\beta_1x_i\). Residuals: \(e_i=y_i-\hat y_i\).
\(\sigma\) (unbiased estimate): \(\hat\sigma=\sqrt{\sum e_i^2/(n-2)}\).
A slide note gives a second way to get \(\hat\beta_1\). Divide the sample covariance of \(y\) and \(x\) by the sample variance of \(x\). The \(n-1\) cancels, giving \(S_{xy}/S_{xx}\).
\(\hat\sigma\) is the square root of \(\hat\sigma^2\), not of \(\hat\sigma^2_{ML}\).

How Added

Get the three point estimates \(\hat\beta_0\), \(\hat\beta_1\), \(\hat\sigma\)
  1. Calculate \(\bar x\), \(\bar y\), and \(n\).
  2. Calculate \(S_{xy}\) and \(S_{xx}\).
  3. Calculate \(\hat\beta_1=S_{xy}/S_{xx}\).
  4. Calculate \(\hat\beta_0=\bar y-\hat\beta_1\bar x\).
  5. Calculate each fitted value \(\hat y_i\) and each residual \(e_i\).
  6. Calculate \(\hat\sigma=\sqrt{\sum e_i^2/(n-2)}\).

Self-check: The residuals add to 0. \(\hat\beta_0+\hat\beta_1\bar x=\bar y\).

Example · A data set with six points Added

\(x=(1,2,3,4,5,6)\), \(y=(3,5,4,8,7,9)\).

Step 1: \(n=6\). \(\bar x=21/6=3.5\). \(\bar y=36/6=6\).
Step 2: \(x_i-\bar x=(-2.5,-1.5,-0.5,0.5,1.5,2.5)\). \(y_i-\bar y=(-3,-1,-2,2,1,3)\).
Step 2: \(S_{xy}=7.5+1.5+1+1+1.5+7.5=20\). \(S_{xx}=6.25+2.25+0.25+0.25+2.25+6.25=17.5\).
Step 3: \(\hat\beta_1=20/17.5=1.1429\) (exactly \(8/7\)).
Step 4: \(\hat\beta_0=6-\frac87\times3.5=6-4=2\).
Step 5: \(\hat y_i=2+\frac87x_i\): 3.143, 4.286, 5.429, 6.571, 7.714, 8.857.
Step 5: \(e_i=y_i-\hat y_i\): \(-0.143,\ 0.714,\ -1.429,\ 1.429,\ -0.714,\ 0.143\).
Step 6: \(\sum e_i^2=0.0204+0.5102+2.0408+2.0408+0.5102+0.0204=5.1429\).
Step 6: \(\hat\sigma^2=5.1429/(6-2)=5.1429/4=1.2857\). \(\hat\sigma=\sqrt{1.2857}=1.134\).
Check: the residuals add to 0. \(2+\frac87\times3.5=2+4=6=\bar y\).

06.6Estimates and fitted values for the brainhead data Slides p.38

What Slides p.38

Data Example · Lecture 2 · p.38 (statistical results printed on the slide) Regression coefficients: \(\hat\beta_0=335.4323150\) (intercept), \(\hat\beta_1=0.2608207\).
Fitted values of observations 1–6: 1512.255, 1310.380, 1446.789, 1320.552, 1424.880, 1270.475.
Intercept: \(\hat\beta_0=335.4323\) g is the estimated mean of \(y\) at \(x=0\).
Slope: one more cm³ of head size gives an estimated mean brain weight 0.2608 g larger.

How Added

Check a fitted value and find its residual
  1. Find \(x_i\) and \(y_i\) on Slides p.10.
  2. Calculate \(\hat\beta_1x_i\).
  3. Add \(\hat\beta_0\) to get \(\hat y_i\).
  4. Compare \(\hat y_i\) with Slides p.38.
  5. Calculate \(e_i=y_i-\hat y_i\).

Self-check: \(\hat y_i\), rounded to 3 decimals, equals the value on Slides p.38.

Example · Observations 3 and 5 Added

Slides p.10: \((x_3,y_3)=(4261,1335)\) and \((x_5,y_5)=(4177,1590)\).

Observation 3, Step 2: \(\hat\beta_1x_3=0.2608207\times4261=1111.3570\).
Observation 3, Step 3: \(\hat y_3=335.4323150+1111.3570=1446.7893\).
Observation 3, Step 4: 1446.789, the third value on Slides p.38.
Observation 3, Step 5: \(e_3=1335-1446.789=-111.789\) g, below the fitted line.
Observation 5, Step 2: \(\hat\beta_1x_5=0.2608207\times4177=1089.4481\).
Observation 5, Step 3: \(\hat y_5=335.4323150+1089.4481=1424.8804\). Rounded: 1424.880, the fifth value on Slides p.38.
Observation 5, Step 5: \(e_5=1590-1424.880=165.120\) g, above the fitted line.

For \(\hat\sigma\) of these data, use all 236 residuals (Section 06.5, step 6).

Summary of this unit

\(\hat\sigma^2_{ML}=\sum e_i^2/n\). The course uses the unbiased \(\hat\sigma^2=\sum e_i^2/(n-2)\). Lecture 3 uses \(\hat\sigma\) in confidence intervals and tests.

06.7Practice Added

Q1. Data: \(x=(0,1,2,3)\) and \(y=(1,3,2,6)\). Calculate \(\hat\beta_0\), \(\hat\beta_1\), the residuals, \(\hat\sigma^2_{ML}\), \(\hat\sigma^2\), and \(\hat\sigma\).

Answer
Step 1: \(n=4\). \(\bar x=6/4=1.5\). \(\bar y=12/4=3\).
Step 2: \(x_i-\bar x=(-1.5,-0.5,0.5,1.5)\). \(y_i-\bar y=(-2,0,-1,3)\).
Step 2: \(S_{xy}=3+0-0.5+4.5=7\). \(S_{xx}=2.25+0.25+0.25+2.25=5\).
Step 3: \(\hat\beta_1=7/5=1.4\).
Step 4: \(\hat\beta_0=3-1.4\times1.5=3-2.1=0.9\).
Step 5: \(\hat y_i=0.9+1.4x_i\): 0.9, 2.3, 3.7, 5.1. Residuals: \(0.1,\ 0.7,\ -1.7,\ 0.9\). Sum: 0.
Step 6: \(\sum e_i^2=0.01+0.49+2.89+0.81=4.2\).
\(\hat\sigma^2_{ML}=4.2/4=1.05\).
\(\hat\sigma^2=4.2/(4-2)=4.2/2=2.1\). \(\hat\sigma=\sqrt{2.1}=1.449\).

\(n/(n-2)=4/2=2\): the unbiased estimate is two times the MLE.

Q2. Use \(\frac{1}{\sigma^2}\sum_{i=1}^n e_i^2\sim\chi^2_{(n-2)}\) to find \(E[\hat\sigma^2_{ML}]\). Is \(\hat\sigma^2_{ML}\) unbiased? Give the factor for \(n=5\) and for \(n=50\).

Answer
1
\[E[\hat\sigma^2_{ML}]=E\left[\frac{\sum_{i=1}^n e_i^2}{n}\right]\]
2
\[=\frac{\sigma^2}{n}E\left[\frac{1}{\sigma^2}\sum_{i=1}^n e_i^2\right]\]
linearity of \(E\)
3
\[=\frac{\sigma^2}{n}(n-2)\]
\(E[\chi^2_{(n-2)}]=n-2\)
4
\[=\frac{n-2}{n}\sigma^2\]
∎

The factor \(\frac{n-2}{n}\) is less than 1. \(E[\hat\sigma^2_{ML}]\ne\sigma^2\): \(\hat\sigma^2_{ML}\) is not unbiased. On average it is too low. For \(n=5\), the factor is \(3/5=0.6\). For \(n=50\), it is \(48/50=0.96\).

Q3. Use the six fitted values on Slides p.38 and the six values \(y_i\) on Slides p.10. Calculate \(e_1,\dots,e_6\) and their sum. Can you use these six residuals to calculate \(\hat\sigma\) for the brainhead data?

Answer
Step 1: \(e_1=1530-1512.255=17.745\), \(e_2=1297-1310.380=-13.380\), \(e_3=1335-1446.789=-111.789\).
Step 2: \(e_4=1282-1320.552=-38.552\), \(e_5=1590-1424.880=165.120\), \(e_6=1300-1270.475=29.525\).
Step 3: \(17.745-13.380-111.789-38.552+165.120+29.525=48.669\).

The sum is not 0. \(\sum e_i=0\) holds for all \(n=236\) residuals together, not for six.

No. \(\hat\sigma=\sqrt{\sum e_i^2/(n-2)}\) needs all 236 residuals, with \(n-2=234\). The slides do not print the other 230.