versioninfo() using Random Random.seed!(280) # seed n, p = 5, 3 X = randn(n, p) # predictor matrix y = randn(n) # response vector # finds the least squares solution X \ y using Random, LinearAlgebra Random.seed!(280) # seed y = randn(5) # response vector X = randn(5, 3) # predictor matrix X \ y # least squares solution by QR # same as qr(X) \ y cholesky(X'X) \ (X'y) # least squares solution by Cholesky # QR factorization with column pivoting xqr = qr(X, Val(true)) xqr \ y # least squares solution # thin Q matrix multiplication (a sequence of Householder transforms) norm(xqr.Q * xqr.R - X[:, xqr.p]) # recovers X (with columns permuted)