Skip to the content

Topics Covered

Partition Method Sweep-Out Doolittle LU Moore–Penrose g-Inverse Trace Method Covariance Matrix Lack of Fit Partial Correlation VIF
On this page
  1. Objectives
  2. The Fourteen Practicals
  3. Practical 1 — Inverse by the Partition Method
  4. Practical 2 — Solution of Linear Equations by the Sweep-Out Method
  5. Practical 3 — Solution of Linear Equations by the Doolittle Method
  6. Practical 4 — Moore–Penrose Inverse by the Penrose Method
  7. Practical 5 — Generalized Inverse of a Matrix
  8. Practical 6 — Characteristic Equation from Traces of Successive Powers
  9. Practical 7 — Spectral Decomposition of a Third-Order Matrix
  10. Practical 8 — Simultaneous Reduction of a Pair of Quadratic Forms
  11. Practical 9 — Orthonormal Basis by the Gram–Schmidt Process
  12. Practical 10 — The Variance–Covariance Matrix and Its Characteristics
  13. Practical 11 — Simple Linear Regression with Lack of Fit
  14. Practical 12 — Multiple Linear Regression
  15. Practical 13 — Simple, Partial and Multiple Correlation
  16. Practical 14 — Testing Multicollinearity
  17. What the Practical Record Should Contain
About this course. STS-106 is a practical examined in two sections — Section A conventional (by hand) and Section B using R. Its own note says the R must be written without using packages, so every program below builds the method from arithmetic rather than calling a library routine. Where R has a built-in that does the same job it is shown too, as a check on the hand-written version.

Objectives

  1. Knowing the computational procedures and also their implementation using R.
  2. Finding the inverse of a matrix using various methods.
  3. Applying transformations on matrices.
  4. Applying matrix operations to given data sets — determinant, eigenvalues, eigenvectors, transformations.
  5. Summarizing the properties of data sets based on matrix operations.

The Fourteen Practicals

All fourteen are worked below, each set out as 1. Problem, 2. Aim, 3. Formula, 4. Calculation, 5. Result, with the R program (written without packages) and its real output inside the Calculation.

#PracticalWorked hereAlso in
1Inverse of a matrix by the partition methodPractical 1—
2Solutions of linear equations by the sweep-out methodPractical 2—
3Solutions of linear equations by the Doolittle methodPractical 3—
4Moore–Penrose inverse by the Penrose methodPractical 4Unit 1, Example 1.3
5Generalized inverse of a matrixPractical 5—
6Characteristic equation from traces of successive powersPractical 6Unit 2, Example 2.1
7Spectral decomposition of a third-order square matrixPractical 7Unit 2, Example 2.4
8Simultaneous reduction of a pair of quadratic formsPractical 8Unit 3, Example 3.3
9Orthonormal basis by the Gram–Schmidt processPractical 9Unit 1, Example 1.1
10Variance–covariance matrix and its characteristicsPractical 10—
11Simple linear regression, lack of fit, R², adjusted R², pure error, CIPractical 11—
12Multiple linear regression, the same quantitiesPractical 12—
13Simple, partial and multiple correlation coefficientsPractical 13—
14Testing multicollinearityPractical 14Unit 4, Example 4.2
ONE MATRIX RUNS THROUGH PRACTICALS 1, 2, 3, 6 AND 7

All five use

\[ A = \begin{pmatrix} 2 & 1 & 1 \\ 1 & 2 & 1 \\ 1 & 1 & 2 \end{pmatrix}, \qquad \mathbf{b} = \begin{pmatrix} 7 \\ 8 \\ 9 \end{pmatrix}, \]

so five different methods can be checked against one another instead of each being taken on trust. The answers they must all reproduce are \(\det A = 4\), \(\mathbf{x} = (1, 2, 3)'\), and

\[ A^{-1} = \frac{1}{4}\begin{pmatrix} 3 & -1 & -1 \\ -1 & 3 & -1 \\ -1 & -1 & 3 \end{pmatrix}. \]

Practical 1 — Inverse by the Partition Method

1. Problem

Find the inverse of \(A = \begin{pmatrix} 2 & 1 & 1 \\ 1 & 2 & 1 \\ 1 & 1 & 2 \end{pmatrix}\) by the partition method.

2. Aim

To invert a matrix by partitioning it into blocks and inverting the smaller pieces.

3. Formula

\[ A = \begin{pmatrix} A_{11} & A_{12} \\ A_{21} & A_{22} \end{pmatrix}, \quad S = A_{22} - A_{21}A_{11}^{-1}A_{12}, \] \[ B_{22} = S^{-1}, \quad B_{12} = -A_{11}^{-1}A_{12}S^{-1}, \quad B_{21} = -S^{-1}A_{21}A_{11}^{-1}, \quad B_{11} = A_{11}^{-1} + A_{11}^{-1}A_{12}S^{-1}A_{21}A_{11}^{-1} \]

\(S\) is the Schur complement of \(A_{11}\).

Applying it:

  1. Partition, taking \(A_{11}\) as the leading \(2 \times 2\).
  2. Invert \(A_{11}\).
  3. Form the Schur complement and its inverse.
  4. The off-diagonal blocks, then the leading block.
  5. Assemble and check \(AA^{-1} = I\).

4. Calculation

\[ A_{11} = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}, \quad A_{12} = \begin{pmatrix} 1 \\ 1 \end{pmatrix}, \quad A_{21} = \begin{pmatrix} 1 & 1 \end{pmatrix}, \quad A_{22} = \begin{pmatrix} 2 \end{pmatrix}; \qquad A_{11}^{-1} = \frac{1}{3}\begin{pmatrix} 2 & -1 \\ -1 & 2 \end{pmatrix}. \] \[ A_{11}^{-1}A_{12} = \frac{1}{3}\begin{pmatrix} 1 \\ 1 \end{pmatrix}, \quad A_{21}A_{11}^{-1}A_{12} = \frac23, \quad S = 2 - \frac23 = \frac43, \quad S^{-1} = \frac34. \] \[ B_{12} = -\frac{1}{3}\begin{pmatrix} 1 \\ 1 \end{pmatrix}\times\frac34 = \begin{pmatrix} -\tfrac14 \\ -\tfrac14 \end{pmatrix}, \qquad B_{21} = \begin{pmatrix} -\tfrac14 & -\tfrac14 \end{pmatrix} \ \text{(by symmetry)}, \] \[ B_{11} = \frac{1}{3}\begin{pmatrix} 2 & -1 \\ -1 & 2 \end{pmatrix} + \frac{1}{12}\begin{pmatrix} 1 & 1 \\ 1 & 1 \end{pmatrix} = \begin{pmatrix} \tfrac34 & -\tfrac14 \\ -\tfrac14 & \tfrac34 \end{pmatrix}, \]

