##Positive Defintie Case
M <- 0.9^apply(as.matrix(1:4),1,function(a){abs(a-(1:4))})
modchol(M) ## Different estimate from chol(M) due to pivoting
PosDefEst(M) ## Same as M
##Not Positive Definite
M2 <-M
M2[2,2] <- 0.7
eigen(M2)$values ##has a negative eigenvalue
L <- modchol(M2)
L
M2_est <- PosDefEst(M2)
M2_est
M2_est - M2 ## == diag(L$E)
Run the code above in your browser using DataLab