Hello, I was dealing with some matrices (for a statistical model), when I came across this case which raised an error during the fitting. I was trying to compute
but a matrix A_star raised the error “LinearAlgebra.PosDefException(-1)”.
However, I don’t understand why, since all its eigenvalues are strictly positive, which would mean that the matrix, and also its inverse inside the multivariate normal, are positive definite. But instead the isposdef() command seems to disagree about the inverse.
The erorr occured at the 26th iteration, meaning that all the before cases were correct, so for now I was thinking that it is a numerical problem, especially also because the definition of A_star is the sum of positive definite matrices so it should preserve the positive definitiveness:
A_star = I(p)/s2_beta
for j in 1:n
X_jt = Xlk_covariates[j,:,t]
A_star += (X_jt * X_jt') / sig2h_iter[Si_iter[j],t]
end
The packages involved should be just LinearAlgebra and Distributions.
The problem is that a matrix must be hermitian (symmetric) to be positive definite (see Definite matrix - Wikipedia) and inv doesn’t preserve symmetry unless you tell it that the input is a Hermitian (Symmetric) matrix.
That isn’t accurate. The Wikipedia page says “A real symmetric matrix is positive definite if…”. Unsymmetric square matrices can be positive definite as well. There’s a section about that on the same page: Definite matrix - Wikipedia
I think it would make sense for isposdef to require the input to be Hermitian. Cholesky won’t be well defined for unsymmetric matrices, even one that is positive definite according to the extended definition.