Formula: (X'X) beta = X'y; beta = (X'X)^-1 X'y; Var(beta) = sigma2 (X'X)^-1; H = X(X'X)^-1 X'
References
Montesinos Lopez, Montesinos Lopez and Crossa (2022), Multivariate Statistical Machine Learning Methods for Genomic Prediction, Springer, doi:10.1007/978-3-030-89010-0. Chapter 3, Sect. 3.2 pp. 72-73: setting the gradient of the residual sum of squares to zero gives the normal equations (X'X)beta = X'Y with unique solution beta = (X'X)^-1 X'y, variance sigma2 (X'X)^-1, and hat matrix H = X(X'X)^-1 X'. sigma2 is the unbiased residual variance RSS/(n - p). Read from the chapter PDF, not recalled.
Examples
V <- c(1, 2, 3, 4, 5, 6, 7, 8)
Olsnormeq(V, V)
#> $beta
#> [1] 6.097555e-16 1.000000e+00
#>
#> $fitted
#> [1] 1 2 3 4 5 6 7 8
#>
#> $resid
#> [1] -2.220446e-16 0.000000e+00 4.440892e-16 8.881784e-16 8.881784e-16
#> [6] 8.881784e-16 1.776357e-15 1.776357e-15
#>
#> $rss
#> [1] 8.923989e-30
#>
#> $sigma2
#> [1] 1.487331e-30
#>
#> $se
#> [1] 9.502751e-16 1.881825e-16
#>
#> $leverage
#> [1] 0.4166667 0.2738095 0.1785714 0.1309524 0.1309524 0.1785714 0.2738095
#> [8] 0.4166667
#>
#> $n
#> [1] 8
#>
#> $p
#> [1] 2
#>
#> $method
#> [1] "OLS via the normal equations, MVSML Sect. 3.2"
#>
#> attr(,"class")
#> [1] "morie_rich_result" "list"
