Matrix Calculus

Matrix Inverse

  • \((X^TX)^{-1}\)
X <- matrix(c(1, -2, 0, 3, 7, 1), nrow = 3, ncol = 2)
XtX <- t(X) %*% X
XtXinv <- solve(XtX)
XtXinv
##            [,1]       [,2]
## [1,] 0.33908046 0.06321839
## [2,] 0.06321839 0.02873563

System of Linear Equations

  • \(\beta=(X^TX)^{-1}X^Ty\)
y <- c(2, 1, 0)
beta <- solve(qr(X), y)
beta
## [1] 0.8218391 0.3735632