since \(\tfrac23 + \tfrac1{12} = \tfrac34\) and \(-\tfrac13 + \tfrac1{12} = -\tfrac14\).

CHECK IN R
A <- matrix(c(2,1,1, 1,2,1, 1,1,2), 3, 3, byrow = TRUE)
A11 <- A[1:2, 1:2]; A12 <- A[1:2, 3, drop = FALSE]; A21 <- A[3, 1:2, drop = FALSE]; A22 <- A[3, 3, drop = FALSE]
A11i <- solve(A11); S <- A22 - A21 %*% A11i %*% A12; Si <- solve(S)
B12 <- -A11i %*% A12 %*% Si; B21 <- -Si %*% A21 %*% A11i
B11 <- A11i + A11i %*% A12 %*% Si %*% A21 %*% A11i
Ainv <- rbind(cbind(B11, B12), cbind(B21, Si)); Ainv * 4
round(max(abs(A %*% Ainv - diag(3))), 10)   # 0 -- A times its inverse is I
     [,1] [,2] [,3]
[1,]    3   -1   -1
[2,]   -1    3   -1
[3,]   -1   -1    3
[1] 0

5. Result

\[ A^{-1} = \frac{1}{4}\begin{pmatrix} 3 & -1 & -1 \\ -1 & 3 & -1 \\ -1 & -1 & 3 \end{pmatrix}, \]

the matrix obtained in Unit 2 by Cayley–Hamilton and again by spectral decomposition (Practical 7): three independent routes, one answer. \(\checkmark\)

Practical 2 — Solution of Linear Equations by the Sweep-Out Method

1. Problem

