Lecture 6
Multiple Linear Regression: Intro and Estimation
This lecture writes multiple linear regression in matrix form, estimates \(\boldsymbol\beta\) and \(\sigma^2\), and finds the properties of the estimators (Lecture 6 · p.1–41).
Unit 01Recap: matrix calculus, random vectors, and the multivariate normal
Step 1: Take the derivative of a scalar with respect to a vector (Slides p.3).
Step 2: Find the expectation and variance of a random vector after a linear change (Slides p.4).
Step 3: Define the multivariate normal distribution (Slides p.5).
Step 4: Use four properties of the multivariate normal (Slides p.6).
Step 5: Write the regression model as \(\boldsymbol{y}=\boldsymbol{X}\boldsymbol\beta+\boldsymbol\epsilon\) (Slides p.7).
The slides give no data. The examples use small 2×2 or 3×3 matrices.
01.1Notation Slides p.1–2
Slide p.1: title "Lecture 6: Multiple Linear Regression: Intro & Estimation". Slide p.2: section page "Recap". Added
01.2Matrix calculus Slides p.3
What Slides p.3
A partial derivative \(\partial z/\partial y_j\) is the rate of change of \(z\) when only \(y_j\) changes. A symmetric matrix has \(\boldsymbol{A}^T=\boldsymbol{A}\), that is, \(a_{ij}=a_{ji}\).
- If \(z=\boldsymbol{a}^T\boldsymbol{y}\), where \(\boldsymbol{a}=(a_1,\dots,a_k)^T\) is a vector, then \(\frac{\partial z}{\partial \boldsymbol{y}}=\boldsymbol{a}\)
- If \(z=\boldsymbol{y}^T\boldsymbol{A}\boldsymbol{y}\) where \(\boldsymbol{A}\) is a \(k\times k\) matrix, then \(\frac{\partial z}{\partial \boldsymbol{y}}=\boldsymbol{A}\boldsymbol{y}+\boldsymbol{A}^T\boldsymbol{y}\)
and if \(\boldsymbol{A}\) is symmetric, then: \(\frac{\partial z}{\partial \boldsymbol{y}}=2\boldsymbol{A}\boldsymbol{y}\)
Linear form \(\boldsymbol{a}^T\boldsymbol{y}=a_1y_1+\dots+a_ky_k\): each term is a constant times one entry. Quadratic form \(\boldsymbol{y}^T\boldsymbol{A}\boldsymbol{y}\): each term is a constant times two entries.
How Added
- Find the type of \(z\): linear form or quadratic form.
- For a linear form, write \(\partial z/\partial\boldsymbol{y}=\boldsymbol{a}\).
- For a quadratic form, compare each \(a_{ij}\) with \(a_{ji}\). All equal: write \(2\boldsymbol{A}\boldsymbol{y}\). Else: write \(\boldsymbol{A}\boldsymbol{y}+\boldsymbol{A}^T\boldsymbol{y}\).
- Write the result as a \(k\times1\) column.
Self-check: The result has length \(k\).
Self-check: Expand \(z\) and find each \(\partial z/\partial y_j\). The result must agree with step 2 or 3.
Example Added
Let \(k=2\), \(\boldsymbol{y}=(y_1,y_2)^T\), and use the point \(\boldsymbol{y}=(1,2)^T\).
Example (i): linear form, \(\boldsymbol{a}=(3,5)^T\).
Expand \(z\) How step 1
Partial derivatives Self-check 2
Column How step 2
Example (ii): symmetric quadratic form, \(\boldsymbol{A}=\left[\begin{array}{cc}2&1\\1&3\end{array}\right]\), \(a_{12}=a_{21}=1\).
Expand \(z\) How step 1
Partial derivatives Self-check 2
Rule \(2\boldsymbol{A}\boldsymbol{y}\) How step 3
Agrees with step 2.
Put in \(\boldsymbol{y}=(1,2)^T\)
Example (iii): non-symmetric quadratic form, \(\boldsymbol{A}=\left[\begin{array}{cc}1&2\\0&3\end{array}\right]\), \(a_{12}=2\ne a_{21}=0\).
Expand \(z\) How step 1
Partial derivatives Self-check 2
Rule \(\boldsymbol{A}\boldsymbol{y}+\boldsymbol{A}^T\boldsymbol{y}\) How step 3
\(\boldsymbol{A}^T=\left[\begin{array}{cc}1&0\\2&3\end{array}\right]\). Agrees with step 2.
Put in \(\boldsymbol{y}=(1,2)^T\)
Why Added
Linear form:
Only term \(i=j\) contains \(y_j\).
Definition on p.3. ∎
Quadratic form. \(a_{ij}\) is the entry of \(\boldsymbol{A}\) in row \(i\), column \(j\).
Product rule: \(y_j\) is in terms \(i=j\) and \(l=j\).
First sum: row \(j\) of \(\boldsymbol{A}\) times \(\boldsymbol{y}\).
\(a_{ij}\) is entry \((j,i)\) of \(\boldsymbol{A}^T\).
Symmetric: \(\boldsymbol{A}^T=\boldsymbol{A}\). ∎
Unit 03 uses these rules on \(S(\boldsymbol\beta)\).
01.3Properties of random vectors Slides p.4
What Slides p.4
A random variable is a number whose value comes from a random result. A random vector has random variables as entries. The expectation \(E[\cdot]\) is the long-run average, taken entry by entry for a vector.
The variance of a random variable is its expected squared distance from its expectation. The covariance \(\mathrm{cov}(y_i,y_j)=E[(y_i-E[y_i])(y_j-E[y_j])]\) shows how much two variables change together. The covariance matrix \(\mathrm{Var}(\boldsymbol{y})\) has entry \((i,j)\) equal to \(\mathrm{cov}(y_i,y_j)\), and variances on the diagonal. Below, \(\boldsymbol{a}\), \(\boldsymbol{b}\), and \(\boldsymbol{A}\) are constants.
- \(E[\boldsymbol{a}]=\boldsymbol{a}\)
- \(E[\boldsymbol{a}^T\boldsymbol{y}+\boldsymbol{b}]=\boldsymbol{a}^TE[\boldsymbol{y}]+\boldsymbol{b}\)
- \(E[\boldsymbol{A}\boldsymbol{y}]=\boldsymbol{A}E[\boldsymbol{y}]\)
- \(\mathrm{Var}(\boldsymbol{y})=E[(\boldsymbol{y}-E[\boldsymbol{y}])(\boldsymbol{y}-E[\boldsymbol{y}])^T]\)
- \(\mathrm{Var}(\boldsymbol{a}^T\boldsymbol{y})=\boldsymbol{a}^T\mathrm{Var}(\boldsymbol{y})\boldsymbol{a}\)
- \(\mathrm{Var}(\boldsymbol{A}\boldsymbol{y})=\boldsymbol{A}\mathrm{Var}(\boldsymbol{y})\boldsymbol{A}^T\)
For the variance, \(\boldsymbol{A}\) goes on the left and \(\boldsymbol{A}^T\) on the right. \(\mathrm{Var}(\boldsymbol{a}^T\boldsymbol{y})\) is a scalar. \(\mathrm{Var}(\boldsymbol{A}\boldsymbol{y})\) is a matrix.
How Added
- Write \(\boldsymbol{A}\) (\(m\times k\)), \(E[\boldsymbol{y}]\) (\(k\times1\)), and \(\mathrm{Var}(\boldsymbol{y})\) (\(k\times k\)).
- Calculate \(\boldsymbol{A}E[\boldsymbol{y}]\) (\(m\times1\)).
- Calculate \(\boldsymbol{A}\mathrm{Var}(\boldsymbol{y})\), then multiply on the right by \(\boldsymbol{A}^T\) (\(m\times m\)).
Self-check: The variance matrix is symmetric.
Self-check: The diagonal entries are \(\ge 0\).
Example Added
Let \(E[\boldsymbol{y}]=(10,20)^T\), \(\mathrm{Var}(\boldsymbol{y})=\boldsymbol{I}\) (2×2), \(\boldsymbol{A}=\left[\begin{array}{cc}1&2\\3&4\end{array}\right]\), and \(\boldsymbol{a}=(1,1)^T\).
Expectation How step 2
Variance How step 3
Symmetric, positive diagonal: both self-checks pass.
Scalar case
\(\boldsymbol{a}^T\boldsymbol{y}=y_1+y_2\).
Order is important: \(\boldsymbol{A}^T\boldsymbol{A}=\left[\begin{array}{cc}10&14\\14&20\end{array}\right]\) is a different matrix.
Why Added
Definition of Var, p.4.
\(E[\boldsymbol{A}\boldsymbol{y}]=\boldsymbol{A}E[\boldsymbol{y}]\).
\((\boldsymbol{B}\boldsymbol{C})^T=\boldsymbol{C}^T\boldsymbol{B}^T\).
Constant matrices move out of \(E\).
One row \(\boldsymbol{a}^T\) gives the scalar rule. ∎
Unit 04 uses this rule to find \(\mathrm{Var}[\hat{\boldsymbol\beta}]\).
01.4Multivariate normal distribution Slides p.5
What Slides p.5
\(N(0,1)\) is the standard normal: mean 0, variance 1. "i.i.d." means independent and identically distributed. Two variables are independent if the value of one does not change the distribution of the other. The multivariate normal (MVN) is a distribution of a random vector, set fully by its mean \(\boldsymbol\mu\) and covariance matrix \(\boldsymbol\Sigma\).
The integral of the density \(f(\boldsymbol{y})\) over a region gives the probability that \(\boldsymbol{y}\) is in that region. The determinant \(|\boldsymbol\Sigma|\) is one number from a square matrix; for 2×2, \(\left|\begin{array}{cc}p&q\\r&s\end{array}\right|=ps-qr\). The inverse \(\boldsymbol\Sigma^{-1}\) satisfies \(\boldsymbol\Sigma\boldsymbol\Sigma^{-1}=\boldsymbol{I}\).
Then \(\boldsymbol{y}=\boldsymbol{A}\boldsymbol{z}+\boldsymbol\mu\) has multivariate normal distribution, i.e.: \(\boldsymbol{y}\sim MVN(\boldsymbol\mu,\boldsymbol\Sigma)\) where \(E[\boldsymbol{y}]=\boldsymbol\mu\) and \(\mathrm{Var}(\boldsymbol{y})=\boldsymbol\Sigma=\boldsymbol{A}\boldsymbol{A}^T\).
\(\boldsymbol{y}\sim MVN(\boldsymbol\mu,\boldsymbol\Sigma)\), if: \[f(\boldsymbol{y})=\frac{1}{(2\pi)^{\frac n2}|\boldsymbol\Sigma|^{\frac12}}\exp\left\{-\frac12(\boldsymbol{y}-\boldsymbol\mu)^T\boldsymbol\Sigma^{-1}(\boldsymbol{y}-\boldsymbol\mu)\right\}\]
The slide gives two equivalent descriptions: a construction from \(n\) independent standard normals, and a density. Both use only \(\boldsymbol\mu\) (\(n\times1\)) and \(\boldsymbol\Sigma\) (\(n\times n\)).
How Added
- Read \(\boldsymbol\mu\), the added constant vector.
- Calculate \(\boldsymbol\Sigma=\boldsymbol{A}\boldsymbol{A}^T\).
- Write \(\boldsymbol{y}\sim MVN(\boldsymbol\mu,\boldsymbol\Sigma)\).
- For \(f(\boldsymbol{y})\), calculate \(|\boldsymbol\Sigma|\), then \(\boldsymbol\Sigma^{-1}\), then \((\boldsymbol{y}-\boldsymbol\mu)^T\boldsymbol\Sigma^{-1}(\boldsymbol{y}-\boldsymbol\mu)\).
- Put these three values into the density formula.
Self-check: \(\boldsymbol\Sigma\) is symmetric and \(|\boldsymbol\Sigma|>0\). Else \(|\boldsymbol\Sigma|^{1/2}\) and \(\boldsymbol\Sigma^{-1}\) do not exist.
Self-check: At \(\boldsymbol{y}=\boldsymbol\mu\), the exponential term is \(e^0=1\).
Example Added
Use \(\boldsymbol{A}\) from Section 01.3, \(n=2\), \(\boldsymbol\mu=(10,20)^T\), and \(\boldsymbol{y}=\boldsymbol{A}\boldsymbol{z}+\boldsymbol\mu\).
Mean How step 1
Covariance matrix How step 2
Same product as Section 01.3.
Distribution How step 3
Determinant How step 4
Density at \(\boldsymbol{y}=\boldsymbol\mu\) Self-check 2
Second example: \(\boldsymbol\mu=\boldsymbol{0}\), \(\boldsymbol\Sigma=\boldsymbol{I}\) (2×2), \(\boldsymbol{y}=(1,-1)^T\). Added
Determinant and inverse How step 4
Quadratic form How step 4
Density How step 5
Check with two one-dimensional densities
\(N(0,1)\) density: \(\frac{1}{\sqrt{2\pi}}e^{-y^2/2}\).
The cloud centers near \(\boldsymbol\mu=(10,20)\). It slopes up-right because \(\mathrm{cov}(y_1,y_2)=11>0\). It is taller than wide because \(\mathrm{Var}(y_2)=25>\mathrm{Var}(y_1)=5\).
Figure 1-1. 300 simulated points \(\boldsymbol{y}=\boldsymbol{A}\boldsymbol{z}+\boldsymbol\mu\) with \(\boldsymbol{A}=\left[\begin{array}{cc}1&2\\3&4\end{array}\right]\) (blue). Orange cross: mean \(\boldsymbol\mu\).
Why Added
Each \(z_i\) has mean 0 and variance 1, and different \(z_i\) have covariance 0. Then \(E[\boldsymbol{z}]=\boldsymbol{0}\) and \(\mathrm{Var}(\boldsymbol{z})=\boldsymbol{I}\).
p.4 expectation rules.
An added constant does not change variance.
p.4 variance rule.
∎
01.5Properties of \(\boldsymbol{y}\sim MVN(\boldsymbol\mu,\boldsymbol\Sigma)\) Slides p.6
What Slides p.6
A marginal distribution is the distribution of some entries of a vector. A conditional distribution \(\boldsymbol{y}_1\mid\boldsymbol{y}_2\) is the distribution of \(\boldsymbol{y}_1\) when \(\boldsymbol{y}_2\) is known. \(\Sigma_{ij}=\mathrm{cov}(y_i,y_j)\) is entry \((i,j)\) of \(\boldsymbol\Sigma\).
Conditional Distribution: If \(\boldsymbol{y}=(\boldsymbol{y}_1^T,\boldsymbol{y}_2^T)^T\), then \(\boldsymbol{y}_1^T\mid\boldsymbol{y}_2^T\) is MVN-distributed.
Independence: If \(\Sigma_{ij}=0\), then \(\boldsymbol{y}_i\) and \(\boldsymbol{y}_j\) are independent.
How Added
A linear combination is a sum of entries, each multiplied by a constant.
- Write \(\boldsymbol{u}=\boldsymbol{C}\boldsymbol{y}+\boldsymbol{d}\). For a subset, each row of \(\boldsymbol{C}\) has one 1 and all other entries 0.
- Mean: calculate \(\boldsymbol{C}\boldsymbol\mu+\boldsymbol{d}\).
- Variance: calculate \(\boldsymbol{C}\boldsymbol\Sigma\boldsymbol{C}^T\).
- Write \(\boldsymbol{u}\sim MVN(\text{step 2},\text{step 3})\). For one entry, write \(N(\cdot,\cdot)\).
Self-check: Columns of \(\boldsymbol{C}\) = length of \(\boldsymbol{y}\). Length of \(\boldsymbol{d}\) = rows of \(\boldsymbol{C}\).
Example Added
Use \(\boldsymbol{y}\sim MVN\left(\left[\begin{array}{c}10\\20\end{array}\right],\left[\begin{array}{cc}5&11\\11&25\end{array}\right]\right)\) from Section 01.4.
(i) Linearity: \(u=y_1+y_2\).
Write \(u=\boldsymbol{C}\boldsymbol{y}+\boldsymbol{d}\) How step 1
Mean How step 2
Variance How step 3
Distribution How step 4
(ii) Marginal: \(\boldsymbol{C}=\left[\begin{array}{cc}1&0\end{array}\right]\), \(\boldsymbol{d}=0\). Mean \(1(10)+0(20)=10\), variance \(\Sigma_{11}=5\): \(y_1\sim N(10,5)\).
(iii) Independence: \(\boldsymbol\Sigma=\boldsymbol{I}\), \(\boldsymbol\mu=\boldsymbol{0}\), \(\Sigma_{12}=0\). The joint density is the product of two \(N(0,1)\) densities: both give 0.05854983 at \((1,-1)\) (Section 01.4).
Why Added
Let \(\boldsymbol{y}=\boldsymbol{A}\boldsymbol{z}+\boldsymbol\mu\), with \(\boldsymbol\Sigma=\boldsymbol{A}\boldsymbol{A}^T\).
p.5 construction.
Form "matrix × \(\boldsymbol{z}\) + vector": p.5 applies.
\((\boldsymbol{C}\boldsymbol{A})^T=\boldsymbol{A}^T\boldsymbol{C}^T\).
∎ Marginal: \(\boldsymbol{C}\) selects entries.
The lecture states the conditional and independence properties without proof. Unit 04 uses linearity to get the distribution of \(\hat{\boldsymbol\beta}\).
01.6Recap: multiple linear regression Slides p.7
What Slides p.7
Multiple linear regression (MLR) models an outcome \(y_i\) as an intercept, plus a linear combination of \(p\) covariates \(x_{i1},\dots,x_{ip}\), plus a random error \(\epsilon_i\). The regression coefficients \(\beta_0,\dots,\beta_p\) and the error variance \(\sigma^2\) are unknown constants. \(n\) is the number of observations.
Row \(i\) is one observation. Column 1 of \(\boldsymbol{X}\) is all 1s, for the intercept \(\beta_0\). Column \(j+1\) is covariate \(j\). \(\boldsymbol{X}\) is \(n\times(p+1)\); \(\boldsymbol\beta\) is \((p+1)\times1\).
"\(\epsilon_i\) i.i.d. \(N(0,\sigma^2)\)" equals \(\boldsymbol\epsilon\sim MVN(\boldsymbol{0},\sigma^2\boldsymbol{I})\): means 0, variances \(\sigma^2\), covariances 0.
Figure 1-2. Block sizes in \(\boldsymbol{y}=\boldsymbol{X}\boldsymbol\beta+\boldsymbol\epsilon\). Left of the dashed line: the column of 1s. Columns of \(\boldsymbol{X}\) = length \(p+1\) of \(\boldsymbol\beta\). \(\boldsymbol{X}\boldsymbol\beta\) is \(n\times1\).
How Added
- For \(\boldsymbol{y}\), put \(y_1,\dots,y_n\) in one column.
- For \(\boldsymbol{X}\), write \((1,x_{i1},\dots,x_{ip})\) as row \(i\).
- For \(\boldsymbol\beta\), put \(\beta_0,\dots,\beta_p\) in one column.
- Check: row \(i\) of \(\boldsymbol{X}\) times \(\boldsymbol\beta\) equals \(\beta_0+\beta_1x_{i1}+\dots+\beta_px_{ip}\).
Self-check: \(\boldsymbol{X}\) is \(n\times(p+1)\), with a first column of 1s.
Example Added
Let \(n=3\), \(p=2\), covariates \((1,4)\), \((2,5)\), \((3,6)\). For the algebra only, let \(\boldsymbol\beta=(1,2,3)^T\).
Write \(\boldsymbol{X}\) How step 2
Calculate \(\boldsymbol{X}\boldsymbol\beta\) How step 4
Then \(\boldsymbol{y}\sim MVN\big((15,20,25)^T,\ \sigma^2\boldsymbol{I}\big)\).
Why Added
Use linearity (Section 01.5) with \(\boldsymbol{C}=\boldsymbol{I}\) and constant \(\boldsymbol{d}=\boldsymbol{X}\boldsymbol\beta\).
p.6 linearity.
Reverse: \(\boldsymbol{d}=-\boldsymbol{X}\boldsymbol\beta\) gives \(\iff\). ∎
01.7Practice Added
Q1. Let \(z=\boldsymbol{y}^T\boldsymbol{A}\boldsymbol{y}\) with \(\boldsymbol{A}=\left[\begin{array}{cc}4&1\\1&2\end{array}\right]\). Find \(\frac{\partial z}{\partial\boldsymbol{y}}\) at \(\boldsymbol{y}=(1,-1)^T\). Check entry by entry.
Answer
Agrees with step 1.
Q2. Let \(\boldsymbol{y}\sim MVN(\boldsymbol\mu,\boldsymbol\Sigma)\), \(\boldsymbol\mu=(1,2)^T\), \(\boldsymbol\Sigma=\left[\begin{array}{cc}2&1\\1&3\end{array}\right]\). Find the distribution of \(u=y_1-y_2\).
Answer
p.6 linearity.
Q3. An MLR has \(n=50\) and \(p=3\), with \(\boldsymbol{y}=\boldsymbol{X}\boldsymbol\beta+\boldsymbol\epsilon\), \(\boldsymbol\epsilon\sim MVN(\boldsymbol{0},\sigma^2\boldsymbol{I})\). (a) Give the dimensions of \(\boldsymbol{X}\), \(\boldsymbol\beta\), and \(\mathrm{Var}(\boldsymbol{y})\). (b) Show \(E[\boldsymbol{y}]=\boldsymbol{X}\boldsymbol\beta\) with the random-vector properties.
Answer
(a) \(\boldsymbol{X}\): \(n\times(p+1)=50\times4\). \(\boldsymbol\beta\): \(4\times1\). \(\mathrm{Var}(\boldsymbol{y})=\sigma^2\boldsymbol{I}\): \(50\times50\).
(b)
p.4: \(E[\boldsymbol{a}]=\boldsymbol{a}\) for constant \(\boldsymbol{X}\boldsymbol\beta\).
Unit 02Data example and interpreting regression coefficients
Step 1 (Slides p.8–9): meet the data set satisfaction.csv.
Step 2 (Slides p.10–11): read the summary numbers and the scatter plots.
Step 3 (Slides p.12): list the questions of the lecture.
Step 4 (Slides p.13): write the model in scalar form and matrix form.
Step 5 (Slides p.14–16): interpret the intercept \(\beta_0\) and each slope \(\beta_j\).
Variable: one column of a data table.
Observation: one row of a data table. In this unit, one patient.
The subscript \(i\) gives the observation. The subscript \(j\) gives the covariate.
02.1Title page Slides p.8
Slides p.8 Slide p.8 repeats the title "Lecture 6: Multiple Linear Regression: Intro & Estimation".
Slides p.1–7 are a recap. New material starts on Slides p.9.
02.2Data example: satisfaction.csv Slides p.9
What Slides p.9
satisfaction.csv contains data on \(n = 46\) hospital patients. The variables are:
- Satisfaction: degree of satisfaction with quality of care (higher values = more)
- Age: age of patient in years
- Severity: severity score for patient condition
- Stress: patient self reported degree of stress
| Variable | Role |
|---|---|
| Satisfaction | outcome \(y_i\) |
| Age | covariate 1, \(x_{i1}\) |
| Severity | covariate 2, \(x_{i2}\) |
| Stress | covariate 3, \(x_{i3}\) |
\(n=46\) observations, \(p=3\) covariates.
02.3Exploratory data analysis: first rows and summary numbers Slides p.10
Exploratory data analysis (EDA): a check of the range, center, and shape of the data before you make a model.
What Slides p.10
First 6 rows:
| Row | Satisfaction | Age | Severity | Stress |
|---|---|---|---|---|
| 1 | 48 | 50 | 51 | 2.3 |
| 2 | 57 | 36 | 46 | 2.3 |
| 3 | 66 | 40 | 48 | 2.2 |
| 4 | 70 | 41 | 44 | 1.8 |
| 5 | 89 | 28 | 43 | 1.8 |
| 6 | 36 | 49 | 54 | 2.9 |
Summary numbers:
| Satisfaction | Age | Severity | Stress | |
|---|---|---|---|---|
| Minimum | 26.00 | 22.00 | 41.00 | 1.800 |
| 1st quartile | 48.25 | 31.25 | 48.00 | 2.100 |
| Median | 60.00 | 37.50 | 50.50 | 2.300 |
| Mean | 61.57 | 38.39 | 50.43 | 2.287 |
| 3rd quartile | 76.75 | 44.75 | 53.00 | 2.475 |
| Maximum | 92.00 | 55.00 | 62.00 | 2.900 |
Quartile: a value that divides the sorted data into four equal parts. About 25% of the data are below the 1st quartile, about 75% below the 3rd.
Median: the middle value of the sorted data.
Sample mean \(\bar y=\frac1n\sum_{i=1}^n y_i\).
How Added
- Find the column of the variable.
- Read the minimum and maximum. They give the range.
- Read the median and mean. They give the center.
- Read the 1st and 3rd quartiles. The middle 50% of the data are between them.
Self-check: minimum ≤ 1st quartile ≤ median ≤ 3rd quartile ≤ maximum. The mean is in the range.
Example · Read the two tables Added
Patient 1: \(y_1=48\), \(x_{11}=50\), \(x_{12}=51\), \(x_{13}=2.3\).
| Variable | Range | Mean |
|---|---|---|
| Satisfaction | 26 to 92 | 61.57 (median 60) |
| Age | 22 to 55 years | 38.39 |
| Severity | 41 to 62 | 50.43 |
| Stress | 1.8 to 2.9 | 2.287 |
Self-check: For Age, 22 ≤ 31.25 ≤ 37.50 ≤ 44.75 ≤ 55, and 38.39 is between 22 and 55.
No covariate has the value 0. Section 02.7 uses this fact. ▲
02.4Scatter plot matrix Slides p.11
What Slides p.11
Slides p.11 shows a scatter plot matrix of the four variables.
Scatter plot: one point for each observation. The horizontal position is one variable, the vertical position is another.
Scatter plot matrix (pairs plot): a grid with the scatter plot of each pair of variables. 4 variables give a 4×4 grid. The diagonal cells show only the names.
How Added
- Find variable A on the diagonal. Note its row.
- Find variable B on the diagonal. Note its column.
- Go to row A, column B. The vertical axis is A. The horizontal axis is B.
- Points from lower left to upper right show a positive association.
- Points from upper left to lower right show a negative association.
Self-check: Each axis covers the minimum to the maximum of its variable in the summary table.
Example · Satisfaction against Age Added
Row 1, column 2: vertical axis Satisfaction, horizontal axis Age.
The points go from upper left to lower right (step 5). Satisfaction and Age have a negative association.
The axes cover 26 to 92 and 22 to 55, as in the summary table.
This plot does not hold Severity and Stress fixed. Section 02.7 does. ▲
02.5Motivating questions Slides p.12
What Slides p.12
- Is mean satisfaction associated with stress, conditional on age and severity?
- How does mean satisfaction differ for older patients vs younger patients with the same severity and stress scores?
- Given a patient's stress, age, and severity, can we predict their satisfaction?
- Later: is the (conditional) association between stress and satisfaction different for older patients than for younger patients?
- Many others...
Association: when one variable changes, the mean of another variable changes.
Conditional on: with the other variables held at fixed values.
Questions 1 and 2 hold other variables fixed. Figure 2-1 cannot do this. We need a model with all three covariates.
02.6The multiple linear regression model Slides p.13
What Slides p.13
Or
\[\boldsymbol{y}=\boldsymbol{X}\boldsymbol{\beta}+\boldsymbol{\epsilon},\quad \boldsymbol{\epsilon}\sim MVN(\boldsymbol{0},\sigma^2\boldsymbol{I})\] \[\iff\] \[\boldsymbol{y}\sim MVN(\boldsymbol{X}\boldsymbol{\beta},\sigma^2\boldsymbol{I})\]Note: we assume \(p+1<n\)
This is the model of Section 01.6, with \(i=1,\dots,n\) added.
\(p+1<n\): there are fewer unknown coefficients than observations. It makes \(n-(p+1)\) positive. Unit 05 divides by it.
How Added
- Find the outcome and the covariates. Write \(n\) and \(p\).
- Write the scalar form with the variable names.
- Put \(n\) 1s in column 1 of \(\boldsymbol{X}\).
- Put covariate \(j\) in column \(j+1\).
- Check \(p+1<n\).
Self-check: \(\boldsymbol{X}\) is \(n\times(p+1)\). \(\boldsymbol{\beta}\) has \(p+1\) entries. Row \(i\) of \(\boldsymbol{X}\) matches row \(i\) of the data.
Example · The model for satisfaction.csv Added
Step 1. \(n=46\), \(p=3\).
Step 2.
\[\text{Satisfaction}_i=\beta_0+\beta_1\,\text{Age}_i+\beta_2\,\text{Severity}_i+\beta_3\,\text{Stress}_i+\epsilon_i,\qquad \epsilon_i\overset{iid}{\sim}N(0,\sigma^2),\quad i=1,\dots,46\]Steps 3–4. First three rows from Slides p.10:
\[\boldsymbol{X}=\left[\begin{array}{cccc}1&50&51&2.3\\1&36&46&2.3\\1&40&48&2.2\\\vdots&\vdots&\vdots&\vdots\end{array}\right]_{46\times4},\qquad \boldsymbol{\beta}=\left[\begin{array}{c}\beta_0\\\beta_1\\\beta_2\\\beta_3\end{array}\right]\]Step 5. \(4<46\). The assumption is true.
Self-check: \(46\times4=n\times(p+1)\). Row 1 is patient 1: Age 50, Severity 51, Stress 2.3.
Coefficient estimates used in this unit. Estimate: a number calculated from the data in place of an unknown true value. A hat marks it, for example \(\hat\beta_1\).
Lecture 6 does not print the estimates. Lecture 7 · p.51 prints a 95% confidence interval for each coefficient. Confidence interval: a range of values for an unknown coefficient, calculated from the data.
The estimate is the midpoint of each interval:
This unit uses \(\hat{\boldsymbol\beta}=(158.491,\,-1.142,\,-0.442,\,-13.470)^T\). Unit 03 calculates it. ▲
Why Added
The scalar form and the matrix form give the same model. Row \(i\) of \(\boldsymbol{X}\boldsymbol\beta\):
Add \(\epsilon_i\) to get the scalar form. The form \(\boldsymbol{y}\sim MVN(\boldsymbol{X}\boldsymbol\beta,\sigma^2\boldsymbol{I})\) comes from linearity (Slides p.6, Section 01.6).
Check with patient 1, row \((1,50,51,2.3)\):
This equals the scalar form \(\hat\beta_0+\hat\beta_1(50)+\hat\beta_2(51)+\hat\beta_3(2.3)\). ∎
02.7Interpreting regression coefficients Slides p.14–16
Slides p.14–16 Slides p.14 and p.15 are the first parts of Slides p.16. This section follows p.16.
What Slides p.14–16
To interpret a parameter, isolate it!
\[E[y_i\,|\,x_{i1},\dots,x_{ip}]=\beta_0+\beta_1x_{i1}\cdots+\beta_Px_{ip}\]What does \(\beta_0\) represent?
\[E[y_i\,|\,x_{i1}=\cdots=x_{ip}=0]=\beta_0+\beta_1(0)+\cdots+\beta_P(0)=\beta_0\]- \(\implies\beta_0\) is the mean outcome when all covariates are set to 0
- May not be interpretable: e.g. what does it mean for age to be 0 in a sample of adults?
What does \(\beta_1\) represent?
\[E[y_i\,|\,x_{i1}=x_1,x_{i2}=x_2,\dots,x_{ip}=x_P]=\beta_0+\beta_1(x_1)+\beta_2(x_2)+\cdots+\beta_P(x_P)\] \[E[y_i\,|\,x_{i1}=(x_1+1),x_{i2}=x_2,\dots,x_{ip}=x_P]=\beta_0+\beta_1(x_1+1)+\cdots+\beta_P(x_P)\]- \(E[y_i\,|\,x_{i1}=(x_1+1),x_{i2}=x_2,\dots,x_{ip}=x_P]-E[y_i\,|\,x_{i1}=x_1,x_{i2}=x_2,\dots,x_{ip}=x_P]=\beta_1\)
- More generally \(\beta_j\) represents the difference in mean outcome for a one-unit change in the \(j^{th}\) covariate, holding other covariates fixed.
Conditional expectation \(E[y_i\,|\,x_{i1},\dots,x_{ip}]\): the mean of \(y_i\) at the given covariate values. Read \(|\) as "given".
If 0 is outside the range of the data, \(\beta_0\) has no practical meaning.
"Holding other covariates fixed" is a necessary part of each slope interpretation.
How Added
- Write \(\beta_0+\beta_1x_{i1}+\cdots+\beta_px_{ip}\).
- Intercept: put 0 for all covariates. The result is \(\beta_0\).
- Check in the summary table if 0 is in the range of each covariate.
- Slope: write the expression with covariate \(j\) at \(x_j\), then at \(x_j+1\).
- Give the other covariates the same values in both.
- Subtract. Only \(\beta_j\) remains.
- Write: a one-unit increase in covariate \(j\) changes the mean outcome by \(\beta_j\), other covariates held fixed.
Self-check: The sentence names the covariate and its unit, the direction and size, and "held fixed". With an estimate, it says "estimated mean outcome".
Example · Interpret \(\hat\beta_0\) and \(\hat\beta_1\) Added
Step 1.
\[\hat\beta_0+\hat\beta_1\,\text{Age}+\hat\beta_2\,\text{Severity}+\hat\beta_3\,\text{Stress}=158.491-1.142\,\text{Age}-0.442\,\text{Severity}-13.470\,\text{Stress}\]Step 2 (intercept). Age = Severity = Stress = 0:
Step 3. Minimum Age is 22, Severity 41, Stress 1.8 (Section 02.3). \(\hat\beta_0\) has no practical meaning. This is the second bullet of Slides p.15.
Steps 4–5 (Age). Hold Severity = 50, Stress = 2.3. Use Age 40, then 41.
Step 6.
\(-22.1\) and \(-30.981\) cancel.
Step 7. Each one-year increase in Age decreases the estimated mean satisfaction by 1.142, with Severity and Stress held fixed.
\(\hat\beta_2=-0.442\): each one-point increase in Severity decreases the estimated mean satisfaction by 0.442, with Age and Stress held fixed.
\(\hat\beta_3=-13.470\): each one-unit increase in Stress decreases the estimated mean satisfaction by 13.470, with Age and Severity held fixed.
Figure 2-2 holds Severity and Stress at their means, 50.43 and 2.287: \(158.491-0.442(50.43)-13.470(2.287)-1.142\,\text{Age}=105.395-1.142\,\text{Age}\) (3 decimals).
Other fixed values, for example Severity = 60, move the line up or down. The slope stays \(-1.142\). ▲
Why Slides p.14–16
Model, Slides p.13
Given covariates, first part is fixed
\(E[\epsilon_i]=0\)
Other terms are equal and cancel
Line 8 needs equal values of the other covariates. The result does not depend on \(x_j\): Age 40 to 41 and Age 30 to 31 both give \(\beta_1\). ∎
02.8Practice Added
Use \(\hat{\boldsymbol\beta}=(158.491,\,-1.142,\,-0.442,\,-13.470)^T\).
Q1. Interpret \(\hat\beta_3=-13.470\). Two patients have the same Age and Severity. Their Stress differs by 0.5. Find the difference in estimated mean satisfaction.
Answer
Each one-unit increase in Stress decreases the estimated mean satisfaction by 13.470, with Age and Severity held fixed.
\(0.5\times(-13.470)=-6.735\)
The patient with higher Stress has an estimated mean satisfaction 6.735 lower.
Q2. Two patients have Severity = 50 and Stress = 2.3. Their ages are 30 and 50. Find each estimated mean satisfaction and the difference. Write the difference with \(\hat\beta_1\).
Answer
Difference: \(48.31-71.15=-22.84\).
With \(\hat\beta_1\): \(20\times\hat\beta_1=20\times(-1.142)=-22.84\).
The Severity and Stress terms cancel. The older patient is 22.84 lower.
Q3. Patient 5 (Slides p.10) has Age 28, Severity 43, Stress 1.8. Write row 5 of \(\boldsymbol{X}\). Find the estimated mean satisfaction.
Answer
Row 5 of \(\boldsymbol{X}\): \((1,28,43,1.8)\).
Estimate 83.263. Observed value 89.
Unit 03Estimating β: least squares and maximum likelihood
Step 1: State the model (Slides p.17).
Step 2: Least squares: minimize \(S(\boldsymbol\beta)\) (Slides p.18–20).
Step 3: Solve a small data set by hand (Added).
Step 4: Maximum likelihood: link \(\ell\) to \(S(\boldsymbol\beta)\) (Slides p.21–22).
03.1Title page: Estimating \(\boldsymbol\beta\) Slides p.17
Model: \(\boldsymbol{y}=\boldsymbol{X}\boldsymbol\beta+\boldsymbol\epsilon\), \(\boldsymbol\epsilon\sim MVN(\boldsymbol{0},\sigma^2\boldsymbol{I})\). The errors are independent normal, each with variance \(\sigma^2\).
The slides use the satisfaction data (\(n=46\), \(p=3\), Slides p.9). The example uses a smaller data set.
03.2Least squares estimation Slides p.18–20
Slides p.18–19 build up p.20.
What Slides p.20
How Added
- Write \(\boldsymbol{y}\) (\(n\times1\)) and \(\boldsymbol{X}\) (\(n\times(p+1)\), first column all 1s).
- Calculate \(\boldsymbol{X}^T\boldsymbol{X}\). Entry \((j,k)\) is \(\sum_i x_{ij}x_{ik}\).
- Calculate \(\boldsymbol{X}^T\boldsymbol{y}\). Entry \(j\) is \(\sum_i x_{ij}y_i\).
- Make sure that \(\det(\boldsymbol{X}^T\boldsymbol{X})\neq0\).
- Solve \((\boldsymbol{X}^T\boldsymbol{X})\boldsymbol\beta=\boldsymbol{X}^T\boldsymbol{y}\).
Self-check: (1) \(\boldsymbol{X}^T\boldsymbol{X}\) is symmetric, and its entry \((1,1)\) is \(n\). (2) Entry 1 of \(\boldsymbol{X}^T\boldsymbol{y}\) is \(\sum_iy_i\). (3) \((\boldsymbol{X}^T\boldsymbol{X})\hat{\boldsymbol\beta}\) equals \(\boldsymbol{X}^T\boldsymbol{y}\).
Example Added
\(n=4\), one covariate (\(p=1\)), \(\boldsymbol\beta=(\beta_0,\beta_1)^T\).
Write \(\boldsymbol{y}\) and \(\boldsymbol{X}\) How step 1
Calculate \(\boldsymbol{X}^T\boldsymbol{X}\) How step 2
Self-check: symmetric; entry \((1,1)=4=n\).
Calculate \(\boldsymbol{X}^T\boldsymbol{y}\) How step 3
Self-check: entry 1 is \(\sum_iy_i\).
Make sure that the inverse exists How step 4
The columns of \(\boldsymbol{X}\) are linearly independent.
Find \((\boldsymbol{X}^T\boldsymbol{X})^{-1}\) How step 5
Rows \((a,b),(c,d)\) → \(\frac{1}{ad-bc}\) times rows \((d,-b),(-c,a)\).
Calculate \(\hat{\boldsymbol\beta}=(\boldsymbol{X}^T\boldsymbol{X})^{-1}\boldsymbol{X}^T\boldsymbol{y}\) How step 5 · Slides p.20
Basis: Slides p.20. Step 4 makes the solution unique.
Put \(\hat{\boldsymbol\beta}\) back into the equations Self-check 3
Self-check: 16 and 47 equal \(\boldsymbol{X}^T\boldsymbol{y}\).
Model values \(0.5+1.4x\): 1.9, 3.3, 4.7, 6.1. Differences \(y_i-(\boldsymbol{X}\hat{\boldsymbol\beta})_i\): 0.1, −0.3, 0.3, −0.1.
Result: \(\hat{\boldsymbol\beta}=(0.5,\,1.4)^T\), \(S(\hat{\boldsymbol\beta})=0.2\). ▲
In the figure, \(\beta_0\) stays at 0.5 and only \(\beta_1\) changes. Then \(S=0.2+30(\beta_1-1.4)^2\), with \(30=\sum_ix_i^2\).
At \(\beta_1=\hat\beta_1\pm0.1\), \(S=0.2+30(0.1)^2=0.5\).
Why Slides p.20
Rules from Unit 01, with \(\boldsymbol\beta\) in place of \(\boldsymbol{y}\):
\((\boldsymbol{X}\boldsymbol\beta)^T=\boldsymbol\beta^T\boldsymbol{X}^T\).
A \(1\times1\) value equals its transpose.
Line 3 of Slides p.20.
Form \(\boldsymbol{a}^T\boldsymbol\beta\), \(\boldsymbol{a}=\boldsymbol{X}^T\boldsymbol{y}\).
Rule A.
Symmetric: Rule B applies.
Rule B with \(\boldsymbol{A}=\boldsymbol{X}^T\boldsymbol{X}\).
Steps 7 and 9.
The derivative is 0 at the minimum.
Multiply on the left by \((\boldsymbol{X}^T\boldsymbol{X})^{-1}\). ∎
Check of step 11 on the example: \(-2(16,47)^T+2(16,47)^T=(0,0)^T\).
03.3Maximum likelihood Slides p.21–22
Slide p.21 builds up p.22.
What Slides p.22
So \(\hat{\boldsymbol\beta}_{MLE}=\hat{\boldsymbol\beta}=(\boldsymbol{X}^T\boldsymbol{X})^{-1}\boldsymbol{X}^T\boldsymbol{y}\)
• I.e. MLE=OLS (when all our assumptions hold)
"Look familiar?": only the last term of \(\ell\) contains \(\boldsymbol\beta\), and it is \(-\frac{1}{2\sigma^2}S(\boldsymbol\beta)\). The largest \(\ell\) occurs at the smallest \(S\). The assumptions are linearity, independence, normality, and equal variance.
How Added
- Write \(\boldsymbol{y}\sim MVN(\boldsymbol{X}\boldsymbol\beta,\sigma^2\boldsymbol{I})\).
- Write \(\mathcal{L}(\boldsymbol\beta,\sigma^2|\mathbf{Y})\). Take the log to get \(\ell(\boldsymbol\beta,\sigma^2|\mathbf{Y})\).
- Find the term of \(\ell\) with \(\boldsymbol\beta\): \(-\frac{1}{2\sigma^2}(\boldsymbol{y}-\boldsymbol{X}\boldsymbol\beta)^T(\boldsymbol{y}-\boldsymbol{X}\boldsymbol\beta)\).
- The factor \(-\frac{1}{2\sigma^2}\) is negative. Maximize \(\ell\) by minimizing \(S(\boldsymbol\beta)\).
- Use Section 03.2: \(\hat{\boldsymbol\beta}_{MLE}=(\boldsymbol{X}^T\boldsymbol{X})^{-1}\boldsymbol{X}^T\boldsymbol{y}\).
Self-check: (1) A change of \(\sigma^2\) does not move the maximizing \(\boldsymbol\beta\). (2) \(\ell(\hat{\boldsymbol\beta},\sigma^2|\mathbf{Y})\) is larger than \(\ell\) at any other \(\boldsymbol\beta\).
Example Added
Data of Section 03.2 (\(n=4\)). \(\sigma^2\) is unknown. Fix \(\sigma^2=1\), then \(\sigma^2=0.5\). Unit 05 estimates \(\sigma^2\).
Write the three terms of \(\ell\) How step 2
\(\frac n2=2\).
Calculate at \(\boldsymbol\beta=\hat{\boldsymbol\beta}\) and \(\sigma^2=1\) Slides p.22
Move \(\beta_1\) by \(\pm0.1\) and keep \(\beta_0=0.5\) Self-check 2
Both sides; bottom curve of Figure 3-1.
Calculate again with \(\sigma^2=0.5\) Self-check 1
Self-check: \(\ell\) changes, but its maximum stays at \(\hat{\boldsymbol\beta}\). \(\sigma^2\) changes only the positive factor \(\frac{1}{2\sigma^2}\).
Result: \(\hat{\boldsymbol\beta}_{MLE}=(0.5,\,1.4)^T\), the OLS estimate. ▲
Why Slides p.22
MVN density.
Diagonal matrix: product of diagonal entries.
Put in steps 2 and 3.
\(\log(abc)=\log a+\log b+\log c\) and \(\log e^{u}=u\).
\(\log a^{k}=k\log a\). Slides p.22.
Definition of \(S(\boldsymbol\beta)\): "Look familiar?"
Section 03.2, Why step 10.
Set to 0; multiply by \(-2\sigma^2\).
Section 03.2, Why steps 11–14. ∎
03.4Practice Added
Q1. Use the data \(x=2,4,6\) and \(y=1,3,8\). Calculate \(\boldsymbol{X}^T\boldsymbol{X}\), \(\boldsymbol{X}^T\boldsymbol{y}\), and \(\hat{\boldsymbol\beta}=(\boldsymbol{X}^T\boldsymbol{X})^{-1}\boldsymbol{X}^T\boldsymbol{y}\).
Answer
\(\boldsymbol{X}\) has rows \((1,2)\), \((1,4)\), \((1,6)\).
\(\boldsymbol{X}^T\boldsymbol{X}\): entry \((1,1)=3\); entry \((1,2)=2+4+6=12\); entry \((2,2)=4+16+36=56\).
\(\boldsymbol{X}^T\boldsymbol{y}\): entry \(1=1+3+8=12\); entry \(2=2(1)+4(3)+6(8)=2+12+48=62\).
\(\det(\boldsymbol{X}^T\boldsymbol{X})=3(56)-12(12)=168-144=24\).
\(\hat\beta_0=\frac{1}{24}\big(56(12)-12(62)\big)=\frac{1}{24}(672-744)=\frac{-72}{24}=-3\).
\(\hat\beta_1=\frac{1}{24}\big(-12(12)+3(62)\big)=\frac{1}{24}(-144+186)=\frac{42}{24}=1.75\).
Check row 1: \(3(-3)+12(1.75)=-9+21=12\). Check row 2: \(12(-3)+56(1.75)=-36+98=62\). \(\hat{\boldsymbol\beta}=(-3,\,1.75)^T\).
Q2. Intercept-only model \(y_i=\beta_0+\epsilon_i\): \(\boldsymbol{X}\) is an \(n\times1\) column of 1s. Use \(\hat{\boldsymbol\beta}=(\boldsymbol{X}^T\boldsymbol{X})^{-1}\boldsymbol{X}^T\boldsymbol{y}\) to find \(\hat\beta_0\). Calculate it for \(y=2,3,5,6\).
Answer
\(\boldsymbol{X}=(1,\dots,1)^T\).
\(\boldsymbol{X}^T\boldsymbol{X}=\sum_{i=1}^n1\cdot1=n\).
\(\boldsymbol{X}^T\boldsymbol{y}=\sum_{i=1}^ny_i\).
\(\hat\beta_0=n^{-1}\sum_{i=1}^ny_i=\bar y\), the sample mean.
Data: \(n=4\), \(\sum_iy_i=2+3+5+6=16\), \(\hat\beta_0=16/4=4\).
Q3. Use \(\boldsymbol{y}\sim MVN(\boldsymbol{X}\boldsymbol\beta,\sigma^2\boldsymbol{I})\). Why does the \(\boldsymbol\beta\) with the largest \(\ell(\boldsymbol\beta,\sigma^2|\mathbf{Y})\) not depend on \(\sigma^2\)? For \(n=4\), \(S(\hat{\boldsymbol\beta})=0.2\), calculate \(\ell(\hat{\boldsymbol\beta},2|\mathbf{Y})\).
Answer
\(\ell(\boldsymbol\beta,\sigma^2|\mathbf{Y})=-\frac n2\log(2\pi)-\frac n2\log\sigma^2-\frac{1}{2\sigma^2}S(\boldsymbol\beta)\).
Only the third term contains \(\boldsymbol\beta\): the positive \(\frac{1}{2\sigma^2}\) times \(-S(\boldsymbol\beta)\).
For each \(\sigma^2>0\), the largest \(\ell\) occurs at the smallest \(S\), at \(\hat{\boldsymbol\beta}=(\boldsymbol{X}^T\boldsymbol{X})^{-1}\boldsymbol{X}^T\boldsymbol{y}\).
Numbers: \(-2\log(2\pi)=-3.675754\), \(-2\log2=-1.386294\), \(-\frac{0.2}{2(2)}=-0.05\).
\(\ell(\hat{\boldsymbol\beta},2|\mathbf{Y})=-3.675754-1.386294-0.05=-5.112048\).
Unit 04Properties of the LS estimator, fitted values, and residuals
Step 1: Show \(E[\hat{\boldsymbol\beta}]=\boldsymbol\beta\) (Slides p.23–25).
Step 2: Find the covariance matrix of \(\hat{\boldsymbol\beta}\) (Slides p.26–27).
Step 3: Write the distribution of \(\hat{\boldsymbol\beta}\) and of each \(\hat\beta_j\) (Slides p.28–29).
Step 4: Define the fitted values and the hat matrix \(\boldsymbol H\) (Slides p.30).
Step 5: Define the residuals and show \(\boldsymbol X^T\boldsymbol e=\boldsymbol 0\) (Slides p.31–32).
Facts from earlier units:
All examples use this data set Added: \(n=4\), \(p=1\), row \(i\) of \(\boldsymbol X\) is \((1,\ x_i)\).
\[x=(0,\ 1,\ 2,\ 3),\qquad \boldsymbol y=(1,\ 3,\ 2,\ 5)^T,\qquad \boldsymbol X=\left[\begin{array}{cc}1&0\\1&1\\1&2\\1&3\end{array}\right]\]Entry \((j,k)\): column \(j\) dot column \(k\).
\(2\times2\) inverse: swap diagonal, negate off-diagonal, divide.
04.1The mean of \(\hat{\boldsymbol\beta}\): unbiasedness Slides p.23–25
What Slides p.25
\(\hat{\boldsymbol\beta}\) comes from the random \(\boldsymbol y\). Each new data set gives a different \(\hat{\boldsymbol\beta}\). Its mean over all data sets is exactly \(\boldsymbol\beta\). Unbiased: the mean of the estimator equals the parameter.
How Added
- Write the estimator as \(\boldsymbol C\boldsymbol y\), with \(\boldsymbol C\) built only from \(\boldsymbol X\) and numbers.
- For \(\hat{\boldsymbol\beta}\), \(\boldsymbol C=(\boldsymbol X^T\boldsymbol X)^{-1}\boldsymbol X^T\).
- Move \(E\) inside: \(E[\boldsymbol C\boldsymbol y]=\boldsymbol C\,E[\boldsymbol y]\).
- Put in \(E[\boldsymbol y]=\boldsymbol X\boldsymbol\beta\) to get \(\boldsymbol C\boldsymbol X\boldsymbol\beta\).
- Calculate \(\boldsymbol C\boldsymbol X\). If \(\boldsymbol C\boldsymbol X=\boldsymbol I\), then \(E[\boldsymbol C\boldsymbol y]=\boldsymbol\beta\).
Self-check: \(\boldsymbol C\) is \((p+1)\times n\). \(\boldsymbol C\boldsymbol X\) is \((p+1)\times(p+1)\), with 1 on the diagonal and 0 elsewhere.
Example Added
Steps 2 and 5 for the small data set:
\(E[\hat{\boldsymbol\beta}]=\boldsymbol I\boldsymbol\beta=\boldsymbol\beta\). Check: row 1 of \(\boldsymbol C\boldsymbol y\) is \(0.7\cdot1+0.4\cdot3+0.1\cdot2-0.2\cdot5=0.7+1.2+0.2-1.0=1.1\). ▲
Why Slides p.25
\(E[\boldsymbol C\boldsymbol y]=\boldsymbol C\,E[\boldsymbol y]\).
Model: \(E[\boldsymbol y]=\boldsymbol X\boldsymbol\beta\).
∎
04.2The covariance matrix of \(\hat{\boldsymbol\beta}\) Slides p.26–27
What Slides p.27
\(\mathrm{Var}[\hat{\boldsymbol\beta}]\) is \((p+1)\times(p+1)\). Its diagonal entry for \(\beta_j\) is \(\mathrm{Var}[\hat\beta_j]\). \(\sigma^2\) is unknown. \((\boldsymbol X^T\boldsymbol X)^{-1}\) is known.
The slides write \(\boldsymbol V=(\boldsymbol X^T\boldsymbol X)^{-1}\) (p.29). Rows and columns follow the order \(\beta_0,\beta_1,\dots,\beta_p\). \(V_{jj}\) is the diagonal entry for \(\beta_j\).
How Added
- Make \(\boldsymbol X\), with 1 in each entry of column 1.
- Calculate \(\boldsymbol X^T\boldsymbol X\).
- Find \(\boldsymbol V=(\boldsymbol X^T\boldsymbol X)^{-1}\).
- Take \(V_{jj}\). The first diagonal entry is for \(\beta_0\).
- Write \(\mathrm{Var}[\hat\beta_j]=\sigma^2V_{jj}\).
Self-check: \(\boldsymbol V\) is \((p+1)\times(p+1)\) and symmetric. Each \(V_{jj}\) is larger than 0.
Example Added
\(\sigma^2\) is still unknown. Unit 05 estimates it and calculates the standard error. ▲
Why Slides p.27
The slides do lines 3 and 4 in one step Added.
\(\mathrm{Var}[\boldsymbol C\boldsymbol y]=\boldsymbol C\,\mathrm{Var}[\boldsymbol y]\,\boldsymbol C^T\) (Slides p.4).
Added: \((\boldsymbol A\boldsymbol B)^T=\boldsymbol B^T\boldsymbol A^T\).
Symmetric \(\boldsymbol X^T\boldsymbol X\) has a symmetric inverse.
Model: \(\mathrm{Var}[\boldsymbol y]=\sigma^2\boldsymbol I\).
∎
04.3The distribution of \(\hat{\boldsymbol\beta}\) Slides p.28–29
What Slides p.29
Line 1 combines the mean (04.1) and the covariance matrix (04.2). "Property 2" is the marginal property (Slides p.6). It gives one component \(\hat\beta_j\) a normal distribution.
How Added
- Find \(j\): the intercept has \(j=0\), covariate \(k\) has \(j=k\).
- Find \(\boldsymbol V\) (How box of 04.2).
- Take \(V_{jj}\).
- Write \(\hat\beta_j\sim N(\beta_j,\ \sigma^2V_{jj})\). The mean is the parameter \(\beta_j\), not a number.
Self-check: The variance is \(\sigma^2\) times a positive number.
Example Added
Slope estimator \(\hat\beta_1\), small data set:
The value \(\hat\beta_1=1.1\) is one draw from this distribution. ▲
Why Added
The slides give no reason. The reason is the linearity property (Slides p.6):
with \(\boldsymbol y\sim MVN(\boldsymbol\mu,\boldsymbol\Sigma)\).
Model (p.7).
\(\boldsymbol C\) is constant; \(\boldsymbol d=\boldsymbol 0\).
Linearity.
Why of 04.1, lines 3–5.
Why of 04.2, lines 2–7.
Line 1 of p.29. ∎
Line 2 of p.29: the marginal property (p.6) takes entry \(j\) of the mean and diagonal entry \(j\) of \(\sigma^2\boldsymbol V\).
04.4Fitted values and the hat matrix \(\boldsymbol H\) Slides p.30
What Slides p.30
Fitted value: the estimated regression equation at the covariates of observation \(i\), \(\hat y_i=\hat\beta_0+\hat\beta_1x_{i1}+\cdots+\hat\beta_px_{ip}\). Hat matrix \(\boldsymbol H\): the \(n\times n\) matrix that changes \(\boldsymbol y\) into \(\hat{\boldsymbol y}\). \(\boldsymbol H\) depends only on \(\boldsymbol X\).
How Added
- Calculate \(\hat{\boldsymbol\beta}\).
- Take row \(i\) of \(\boldsymbol X\), \((1,x_{i1},\dots,x_{ip})\).
- Multiply it with \(\hat{\boldsymbol\beta}\) term by term and add, to get \(\hat y_i\).
- Do Steps 2 and 3 for each \(i=1,\dots,n\).
- Alternative: calculate \(\boldsymbol H=\boldsymbol X(\boldsymbol X^T\boldsymbol X)^{-1}\boldsymbol X^T\), then \(\boldsymbol H\boldsymbol y\).
Self-check: \(\boldsymbol H\) is \(n\times n\) and symmetric. Steps 4 and 5 give the same \(\hat{\boldsymbol y}\).
Example Added
Step 5: \(\boldsymbol H=\boldsymbol X\boldsymbol C\), with \(\boldsymbol C\) from 04.1. Row \(i\) of \(\boldsymbol H\) is \((\text{row 1 of }\boldsymbol C)+x_i\cdot(\text{row 2 of }\boldsymbol C)\).
\(x_i=0,1,2,3\).
Same as Steps 2–4. ▲
Why Slides p.30
Matrix multiplication is associative.
∎
04.5Residuals and \(\boldsymbol X^T\boldsymbol e=\boldsymbol 0\) Slides p.31–32
What Slides p.32
Residual: observed value minus fitted value, \(e_i=y_i-\hat y_i\). \(\boldsymbol X^T\boldsymbol e=\boldsymbol 0\) gives one equation for each column of \(\boldsymbol X\):
Orthogonal: two vectors with dot product 0 (sum of products of matching entries). \(\boldsymbol e\) is orthogonal to each column of \(\boldsymbol X\).
How Added
- Calculate \(\hat{\boldsymbol y}\) (How box of 04.4).
- Calculate \(e_i=y_i-\hat y_i\) for each \(i\).
- Calculate \(\sum e_i\).
- For each covariate \(k\), calculate \(\sum x_{ik}e_i\).
Self-check: With exact arithmetic, each of the \(p+1\) entries is exactly 0.
Example Added
Why Slides p.31–32
Part 1 is Slides p.31. Part 2 answers the "Why?" on p.32. The slides do lines 2 and 3 of Part 2 in one step Added.
04.4.
∎
Line 3 of Part 1.
Added.
∎
\(E[\hat{\boldsymbol\beta}]=\boldsymbol\beta\). \(\mathrm{Var}[\hat{\boldsymbol\beta}]=\sigma^2\boldsymbol V\). \(\hat\beta_j\sim N(\beta_j,\sigma^2V_{jj})\). \(\hat{\boldsymbol y}=\boldsymbol H\boldsymbol y\). \(\boldsymbol e=(\boldsymbol I-\boldsymbol H)\boldsymbol y\), \(\boldsymbol X^T\boldsymbol e=\boldsymbol 0\). Unit 05 estimates \(\sigma^2\).
04.6Practice Added
Q1. Data: \(n=3\), \(x=(1,\ 2,\ 3)\), model \(y_i=\beta_0+\beta_1x_i+\epsilon_i\). Find \(\boldsymbol V=(\boldsymbol X^T\boldsymbol X)^{-1}\). Write the distribution of \(\hat\beta_1\) in terms of \(\sigma^2\).
Answer
Q2. Use the data of Q1 with \(\boldsymbol y=(2,\ 2,\ 5)^T\). Calculate \(\hat{\boldsymbol\beta}\), the fitted values, and the residuals. Check \(\boldsymbol X^T\boldsymbol e=\boldsymbol 0\).
Answer
Q3. Show \(\boldsymbol X^T\hat{\boldsymbol y}=\boldsymbol X^T\boldsymbol y\). Check row 1 with the small data set.
Answer
p.32.
∎
Row 1 (column of ones): \(\sum\hat y_i=\sum y_i\). \(\sum\hat y_i=1.1+2.2+3.3+4.4=11\). \(\sum y_i=1+3+2+5=11\).
Unit 05Estimating σ², calculating the estimates, and practice
Step 1: Find the MLE \(\hat\sigma^2_{MLE}=\frac1n\boldsymbol{e}^T\boldsymbol{e}\) (Slides p.33–35).
Step 2: Change the divisor to \(n-(p+1)\) to get the unbiased \(\hat\sigma^2\) (Slides p.36).
Step 3: Calculate \(\hat{\boldsymbol\beta}\) from a system of linear equations (Slides p.37).
Step 4: Calculate the fitted values, residuals, \(\hat\sigma^2\), and standard errors (Slides p.38).
Step 5: Do the two practice questions for simple linear regression (Slides p.39–41).
The small data set of this unit Added
The slides do not print the fit for the satisfaction data (\(n=46\), \(p=3\)). This unit uses a small data set that you can do by hand.
Section 5.3 calculates \(\hat{\boldsymbol\beta}=(2.2,\,0.6)^T\) from these data.
05.1MLE of \(\sigma^2\) Slides p.33–35
What Slides p.35
\(\boldsymbol{y}-\boldsymbol{X}\hat{\boldsymbol\beta}=\boldsymbol{e}\), and \(\hat\sigma^2_{MLE}=\frac1n\boldsymbol{e}^T\boldsymbol{e}\): the mean of the squared residuals.
\(\partial\ell/\partial\sigma^2\) holds \(\boldsymbol\beta\) constant. Slides p.34 show the same page without the derivative.
How Added
- Calculate the fitted values \(\hat{\boldsymbol{y}}=\boldsymbol{X}\hat{\boldsymbol\beta}\).
- Calculate the residuals: \(e_i=y_i-\hat y_i\).
- Add the squared residuals to get \(\boldsymbol{e}^T\boldsymbol{e}\).
- Divide by \(n\).
Self-check: \(\boldsymbol{e}^T\boldsymbol{e}\ge0\) and \(\boldsymbol{X}^T\boldsymbol{e}=\boldsymbol{0}\) (Slides p.32). If not, \(\hat{\boldsymbol\beta}\) is wrong.
Example Added
Use \(\hat y=2.2+0.6x\) from Section 05.3.
Fitted values How step 1
Residuals How step 2
Residual sum of squares How step 3
Divide by \(n\) How step 4
Check: \(\sum e_i=-0.8+0.6+1.0-0.6-0.2=0\), \(\sum x_ie_i=-0.8+1.2+3.0-2.4-1.0=0\).
Figure 5-1. Data and fitted line \(\hat y=2.2+0.6x\) (green). Each vertical segment is a residual \(e_i\). The squared lengths add to \(\boldsymbol{e}^T\boldsymbol{e}=2.4\). Purple circle: \((\bar x,\bar y)\).
Why Slides p.35
Let \(Q=(\boldsymbol{y}-\boldsymbol{X}\boldsymbol\beta)^T(\boldsymbol{y}-\boldsymbol{X}\boldsymbol\beta)\). \(Q\) does not contain \(\sigma^2\).
Line 1 of p.35.
With \(u=\sigma^2\): \(\frac{d}{du}\log u=\frac1u\), \(\frac{d}{du}u^{-1}=-u^{-2}\).
Line 2 of p.35.
Multiply by \(2(\sigma^2)^2\).
Line 3 of p.35.
\(\hat{\boldsymbol\beta}\) minimizes \(Q\) for every \(\sigma^2\). ∎
05.2Unbiased estimate of \(\sigma^2\) Slides p.36
What Slides p.36
The bias of an estimator \(\hat\theta\) is \(E[\hat\theta]-\theta\).
Instead we usually use \(\hat\sigma^2=\frac{1}{n-(p+1)}\boldsymbol{e}^T\boldsymbol{e}\). Why?
Only the divisor changes. \(n-(p+1)=n-p-1\) is the residual degrees of freedom: the number of residuals that can change freely. On this page, \(\hat\sigma^2\) is this unbiased estimate.
How Added
- Calculate \(\boldsymbol{e}^T\boldsymbol{e}\) (Section 05.1, steps 1–3).
- Count the coefficients: \(p+1\), with the intercept.
- Calculate the degrees of freedom: \(n-p-1\).
- Divide: \(\hat\sigma^2=\boldsymbol{e}^T\boldsymbol{e}/(n-p-1)\).
Self-check: \(\hat\sigma^2/\hat\sigma^2_{MLE}=n/(n-p-1)>1\).
Example Added
Residual sum of squares How step 1
Section 05.1, step 3.
Count the coefficients How step 2
Degrees of freedom How step 3
Divide How step 4
Check: \(0.8/0.48=5/3=n/(n-p-1)\). \(\hat\sigma=\sqrt{0.8}=0.8944\).
Why Added
Slides p.36 give no proof.
p.32. \(\boldsymbol{X}^T\) has \(p+1\) rows.
\(p+1\) linear constraints on \(e_1,\dots,e_n\).
The constraints fix the other \(p+1\) residuals.
Gives \(E[\hat\sigma^2]=\sigma^2\) (proof below). ∎
In the example, \(\sum e_i=0\) and \(\sum x_ie_i=0\) fix \(e_4\) and \(e_5\) from \(e_1,e_2,e_3\). Only \(5-2=3\) residuals are free.
The trace \(\mathrm{tr}(\boldsymbol{A})\) is the sum of the diagonal entries of a square matrix. \(\mathrm{tr}(\boldsymbol{AB})=\mathrm{tr}(\boldsymbol{BA})\). Use \(\boldsymbol{H}=\boldsymbol{X}(\boldsymbol{X}^T\boldsymbol{X})^{-1}\boldsymbol{X}^T\) (p.30) and \(\boldsymbol{e}=(\boldsymbol{I}-\boldsymbol{H})\boldsymbol{y}\) (p.31). \(\boldsymbol{I}-\boldsymbol{H}\) is symmetric and idempotent: it times itself gives itself.
\(\boldsymbol{H}\boldsymbol{X}=\boldsymbol{X}\) gives \((\boldsymbol{I}-\boldsymbol{H})\boldsymbol{X}=\boldsymbol{0}\).
Symmetric and idempotent.
A number is its own trace. Then \(\mathrm{tr}(\boldsymbol{AB})=\mathrm{tr}(\boldsymbol{BA})\).
\(E[\boldsymbol\epsilon\boldsymbol\epsilon^T]=\mathrm{Var}[\boldsymbol\epsilon]=\sigma^2\boldsymbol{I}\).
\(E[\hat\sigma^2_{MLE}]=\frac{n-p-1}{n}\sigma^2\): too small. ∎
05.3Calculating \(\hat{\boldsymbol\beta}\) as a system of equations Slides p.37
What Slides p.37
The code on Slides p.37 does these steps:
In a system of linear equations, each unknown has only the first power.
How Added
- Make \(\boldsymbol{X}\) and \(\boldsymbol{y}\).
- Calculate \(\boldsymbol{X}^T\boldsymbol{X}\). Entry \((j,k)\) is \(\sum_i\) (column \(j\) entry)(column \(k\) entry).
- Calculate \(\boldsymbol{X}^T\boldsymbol{y}\). Entry \(j\) is \(\sum_i\) (column \(j\) entry)\(y_i\).
- Write the \(p+1\) equations.
- Solve by elimination.
Self-check: \(\boldsymbol{X}^T\boldsymbol{X}\) is symmetric, \((p+1)\times(p+1)\), with top-left entry \(n\). \(\hat{\boldsymbol\beta}\) satisfies each equation.
Example Added
Sums for \(\boldsymbol{X}^T\boldsymbol{X}\) How step 2
Sums for \(\boldsymbol{X}^T\boldsymbol{y}\) How step 3
The system How step 4
Elimination How step 5
First equation times 3.
Second equation minus step 4.
Self-check
\(\hat{\boldsymbol\beta}=(2.2,\,0.6)^T\). ▲
Why Added
Slides p.20.
A system \(\boldsymbol{A}\boldsymbol{b}=\boldsymbol{c}\). ∎
05.4Calculating \(\hat\sigma^2\) and the standard errors Slides p.38
What Slides p.38
The code on Slides p.38 does these steps:
The standard error (SE) of an estimator estimates its standard deviation, with \(\hat\sigma\) in place of \(\sigma\). Slides p.27–29: \(\hat{\boldsymbol\beta}\sim N(\boldsymbol\beta,\sigma^2(\boldsymbol{X}^T\boldsymbol{X})^{-1})\) and \(\hat\beta_j\sim N(\beta_j,\sigma^2V_{jj})\), \(j=0,1,\dots,p\).
How Added
- Calculate \(\hat\sigma^2\) (Section 05.2).
- Calculate \(\boldsymbol{V}=(\boldsymbol{X}^T\boldsymbol{X})^{-1}\). Read \(V_{jj}\).
- Multiply: \(\hat\sigma^2V_{jj}\) estimates \(\mathrm{Var}[\hat\beta_j]\).
- Take the square root: \(\mathrm{SE}(\hat\beta_j)=\hat\sigma\sqrt{V_{jj}}\).
Self-check: Each \(V_{jj}>0\). \(\boldsymbol{V}\boldsymbol{X}^T\boldsymbol{X}=\boldsymbol{I}\).
Example Added
Use \(\boldsymbol{X}^T\boldsymbol{X}=\left[\begin{array}{cc}5&15\\15&55\end{array}\right]\) (Section 5.3) and the \(2\times2\) inverse:
\[\left[\begin{array}{cc}a&b\\c&d\end{array}\right]^{-1}=\frac{1}{ad-bc}\left[\begin{array}{cc}d&-b\\-c&a\end{array}\right]\]\(\hat\sigma^2\) How step 1
Determinant How step 2
\(\boldsymbol{V}\) How step 2
Check: \(1.1(5)-0.3(15)=5.5-4.5=1\).
Multiply How step 3
Square root How step 4
3 degrees of freedom. Lecture 7 uses these. ▲
Why Added
p.27.
Diagonal entry \(j\) (p.29).
Put in \(\hat\sigma^2\) for unknown \(\sigma^2\). ∎
05.5Practice Slides p.39–41
All questions use \(p=1\): simple linear regression (SLR). Lecture 2 notation: \(\bar x=\frac1n\sum x_i\), \(\bar y=\frac1n\sum y_i\), \(S_{xx}=\sum_{i=1}^n(x_i-\bar x)^2\), \(S_{xy}=\sum_{i=1}^n(x_i-\bar x)(y_i-\bar y)\).
Five-point data: \(\bar x=15/5=3\), \(\bar y=20/5=4\).
Q1 Slides p.40
Answer Q1
Plan: invert \(\boldsymbol{X}^T\boldsymbol{X}\), multiply by \(\boldsymbol{X}^T\boldsymbol{y}\), write the sums with \(S_{xx}\) and \(S_{xy}\). First, two identities:
\(\sum x_i=n\bar x\).
Use the \(2\times2\) inverse rule of Section 05.4.
Identity a.
Row 2: \(\hat\beta_1\)
\(\sum x_i=n\bar x\), \(\sum y_i=n\bar y\), then identity b.
Row 1: \(\hat\beta_0\)
Identities a and b in reverse.
The Lecture 2 formula. ∎
Numerical check (five-point data). \(n=5\), \(\sum x_i=15\), \(\sum x_i^2=55\), \(\sum y_i=20\), \(\sum x_iy_i=66\).
Q2 Slides p.41
Answer Q2
\(\mathrm{cov}(U,W)=E[(U-E[U])(W-E[W])]\). The "above" matrix is \(\mathrm{Var}[\hat{\boldsymbol\beta}]=\sigma^2(\boldsymbol{X}^T\boldsymbol{X})^{-1}\) (p.27). Its off-diagonal entry is \(\mathrm{cov}(\hat\beta_0,\hat\beta_1)\).
Q1, step 2.
Row 1, column 2.
Negative when \(\bar x>0\). ∎
The fitted line goes through \((\bar x,\bar y)\) (Figure 5-1). A larger \(\hat\beta_1\) gives a smaller \(\hat\beta_0=\bar y-\hat\beta_1\bar x\).
Numerical check (five-point data). Use \(\hat\sigma^2=0.8\) for \(\sigma^2\).
Q3 Added
Data: \(n=4\), \(x=(0,1,2,3)\), \(y=(1,3,2,6)\). Fitted line: \(\hat y=0.9+1.4x\). (a) Calculate \(\boldsymbol{e}^T\boldsymbol{e}\), \(\hat\sigma^2_{MLE}\), and \(\hat\sigma^2\). (b) Calculate \(S_{xx}\) and \(\mathrm{SE}(\hat\beta_1)=\sqrt{\hat\sigma^2V_{11}}\). (c) Calculate \(\mathrm{cov}(\hat\beta_0,\hat\beta_1)\) with \(\hat\sigma^2\) for \(\sigma^2\).
Answer Q3
(a) Fitted values 05.1 How step 1
(a) Residuals 05.1 How step 2
Check: \(\sum e_i=0.1+0.7-1.7+0.9=0\), \(\sum x_ie_i=0+0.7-3.4+2.7=0\).
(a) Residual sum of squares 05.1 How step 3
(a) MLE 05.1 How step 4
(a) Unbiased estimate 05.2 How
Check: \(2.1/1.05=2=4/2=n/(n-p-1)\).
(b) \(S_{xx}\) and \(V_{11}\) Q1 step 2
Bottom-right entry of the Q1 inverse.
(b) SE 05.4 How steps 3–4
SLR form: \(\hat\sigma/\sqrt{S_{xx}}=\sqrt{2.1}/\sqrt{5}=1.4491/2.2361=0.6481\).
(c) Covariance Q2 step 5
Negative because \(\bar x=1.5>0\). ▲