1

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
jeza
  • 299
  • 1
  • 4
  • 21
  • Yes, it's OK to use your code. Compare with the output of [this function](https://stackoverflow.com/a/40250436/8245406) using SVD decomposition. – Rui Barradas Apr 11 '21 at 13:00

0 Answers0