Compute projection / hat matrix via QR factorization, SVD (and Cholesky factorization?)
问题 I'm trying to calculate in R a projection matrix P of an arbitrary N x J matrix S : P = S (S'S) ^ -1 S' I've been trying to perform this with the following function: P <- function(S){ output <- S %*% solve(t(S) %*% S) %*% t(S) return(output) } But when I use this I get errors that look like this: # Error in solve.default(t(S) %*% S, t(S), tol = 1e-07) : # system is computationally singular: reciprocal condition number = 2.26005e-28 I think that this is a result of numerical underflow and/or