Recently, I am facing a strange problem when using krige() in gstat library. This error was not there a few months ago because I am using the same code with the same data that I successfully used before. But now I am getting singular covariance matrix at grid points at which I want to krige the unknown values. I changed nothing in that old code. Just opened and ran, and now it would not run. Upon searching I found one solution set=list(cn_max = 1e10) from a communication between Edzer and Hengl under title "[R-sig-Geo] 'LDLfactor' error in 'krige' function". However, then krige() gives syntax error about cn_max. I also read "Error in In predict.gstat in R" question on this site, but it also does not work for me.

Why I am getting this error suddenly?


This is caused by the matrix library used by gstat. Historically (gstat was released as open source code in 1997) it used the LDLfactor routine in the meschach library. Around 6 months ago I factored this out this code and replaced it with the BLAS/LAPACK which are native in R. LAPACK uses Choleski decomposition. LDLfactor allows for some non-positive matrices, where Choleski will trigger an error on this.

So, your problem is apparently a non-positive definite matrix which was not detected by LDL, but was detected by Choleski.

| improve this answer | |
  • Thank you for your reply. So within the gstat is there any solution to overcome this issue? I tried setting list(cn_max = 1e10) but R does not recognize cn_max and gives syntax error. I use the UTM coordinates. – Asad Ali Jul 2 '16 at 19:53
  • Indeed, gstat does not solve this for you. – Edzer Pebesma Jul 3 '16 at 20:47
  • First attempt at using kriging here, and I'm also getting the "Covariance matrix singular" for all points. Is there a solution, or are there other causes? – winwaed Oct 17 '16 at 15:46
  • Addenda to my specific problem: I had duplicate input locations. In reference to the OP's problem, you can apparently set a variable "choleski" to 0 (zero) to reproduce the original behaviour. I haven't tried this. – winwaed Oct 18 '16 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.