I can see that ginv
function in R solved the singularity error with the solve
function.
Does it wrong to use ginv
function or I am ok to do so in such a case?
set.seed(1)
X=matrix(rnorm(3*3),ncol = 3)
X=cbind(1,X)
set.seed(1)
Y=rnorm(3)
ginv(t(X) %*% X) %*% t(X) %*% Y
[,1]
[1,] -0.101756527
[2,] 0.968377697
[3,] 0.007936812
[4,] 0.142144114
solve(t(X) %*% X) %*% t(X) %*% Y
Error in solve.default(t(X) %*% X) :
system is computationally singular: reciprocal condition number = 1.85257e-17