Solve \(A\mathbf{x} = \mathbf{b}\) by the sweep-out (Gauss–Jordan) method, where \(A = \begin{pmatrix} 2 & 1 & 1 \\ 1 & 2 & 1 \\ 1 & 1 & 2 \end{pmatrix}\) and \(\mathbf{b} = (7, 8, 9)'\).

2. Aim

To solve a system of linear equations by sweeping the augmented matrix to the identity.

3. Formula

\[ \left(A \mid \mathbf{b}\right) \;\longrightarrow\; \left(I \mid \mathbf{x}\right) \]

At each step, divide the pivot row by the pivot, then subtract multiples of it from every other row so that its column becomes a unit vector. Augmenting with \(I\) instead of \(\mathbf{b}\) produces \(A^{-1}\) with identical work.

Applying it:

  1. First pivot: \(R_1 \div 2\); \(R_2 - R_1\), \(R_3 - R_1\).
  2. Second pivot: \(R_2 \div \tfrac32\); \(R_1 - \tfrac12R_2\), \(R_3 - \tfrac12R_2\).
  3. Third pivot: \(R_3 \div \tfrac43\); \(R_1 - \tfrac13R_3\), \(R_2 - \tfrac13R_3\).
  4. Read \(\mathbf{x}\) and substitute back.

4. Calculation

\[ \left(\begin{array}{ccc|c} 2 & 1 & 1 & 7 \\ 1 & 2 & 1 & 8 \\ 1 & 1 & 2 & 9 \end{array}\right) \to \left(\begin{array}{ccc|c} 1 & \tfrac12 & \tfrac12 & \tfrac72 \\ 0 & \tfrac32 & \tfrac12 & \tfrac92 \\ 0 & \tfrac12 & \tfrac32 & \tfrac{11}{2} \end{array}\right) \to \left(\begin{array}{ccc|c} 1 & 0 & \tfrac13 & \tfrac53 \\ 0 & 1 & \tfrac13 & 3 \\ 0 & 0 & \tfrac43 & 4 \end{array}\right) \to \left(\begin{array}{ccc|c} 1 & 0 & 0 & 1 \\ 0 & 1 & 0 & 2 \\ 0 & 0 & 1 & 3 \end{array}\right) \]

Substituting back: \(2(1)+2+3 = 7\), \(1+2(2)+3 = 8\), \(1+2+2(3) = 9\). \(\checkmark\)

CHECK IN R
A <- matrix(c(2,1,1, 1,2,1, 1,1,2), 3, 3, byrow = TRUE)
sweep <- function(M) {                 # Gauss-Jordan on an augmented matrix
  for (k in seq_len(nrow(M))) {
    M[k, ] <- M[k, ] / M[k, k]
    for (i in seq_len(nrow(M))[-k]) M[i, ] <- M[i, ] - M[i, k] * M[k, ]
  }
  M
}
sweep(cbind(A, c(7, 8, 9)))[, 4]       # the solution
sweep(cbind(A, diag(3)))[, 4:6] * 4    # and, augmenting with I, 4 times the inverse
[1] 1 2 3
     [,1] [,2] [,3]
[1,]    3   -1   -1
[2,]   -1    3   -1
[3,]   -1   -1    3

5. Result

\(\mathbf{x} = (1, 2, 3)'\). The same sweep, applied to \((A \mid I)\), gives \(A^{-1}\) of Practical 1.

Practical 3 — Solution of Linear Equations by the Doolittle Method

1. Problem

Solve \(A\mathbf{x} = \mathbf{b}\) with \(A = \begin{pmatrix} 2 & 1 & 1 \\ 1 & 2 & 1 \\ 1 & 1 & 2 \end{pmatrix}\) and \(\mathbf{b} = (7, 8, 9)'\) by the Doolittle (LU) method, and find \(\det A\).

2. Aim

To factorise a matrix into unit lower and upper triangular factors once, and solve by forward and back substitution.

3. Formula

\[ A = LU, \quad u_{ij} = a_{ij} - \sum_{k<i}\ell_{ik}u_{kj} \ (j \ge i), \quad \ell_{ji} = \frac{a_{ji} - \sum_{k<i}\ell_{jk}u_{ki}}{u_{ii}} \ (j > i); \qquad L\mathbf{z} = \mathbf{b}, \ U\mathbf{x} = \mathbf{z}; \qquad \det A = \prod_i u_{ii} \]

Applying it:

  1. The first row of \(U\) and first column of \(L\).
  2. The second row and column; then \(u_{33}\).
  3. Check \(LU = A\) on one entry.
  4. Forward substitution, then back substitution.

4. Calculation

\(u_{1j} = a_{1j}\): first row of \(U\) is \((2, 1, 1)\); \(\ell_{21} = \ell_{31} = \tfrac12\).

\[ u_{22} = 2 - \tfrac12 = \tfrac32, \quad u_{23} = 1 - \tfrac12 = \tfrac12, \quad \ell_{32} = \frac{1 - \tfrac12}{\tfrac32} = \frac13, \quad u_{33} = 2 - \tfrac12 - \tfrac13\left(\tfrac12\right) = \tfrac43. \] \[ L = \begin{pmatrix} 1 & 0 & 0 \\ \tfrac12 & 1 & 0 \\ \tfrac12 & \tfrac13 & 1 \end{pmatrix}, \qquad U = \begin{pmatrix} 2 & 1 & 1 \\ 0 & \tfrac32 & \tfrac12 \\ 0 & 0 & \tfrac43 \end{pmatrix}. \]

Check: row 3 of \(L\) against column 3 of \(U\): \(\tfrac12 + \tfrac16 + \tfrac43 = 2 = a_{33}\). \(\checkmark\)

\[ z_1 = 7, \quad z_2 = 8 - \tfrac72 = \tfrac92, \quad z_3 = 9 - \tfrac72 - \tfrac32 = 4; \qquad x_3 = \frac{4}{\tfrac43} = 3, \quad x_2 = \frac{\tfrac92 - \tfrac32}{\tfrac32} = 2, \quad x_1 = \frac{7 - 2 - 3}{2} = 1. \]
CHECK IN R
A <- matrix(c(2,1,1, 1,2,1, 1,1,2), 3, 3, byrow = TRUE)
doolittle <- function(A) {             # Doolittle LU, written out rather than calling a library
  n <- nrow(A); L <- diag(n); U <- matrix(0, n, n)
  for (i in 1:n) {
    for (j in i:n) U[i, j] <- A[i, j] - sum(L[i, ] * U[, j])
    if (i < n) for (j in (i+1):n)
      L[j, i] <- (A[j, i] - sum(L[j, ] * U[, i])) / U[i, i]
  }
  list(L = L, U = U)
}
lu <- doolittle(A); lu$L; lu$U
max(abs(lu$L %*% lu$U - A))          # 0 -- the factorisation is exact
z <- forwardsolve(lu$L, c(7, 8, 9)); backsolve(lu$U, z)
prod(diag(lu$U))                     # det(A)
     [,1]      [,2] [,3]
[1,]  1.0 0.0000000    0
[2,]  0.5 1.0000000    0
[3,]  0.5 0.3333333    1
     [,1] [,2]     [,3]
[1,]    2  1.0 1.000000
[2,]    0  1.5 0.500000
[3,]    0  0.0 1.333333
[1] 0
[1] 1 2 3
[1] 4

5. Result

\(\mathbf{x} = (1, 2, 3)'\) and \(\det A = 1 \times 2 \times \tfrac32 \times \tfrac43 = 4\). Factorise once and any number of right-hand sides cost only the two substitutions — which is why this, and not Gauss–Jordan, is what numerical libraries do.

Practical 4 — Moore–Penrose Inverse by the Penrose Method

1. Problem

Find the Moore–Penrose inverse of \(A = \begin{pmatrix} 1 & 0 \\ 0 & 1 \\ 1 & 1 \end{pmatrix}\) and verify the four Penrose conditions.

2. Aim

To find the Moore–Penrose inverse of a matrix of full column rank and verify that it satisfies all four Penrose conditions.

3. Formula

\[ \text{full column rank: } A^{+} = (A'A)^{-1}A'; \qquad \text{(i) } AA^{+}A = A, \ \text{(ii) } A^{+}AA^{+} = A^{+}, \ \text{(iii) } (AA^{+})' = AA^{+}, \ \text{(iv) } (A^{+}A)' = A^{+}A \]

Applying it:

  1. Check the rank.
  2. Form and invert \(A'A\); multiply by \(A'\).
  3. Form \(A^{+}A\) and \(AA^{+}\); check the four conditions.

4. Calculation

The two columns are not multiples of one another, so \(\operatorname{rank}(A) = 2\), full column rank.

\[ A'A = \begin{pmatrix} 2 & 1 \\ 1 & 2 \end{pmatrix}, \quad (A'A)^{-1} = \frac13\begin{pmatrix} 2 & -1 \\ -1 & 2 \end{pmatrix}, \quad A^{+} = \frac{1}{3}\begin{pmatrix} 2 & -1 & 1 \\ -1 & 2 & 1 \end{pmatrix}. \] \[ A^{+}A = I_2, \qquad AA^{+} = \frac{1}{3}\begin{pmatrix} 2 & -1 & 1 \\ -1 & 2 & 1 \\ 1 & 1 & 2 \end{pmatrix}, \quad \operatorname{trace}(AA^{+}) = 2. \]
conditioncheckholds?
(i) \(AA^{+}A = A\)\(A(A^{+}A) = A I_2 = A\)yes
(ii) \(A^{+}AA^{+} = A^{+}\)\(I_2 A^{+} = A^{+}\)yes
(iii) \((AA^{+})' = AA^{+}\)\(AA^{+}\) is symmetricyes
(iv) \((A^{+}A)' = A^{+}A\)\(I_2\) is symmetricyes
CHECK IN R
A <- matrix(c(1,0, 0,1, 1,1), 3, 2, byrow = TRUE)
Ap <- solve(t(A) %*% A) %*% t(A); Ap * 3
c(i = max(abs(A %*% Ap %*% A - A)), ii = max(abs(Ap %*% A %*% Ap - Ap)),
  iii = max(abs(t(A %*% Ap) - A %*% Ap)), iv = max(abs(t(Ap %*% A) - Ap %*% A)))   # all 0
sum(diag(A %*% Ap))                  # the trace of the projection = rank
     [,1] [,2] [,3]
[1,]    2   -1    1
[2,]   -1    2    1
  i  ii iii  iv 
  0   0   0   0 
[1] 2

5. Result

\(A^{+} = \frac13\begin{pmatrix} 2 & -1 & 1 \\ -1 & 2 & 1 \end{pmatrix}\), satisfying all four conditions. \(AA^{+}\) is not \(I_3\) and could not be (its rank is 2): it is the projection onto the column space of \(A\), with trace 2 = rank. Applied to \(\mathbf{y}\), \(A^{+}\) returns the least-squares coefficients (worked also in Unit 1, Example 1.3).

Practical 5 — Generalized Inverse of a Matrix

1. Problem

Find a generalized inverse of the singular matrix \(S = \begin{pmatrix} 1 & 1 & 0 \\ 1 & 1 & 0 \\ 0 & 0 & 2 \end{pmatrix}\), and check whether it is the Moore–Penrose inverse.

2. Aim

To construct a generalized inverse of a singular matrix from a non-singular submatrix, and to see that it need not be the Moore–Penrose inverse.

3. Formula

\[ SGS = S; \qquad G = \text{(inverse of a non-singular } r \times r \text{ submatrix, transposed back into place, zeros elsewhere)} \]

Here \(\det S = 0\) and \(\operatorname{rank}(S) = 2\).

Applying it:

  1. Find a non-singular \(2 \times 2\) submatrix and invert it.
  2. Place its entries back in the transposed positions, zeros elsewhere.
  3. Verify \(SGS = S\); then test the other Penrose conditions.

4. Calculation

Rows 1 and 3, columns 1 and 3: \(\begin{pmatrix} 1 & 0 \\ 0 & 2 \end{pmatrix}\), \(\det = 2\), inverse \(\begin{pmatrix} 1 & 0 \\ 0 & \tfrac12 \end{pmatrix}\). Placing it back:

\[ G = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & \tfrac12 \end{pmatrix}, \qquad SG = \begin{pmatrix} 1 & 0 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 1 \end{pmatrix}, \qquad (SG)S = S. \checkmark \]

\(GSG = G\) also holds, so \(G\) is reflexive. But \((SG)' = \begin{pmatrix} 1 & 1 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 1 \end{pmatrix} \ne SG\): condition (iii) fails.

CHECK IN R
ginv_sub <- function(S, rows, cols) {   # a g-inverse from a non-singular submatrix
  G <- matrix(0, ncol(S), nrow(S))
  G[cols, rows] <- solve(S[rows, cols])
  G
}
S <- matrix(c(1,1,0, 1,1,0, 0,0,2), 3, 3, byrow = TRUE)
G <- ginv_sub(S, c(1, 3), c(1, 3)); G
max(abs(S %*% G %*% S - S))          # 0 -- condition (i) holds
max(abs(G %*% S %*% G - G))          # 0 -- and (ii): G is reflexive
isTRUE(all.equal(t(S %*% G), S %*% G))   # FALSE -- so NOT Moore-Penrose
     [,1] [,2] [,3]
[1,]    1    0  0.0
[2,]    0    0  0.0
[3,]    0    0  0.5
[1] 0
[1] 0
[1] FALSE

5. Result

\(G\) is a (reflexive) generalized inverse of \(S\) but not its Moore–Penrose inverse. There are many g-inverses — a different submatrix gives a different \(G\), and every one satisfies \(SGS = S\); the Moore–Penrose inverse is the single one that is also symmetric in both products. In Unit 4 that non-uniqueness is why \(\hat{\boldsymbol\beta}\) is not unique in a rank-deficient model while \(\boldsymbol\ell'\hat{\boldsymbol\beta}\) for estimable \(\boldsymbol\ell\) is.

Practical 6 — Characteristic Equation from Traces of Successive Powers

1. Problem

Find the characteristic equation of \(A = \begin{pmatrix} 2 & 1 & 1 \\ 1 & 2 & 1 \\ 1 & 1 & 2 \end{pmatrix}\) from the traces of its powers, its roots, and its eigenvectors.

2. Aim

To obtain the characteristic equation of a matrix from the traces of its successive powers, and its roots and vectors.

3. Formula

\[ \lambda^{3} - c_1\lambda^{2} + c_2\lambda - c_3 = 0, \qquad c_1 = t_1, \quad c_2 = \frac{c_1t_1 - t_2}{2}, \quad c_3 = \frac{c_2t_1 - c_1t_2 + t_3}{3}, \qquad t_k = \operatorname{trace}(A^{k}) \]

Checks: \(c_3 = \det A\); the roots sum to the trace and multiply to the determinant.

Applying it:

  1. Compute \(A^{2}\), \(A^{3}\) and the three traces.
  2. The coefficients; the equation.
  3. Factorise; check.
  4. The eigenvectors from \((A - \lambda I)\mathbf{x} = \mathbf{0}\).

4. Calculation

\[ A^{2} = \begin{pmatrix} 6 & 5 & 5 \\ 5 & 6 & 5 \\ 5 & 5 & 6 \end{pmatrix}, \quad A^{3} = \begin{pmatrix} 22 & 21 & 21 \\ 21 & 22 & 21 \\ 21 & 21 & 22 \end{pmatrix}; \qquad t_1 = 6, \ t_2 = 18, \ t_3 = 66. \] \[ c_1 = 6, \quad c_2 = \frac{36 - 18}{2} = 9, \quad c_3 = \frac{54 - 108 + 66}{3} = 4; \qquad \lambda^{3} - 6\lambda^{2} + 9\lambda - 4 = (\lambda - 1)^{2}(\lambda - 4) = 0. \]

\(c_3 = 4 = \det A\); \(4 + 1 + 1 = 6\) and \(4 \times 1 \times 1 = 4\). \(\checkmark\) For \(\lambda = 4\): \(A - 4I\) has rank 2 and \(\mathbf{x} = (1, 1, 1)'\). For \(\lambda = 1\): \(A - I\) has rank 1, the single equation \(x_1 + x_2 + x_3 = 0\), and a basis \((-1, 1, 0)'\), \((-1, 0, 1)'\), both orthogonal to \((1, 1, 1)'\).

CHECK IN R
A <- matrix(c(2,1,1, 1,2,1, 1,1,2), 3, 3, byrow = TRUE)
tr <- function(M) sum(diag(M))       # characteristic equation from traces of powers
A2 <- A %*% A; A3 <- A2 %*% A
t1 <- tr(A); t2 <- tr(A2); t3 <- tr(A3)
c1 <- t1; c2 <- (c1*t1 - t2)/2; c3 <- (c2*t1 - c1*t2 + t3)/3
c(t1, t2, t3); c(c1, c2, c3)
Re(polyroot(c(-c3, c2, -c1, 1)))     # the roots
[1]  6 18 66
[1] 6 9 4
[1] 1 1 4

5. Result

The characteristic equation is \(\lambda^{3} - 6\lambda^{2} + 9\lambda - 4 = 0\), with roots 4 (vector \((1,1,1)'\)) and 1 twice (any vector with \(x_1 + x_2 + x_3 = 0\)) (worked also in Unit 2, Example 2.1).

Practical 7 — Spectral Decomposition of a Third-Order Matrix

1. Problem

Find the spectral decomposition of \(A = \begin{pmatrix} 2 & 1 & 1 \\ 1 & 2 & 1 \\ 1 & 1 & 2 \end{pmatrix}\) (roots 4 and 1, twice, from Practical 6), and from it \(A^{-1}\) and \(A^{1/2}\).

2. Aim

To write a symmetric matrix as a sum of its eigenvalues times the projections onto its eigenspaces, and use it for functions of the matrix.

3. Formula

\[ A = \sum_j \lambda_{(j)} P_j, \qquad P_j^{2} = P_j, \quad P_jP_k = O \ (j \ne k), \quad \sum_j P_j = I, \qquad A^{m} = \sum_j \lambda_{(j)}^{m}P_j \]

Applying it:

  1. The projection onto the \(\lambda = 4\) eigenspace, \(P_1 = \mathbf{v}\mathbf{v}'/\mathbf{v}'\mathbf{v}\).
  2. \(P_2 = I - P_1\).
  3. Check idempotence, orthogonality and the traces (the multiplicities).
  4. Reassemble \(A\); then \(m = -1\) and \(m = \tfrac12\).

4. Calculation

\[ P_1 = \frac{1}{3}J, \qquad P_2 = I - \frac{J}{3}, \qquad J = \mathbf{1}\mathbf{1}', \ J^{2} = 3J. \] \[ P_1^{2} = \frac{3J}{9} = P_1, \quad \operatorname{tr}P_1 = 1; \qquad P_2^{2} = I - \frac{2J}{3} + \frac{J}{3} = P_2, \quad \operatorname{tr}P_2 = 2; \qquad P_1P_2 = O. \checkmark \] \[ 4P_1 + P_2 = I + J = A. \checkmark \qquad A^{-1} = \tfrac14P_1 + P_2 = I - \frac{J}{4}, \qquad A^{1/2} = 2P_1 + P_2 = I + \frac{J}{3}. \]

\((I + J/3)^{2} = I + 2J/3 + J/3 = I + J = A\). \(\checkmark\)

CHECK IN R
A <- matrix(c(2,1,1, 1,2,1, 1,1,2), 3, 3, byrow = TRUE)
J <- matrix(1, 3, 3); P1 <- J / 3; P2 <- diag(3) - J / 3
round(max(abs(4 * P1 + P2 - A)), 10)   # 0 -- the decomposition reproduces A
round(c(max(abs(P1 %*% P1 - P1)), max(abs(P1 %*% P2))), 10)   # idempotent, orthogonal
round(max(abs((P1 / 4 + P2) - solve(A))), 10)   # 0 -- the inverse
R <- 2 * P1 + P2; R; round(max(abs(R %*% R - A)), 10)   # the square root, and its square
[1] 0
[1] 0 0
[1] 0
          [,1]      [,2]      [,3]
[1,] 1.3333333 0.3333333 0.3333333
[2,] 0.3333333 1.3333333 0.3333333
[3,] 0.3333333 0.3333333 1.3333333
[1] 0

5. Result

\(A = 4\cdot\frac{J}{3} + 1\cdot\left(I - \frac{J}{3}\right)\); hence \(A^{-1} = I - J/4\) (diagonal \(\tfrac34\), off-diagonal \(-\tfrac14\), as in Practical 1) and \(A^{1/2} = I + J/3\). Every function of \(A\) comes from one decomposition (worked also in Unit 2, Example 2.4).

Practical 8 — Simultaneous Reduction of a Pair of Quadratic Forms

1. Problem

Reduce the quadratic forms \(\mathbf{x}'A\mathbf{x}\) and \(\mathbf{x}'B\mathbf{x}\) simultaneously, where \(A = \begin{pmatrix} 5 & 2 \\ 2 & 2 \end{pmatrix}\) and \(B = \begin{pmatrix} 2 & 1 \\ 1 & 1 \end{pmatrix}\).

2. Aim

To reduce two quadratic forms, one positive definite, to sums of squares by one transformation.

3. Formula

\[ |A - \lambda B| = 0; \qquad \mathbf{x}'B\mathbf{x} = \sum y_i^{2}, \quad \mathbf{x}'A\mathbf{x} = \sum \lambda_i y_i^{2} \]

\(B\) must be positive definite.

Applying it:

  1. Check \(B\) (and \(A\)) positive definite by leading minors.
  2. Form \(|A - \lambda B|\); factor out the common term.
  3. Verify each root; write the canonical forms.

4. Calculation

\(B\): \(2 > 0\), \(\det B = 1 > 0\); \(A\): \(5 > 0\), \(\det A = 6 > 0\). \(\checkmark\)

\[ |A - \lambda B| = (5 - 2\lambda)(2 - \lambda) - (2 - \lambda)^{2} = (2 - \lambda)\left[(5 - 2\lambda) - (2 - \lambda)\right] = (2 - \lambda)(3 - \lambda). \] \[ A - 2B = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix}, \ \det = 0; \qquad A - 3B = \begin{pmatrix} -1 & -1 \\ -1 & -1 \end{pmatrix}, \ \det = 0. \checkmark \]
CHECK IN R
A <- matrix(c(5, 2, 2, 2), 2); B <- matrix(c(2, 1, 1, 1), 2)
c(det(B), det(A))                    # both positive definite
eigen(solve(B) %*% A)$values         # the roots of |A - lambda B| = 0
c(det(A - 2 * B), det(A - 3 * B))    # both 0
[1] 1 6
[1] 3 2
[1] 0 0

5. Result

The roots are \(\lambda = 2, 3\), and the pair reduces to \(\mathbf{x}'B\mathbf{x} = y_1^{2} + y_2^{2}\), \(\mathbf{x}'A\mathbf{x} = 2y_1^{2} + 3y_2^{2}\). The ratio \(\mathbf{x}'A\mathbf{x}/\mathbf{x}'B\mathbf{x}\) therefore ranges over \([2, 3]\) and no further — in a discriminant problem, the smallest and largest achievable separation (worked also in Unit 3, Example 3.3).

Practical 9 — Orthonormal Basis by the Gram–Schmidt Process

1. Problem

Construct an orthonormal basis of \(\mathbb{R}^{3}\) from \(\mathbf{v}_1 = (1,1,0)'\), \(\mathbf{v}_2 = (1,0,1)'\), \(\mathbf{v}_3 = (0,1,1)'\).

2. Aim

To turn a set of independent vectors into an orthonormal basis of the same space.

3. Formula

\[ \mathbf{u}_1 = \mathbf{v}_1, \qquad \mathbf{u}_k = \mathbf{v}_k - \sum_{j<k}\frac{\mathbf{v}_k'\mathbf{u}_j}{\mathbf{u}_j'\mathbf{u}_j}\mathbf{u}_j, \qquad \mathbf{e}_k = \frac{\mathbf{u}_k}{\|\mathbf{u}_k\|} \]

Applying it:

  1. Take \(\mathbf{u}_1 = \mathbf{v}_1\).
  2. Subtract from \(\mathbf{v}_2\) its projection on \(\mathbf{u}_1\); check orthogonality.
  3. Subtract from \(\mathbf{v}_3\) its projections on \(\mathbf{u}_1\) and \(\mathbf{u}_2\); check.
  4. Normalise.

4. Calculation

\[ \mathbf{u}_1 = (1,1,0)', \ \mathbf{u}_1'\mathbf{u}_1 = 2; \qquad \mathbf{u}_2 = (1,0,1)' - \tfrac12(1,1,0)' = \left(\tfrac12, -\tfrac12, 1\right)', \ \mathbf{u}_2'\mathbf{u}_2 = \tfrac32, \ \mathbf{u}_1'\mathbf{u}_2 = 0. \checkmark \] \[ \mathbf{u}_3 = (0,1,1)' - \tfrac12(1,1,0)' - \tfrac13\left(\tfrac12,-\tfrac12,1\right)' = \left(-\tfrac23, \tfrac23, \tfrac23\right)', \quad \mathbf{u}_3'\mathbf{u}_3 = \tfrac43; \quad \mathbf{u}_1'\mathbf{u}_3 = \mathbf{u}_2'\mathbf{u}_3 = 0. \checkmark \] \[ \mathbf{e}_1 = \frac{1}{\sqrt{2}}(1,1,0)', \qquad \mathbf{e}_2 = \frac{1}{\sqrt{6}}(1,-1,2)', \qquad \mathbf{e}_3 = \frac{1}{\sqrt{3}}(-1,1,1)'. \]
CHECK IN R
gram_schmidt <- function(V) {          # columns of V in, orthonormal columns out
  E <- V
  for (k in seq_len(ncol(V))) {
    u <- V[, k]
    for (j in seq_len(k - 1)) u <- u - sum(V[, k] * E[, j]) * E[, j]
    E[, k] <- u / sqrt(sum(u^2))
  }
  E
}
V <- cbind(c(1, 1, 0), c(1, 0, 1), c(0, 1, 1))
E <- gram_schmidt(V); round(E, 6)
round(t(E) %*% E, 10)                # the identity: orthonormal
         [,1]      [,2]     [,3]
[1,] 0.707107  0.408248 -0.57735
[2,] 0.707107 -0.408248  0.57735
[3,] 0.000000  0.816497  0.57735
     [,1] [,2] [,3]
[1,]    1    0    0
[2,]    0    1    0
[3,]    0    0    1

5. Result

\(\{\mathbf{e}_1, \mathbf{e}_2, \mathbf{e}_3\}\) above is an orthonormal basis: \(E'E = I\). The starting vectors were independent but at \(60^{\circ}\) to one another; the output is a genuine set of coordinate axes for the same space — the construction that, as the Helmert matrix, makes the sample mean and variance independent (worked also in Unit 1, Example 1.1).

Practical 10 — The Variance–Covariance Matrix and Its Characteristics

1. Problem

Five units are measured on three variables:

unit12345mean
\(x_1\)2468106.0
\(x_2\)132543.0
\(x_3\)546585.6

Find the variance–covariance matrix, its trace and determinant, and the correlation matrix, and interpret them.

2. Aim

To compute the variance–covariance matrix of a data set and read the data's spread from its trace, determinant and correlations.

3. Formula

\[ s_{jk} = \frac{1}{n-1}\sum_i(x_{ij} - \bar x_j)(x_{ik} - \bar x_k), \qquad \operatorname{tr}S = \sum s_{jj}, \qquad |S| \le \prod_j s_{jj} \ \text{(Hadamard)}, \qquad r_{jk} = \frac{s_{jk}}{\sqrt{s_{jj}s_{kk}}} \]

Applying it:

  1. Compute each entry from the deviations.
  2. Trace (total variance) and determinant (generalized variance); compare with \(\prod s_{jj}\).
  3. Divide by the standard deviations for the correlation matrix.

4. Calculation

\[ s_{11} = \frac{16 + 4 + 0 + 4 + 16}{4} = 10, \qquad s_{12} = \frac{(-4)(-2) + (-2)(0) + (0)(-1) + (2)(2) + (4)(1)}{4} = \frac{16}{4} = 4, \] \[ S = \begin{pmatrix} 10.0 & 4.0 & 3.5 \\ 4.0 & 2.5 & 0.5 \\ 3.5 & 0.5 & 2.3 \end{pmatrix}; \qquad \operatorname{tr}S = 14.8, \quad \det S = 1.575, \quad \prod_j s_{jj} = 57.5. \] \[ R = \begin{pmatrix} 1.000000 & 0.800000 & 0.729800 \\ 0.800000 & 1.000000 & 0.208514 \\ 0.729800 & 0.208514 & 1.000000 \end{pmatrix}. \]
CHECK IN R
X <- cbind(c(2,4,6,8,10), c(1,3,2,5,4), c(5,4,6,5,8))
S <- cov(X); S
c(trace = sum(diag(S)), det = det(S), prod_diag = prod(diag(S)))
round(cov2cor(S), 6)
     [,1] [,2] [,3]
[1,] 10.0  4.0  3.5
[2,]  4.0  2.5  0.5
[3,]  3.5  0.5  2.3
    trace       det prod_diag 
   14.800     1.575    57.500 
       [,1]     [,2]     [,3]
[1,] 1.0000 0.800000 0.729800
[2,] 0.8000 1.000000 0.208514
[3,] 0.7298 0.208514 1.000000

5. Result

Total variance 14.8; generalized variance 1.575, against 57.5 for uncorrelated variables with these variances (Hadamard's inequality, \(1.575 \le 57.5\)): the correlations have collapsed the cloud to under 3% of that volume. \(x_1\) is strongly related to both others, but \(x_2\) and \(x_3\) are almost unrelated to each other (\(r = 0.2085\)): their apparent connection runs through \(x_1\), which is what the partial correlations of Practical 13 are designed to expose.

Practical 11 — Simple Linear Regression with Lack of Fit

1. Problem

Eight observations at four distinct \(x\) values, two replicates each:

\(x\)11223344
\(y\)34678101113

Fit the simple linear regression; find \(R^{2}\), adjusted \(R^{2}\), a 95% confidence interval for the slope, and test for lack of fit using the pure error.

2. Aim

To fit a simple linear regression, measure its fit, and test whether a straight line is adequate by separating pure error from lack of fit.

3. Formula

\[ b_1 = \frac{S_{xy}}{S_{xx}}, \quad b_0 = \bar y - b_1\bar x, \quad SSR = b_1S_{xy}, \quad R^{2} = \frac{SSR}{S_{yy}}, \quad \bar R^{2} = 1 - (1 - R^{2})\frac{n-1}{n-2}, \quad b_1 \pm t_{n-2,\,0.025}\sqrt{\frac{MSE}{S_{xx}}} \] \[ SS_{PE} = \sum_{\text{groups}}\sum(y - \bar y_g)^{2} \ \text{ on } n - c, \qquad SS_{LOF} = SSE - SS_{PE} \ \text{ on } c - 2, \qquad F = \frac{MS_{LOF}}{MS_{PE}} \]

Applying it:

  1. The raw sums and the corrected sums of squares and products.
  2. The coefficients; the analysis of variance; \(R^{2}\) and \(\bar R^{2}\).
  3. The confidence interval for the slope.
  4. Pure error from the replicates; lack of fit by subtraction; the \(F\) test.

4. Calculation

\[ n = 8, \ \sum x = 20, \ \sum y = 62, \ \sum x^{2} = 60, \ \sum xy = 183, \ \sum y^{2} = 564; \qquad S_{xx} = 10, \ S_{xy} = 183 - 155 = 28, \ S_{yy} = 564 - 480.5 = 83.5. \] \[ b_1 = 2.8, \quad b_0 = 7.75 - 2.8(2.5) = 0.75; \qquad SSR = 78.4, \quad SSE = 5.1, \quad MSE = 0.85, \] \[ R^{2} = \frac{78.4}{83.5} = 0.938922, \qquad \bar R^{2} = 1 - (0.061078)\frac{7}{6} = 0.928743, \] \[ SE(b_1) = \sqrt{0.085} = 0.291548, \qquad 2.8 \pm 2.446912 \times 0.291548 = (2.086609,\ 3.513391). \]
\(x\)valuesmeancontribution
13, 43.50.5
26, 76.50.5
38, 109.02.0
411, 1312.02.0
SS pure error (4 d.f.)5.0
\[ SS_{LOF} = 5.1 - 5.0 = 0.1 \ \text{ on } 2 \text{ d.f.}, \quad MS_{LOF} = 0.05, \quad MS_{PE} = 1.25, \quad F = 0.04, \quad P(F_{2,4} > 0.04) = 0.961169. \]
CHECK IN R
x <- c(1,1,2,2,3,3,4,4); y <- c(3,4,6,7,8,10,11,13)
fit <- lm(y ~ x); coef(fit)
c(R2 = summary(fit)$r.squared, adjR2 = summary(fit)$adj.r.squared)
confint(fit, "x")
anova(fit, lm(y ~ factor(x)))       # lack of fit: the line against the group means
(Intercept)           x 
       0.75        2.80 
       R2     adjR2 
0.9389222 0.9287425 
     2.5 %   97.5 %
x 2.086609 3.513391
Analysis of Variance Table

Model 1: y ~ x
Model 2: y ~ factor(x)
  Res.Df RSS Df Sum of Sq    F Pr(>F)
1      6 5.1                         
2      4 5.0  2       0.1 0.04 0.9612

5. Result

\(\hat y = 0.75 + 2.8x\), \(R^{2} = 0.939\), \(\bar R^{2} = 0.929\), and with 95% confidence the slope lies between 2.09 and 3.51. The lack-of-fit \(F = 0.04\) (\(p = 0.96\)) gives no evidence against a straight line. Without replication \(SSE\) could not have been split, and the residual would confound curvature with noise.

Practical 12 — Multiple Linear Regression

1. Problem

Regress \(y = 12, 18, 20, 28, 32\) on \(x_1\) and \(x_2\) of Practical 10 (\(x_1 = 2, 4, 6, 8, 10\); \(x_2 = 1, 3, 2, 5, 4\)). Find the estimates, \(R^{2}\), adjusted \(R^{2}\), the overall \(F\) test and the standard errors.

2. Aim

To fit a multiple linear regression by solving the normal equations in matrix form, and to test the model and each coefficient.

3. Formula

\[ \hat{\boldsymbol\beta} = (X'X)^{-1}X'\mathbf{y}, \quad SSR = \hat{\boldsymbol\beta}'X'\mathbf{y} - n\bar y^{2}, \quad F = \frac{SSR/p}{SSE/(n - p - 1)}, \quad SE(b_j) = \sqrt{MSE\,c_{jj}}, \ c_{jj} = [(X'X)^{-1}]_{jj} \]

Applying it:

  1. Form \(X'X\) and \(X'\mathbf{y}\); check \(\det(X'X) \ne 0\).
  2. Solve for \(\hat{\boldsymbol\beta}\).
  3. The analysis of variance, \(R^{2}\), \(\bar R^{2}\), \(F\).
  4. Standard errors and \(t\) from the diagonal of \((X'X)^{-1}\).

4. Calculation

\[ X'X = \begin{pmatrix} 5 & 30 & 15 \\ 30 & 220 & 106 \\ 15 & 106 & 55 \end{pmatrix}, \quad X'\mathbf{y} = \begin{pmatrix} 110 \\ 760 \\ 374 \end{pmatrix}, \quad \det(X'X) = 720; \qquad \hat{\boldsymbol\beta} = \begin{pmatrix} 19/3 \\ 37/18 \\ 10/9 \end{pmatrix} = \begin{pmatrix} 6.333333 \\ 2.055556 \\ 1.111111 \end{pmatrix}. \] \[ SST = 256, \quad SSR = 254.444444, \quad SSE = 1.555556, \quad R^{2} = 0.993924, \quad \bar R^{2} = 0.987847, \] \[ MSE = 0.777778, \quad F = \frac{127.222222}{0.777778} = 163.571429, \quad P(F_{2,2} > 163.57) = 0.006076. \]
coefficientestimate\(c_{jj}\)\(SE\)\(t\)\(P(|t_2| > |t|)\)
\(b_1\)2.0555565/720.2324068.8446920.012543
\(b_2\)1.1111115/180.4648112.3904570.139337
CHECK IN R
x1 <- c(2,4,6,8,10); x2 <- c(1,3,2,5,4); y <- c(12,18,20,28,32)
X <- cbind(1, x1, x2); XtX <- t(X) %*% X; XtX; det(XtX)
b <- solve(XtX, t(X) %*% y); round(drop(b), 6)
fit <- lm(y ~ x1 + x2); s <- summary(fit)
round(c(R2 = s$r.squared, adjR2 = s$adj.r.squared, F = unname(s$fstatistic[1])), 6)
round(coef(s)[-1, ], 6)
       x1  x2
    5  30  15
x1 30 220 106
x2 15 106  55
[1] 720
               x1       x2 
6.333333 2.055556 1.111111 
        R2      adjR2          F 
  0.993924   0.987847 163.571429 
   Estimate Std. Error  t value Pr(>|t|)
x1 2.055556   0.232406 8.844692 0.012543
x2 1.111111   0.464811 2.390457 0.139337

5. Result

\(\hat y = 6.333 + 2.056x_1 + 1.111x_2\), \(R^{2} = 0.994\), \(\bar R^{2} = 0.988\). The model as a whole is highly significant (\(p = 0.006\)) and \(x_1\) is individually significant (\(p = 0.013\)), but \(x_2\) is not (\(p = 0.139\)) — with only two error degrees of freedom there is very little power, the classic sign of a model over-fitted to its sample size, and why \(\bar R^{2}\) is reported beside \(R^{2}\).

Practical 13 — Simple, Partial and Multiple Correlation

1. Problem

For the data of Practical 12, find the simple correlations of \(y\), \(x_1\), \(x_2\), the partial correlations \(r_{01.2}\) and \(r_{02.1}\), and the multiple correlation \(R_{0.12}\).

2. Aim

To measure the relation between two variables with a third held fixed, and of one variable with two others jointly.

3. Formula

\[ r_{01.2} = \frac{r_{01} - r_{02}r_{12}}{\sqrt{\left(1 - r_{02}^{2}\right)\left(1 - r_{12}^{2}\right)}}, \qquad R_{0.12} = \sqrt{\frac{r_{01}^{2} + r_{02}^{2} - 2r_{01}r_{02}r_{12}}{1 - r_{12}^{2}}} \]

Subscript 0 is \(y\). Check: \(R_{0.12}^{2}\) equals the \(R^{2}\) of the regression of Practical 12.

Applying it:

  1. The three simple correlations.
  2. The two partial correlations.
  3. The multiple correlation; cross-check with Practical 12.

4. Calculation

\[ r_{01} = 0.988212, \qquad r_{02} = 0.869626, \qquad r_{12} = 0.800000. \]

Numerator: \(0.988212 - 0.869626 \times 0.8 = 0.292511\). Denominator: \(\sqrt{(1 - 0.756249)(1 - 0.64)} = \sqrt{0.087750} = 0.296226\).

\[ r_{01.2} = \frac{0.292511}{0.296226} = 0.987457, \qquad r_{02.1} = 0.860663, \qquad R_{0.12} = 0.996957. \]

Check: \(\sqrt{R^{2}} = \sqrt{0.993924} = 0.996957\) (Practical 12). \(\checkmark\)

CHECK IN R
x1 <- c(2,4,6,8,10); x2 <- c(1,3,2,5,4); y <- c(12,18,20,28,32)
r01 <- cor(y, x1); r02 <- cor(y, x2); r12 <- cor(x1, x2)
round(c(r01 = r01, r02 = r02, r12 = r12), 6)
p012 <- (r01 - r02 * r12) / sqrt((1 - r02^2) * (1 - r12^2))
p021 <- (r02 - r01 * r12) / sqrt((1 - r01^2) * (1 - r12^2))
R012 <- sqrt((r01^2 + r02^2 - 2 * r01 * r02 * r12) / (1 - r12^2))
round(c(r01.2 = p012, r02.1 = p021, R0.12 = R012, sqrtR2 = sqrt(summary(lm(y ~ x1 + x2))$r.squared)), 6)
     r01      r02      r12 
0.988212 0.869626 0.800000 
   r01.2    r02.1    R0.12   sqrtR2 
0.987457 0.860663 0.996957 0.996957 

5. Result

Holding \(x_2\) fixed barely changes the relation between \(y\) and \(x_1\) (0.9882 → 0.9875), so \(x_1\) carries information of its own; holding \(x_1\) fixed also leaves \(r(y, x_2)\) high (0.8696 → 0.8607). The multiple correlation is 0.997. Contrast Practical 10, where \(x_2\) and \(x_3\) appeared related only through \(x_1\) — the case where a partial correlation collapses towards zero, and what the technique is for.

Practical 14 — Testing Multicollinearity

1. Problem

Three regressors are observed on five units:

unit12345
\(x_1\)12345
\(x_2\)246811
\(x_3\)13254

Test the design for multicollinearity.

2. Aim

To detect multicollinearity among regressors by the correlation matrix, the variance inflation factors and the condition number.

3. Formula

\[ VIF_j = \frac{1}{1 - R_j^{2}}, \qquad \kappa = \sqrt{\frac{\lambda_{\max}}{\lambda_{\min}}} \ \text{ of the correlation matrix} \]

\(R_j^{2}\) comes from regressing \(x_j\) on the other regressors. The usual warning lines are \(VIF > 10\) and \(\kappa\) above about 30.

Applying it:

  1. Look before computing: \(x_2\) is exactly \(2x_1\) at the first four units and 11 rather than 10 at the fifth.
  2. The correlation matrix — cheap, but blind to a relation among three or more regressors.
  3. The variance inflation factors, which do catch multi-way relations.
  4. The condition number, a single number for the whole design.

4. Calculation

\[ r(x_1, x_2) = 0.995893, \qquad r(x_1, x_3) = 0.800000, \qquad r(x_2, x_3) = 0.769554. \]
regressor\(R_j^{2}\)\(VIF_j\)reading
\(x_1\)0.99457286184.2593severe
\(x_2\)0.99385246162.6667severe
\(x_3\)0.730000003.7037acceptable

The eigenvalues of the correlation matrix are 2.714426, 0.282689 and 0.002884, so \(\kappa = \sqrt{2.714426/0.002884} = 30.68\).

CHECK IN R
Z <- cbind(x1 = c(1,2,3,4,5), x2 = c(2,4,6,8,11), x3 = c(1,3,2,5,4))
round(cor(Z), 6)
vif_manual <- function(X) {          # VIF without the car package
  sapply(seq_len(ncol(X)), function(j)
    1 / (1 - summary(lm(X[, j] ~ X[, -j]))$r.squared))
}
round(vif_manual(Z), 4)
ev <- eigen(cor(Z))$values; round(ev, 6)
sqrt(max(ev) / min(ev))              # the condition number
         x1       x2       x3
x1 1.000000 0.995893 0.800000
x2 0.995893 1.000000 0.769554
x3 0.800000 0.769554 1.000000
[1] 184.2593 162.6667   3.7037
[1] 2.714426 0.282689 0.002884
[1] 30.67827

5. Result

\(x_1\) and \(x_2\) are severely collinear (\(VIF\) 184 and 163, far above 10); \(x_3\) is not part of the problem (\(VIF = 3.7\)). The condition number of the correlation matrix, 30.7, is just above the warning line of 30: one eigenvalue, 0.0029, is nearly zero — the near-exact relation \(x_2 \approx 2x_1\). The standard error of \(\hat\beta_1\) is \(\sqrt{184.26} = 13.6\) times what orthogonal regressors would give. The estimates stay unbiased and the fit stays good inside the data's range: multicollinearity damages the separation of effects, not the fit. The remedy is in the design — drop or combine one of the pair, or collect data that breaks the pattern — not a larger sample of the same shape (worked also in Unit 4, Example 4.2).

What the Practical Record Should Contain

FOR EACH EXPERIMENT
  1. 1. Problem — the data, as given, and what is to be found.
  2. 2. Aim — in one line.
  3. 3. Formula — the method named, and why it was chosen over the alternatives (partitioning when one block is already inverted, LU when several right-hand sides share a matrix, sweep-out when the inverse is wanted too), with the steps that apply it.
  4. 4. Calculation — every intermediate matrix written out, not only the final answer; an independent check (\(AA^{-1} = I\), \(LU = A\), \(\sum\lambda_i = \operatorname{trace}\), \(\prod\lambda_i = \det\), substitution back, or the same quantity computed a second way); and the R program, written without packages, with its output compared with the hand calculation.
  5. 5. Result — the conclusion in words: not "the inverse is ..." but what the numbers mean for the data.