GeoStat-Framework / PyKrige

Kriging Toolkit for Python
https://pykrige.readthedocs.io
BSD 3-Clause "New" or "Revised" License
759 stars 188 forks source link

Why UK is calculating Variogram on the sampled data rather than on the detrended sample residuals? #167

Closed ehxan139 closed 3 years ago

ehxan139 commented 3 years ago

Hi

First of all thankyou for doing a wonderful job with the PyKrige package. It's very well written and documented.

I have a small query regarding the UK algorithm in the package (uk.py) and was wondering if you can help me out. In your implementation of the UK, you have used variograms calculated from the sample data (e.g. in function _get_kriging_matrix()). However, in the references that you have mentioned and elsewhere, UK is implemented with variograms calculated from the residuals of detrended samples.

I am sure there must be a reason for your implementation, but I am unable to find a reference that mentions to use variogram of original samples even after the trend is modeled. I was hoping if you could guide me to the reference that why do we use variograms of original samples and not the residuals ? #

MuellerSeb commented 3 years ago

That is a good question. Let's try to answer:

In literature, the term detrending is handled very differently in terms of kriging. We have several algorithms that deal with this:

So to answer your question: within UK, there is no trend fitted to the data, only an additional drift is given as described above. Therefore, the variogram is estimated to the not-detrended input data, since it can't be detrended beforehand AND the variogram properties also acutally belong to this not-detrended data.

If you want to use a kriging routine, that estimates the variogram properties from the residuals after applying a trend-model, you have to use Regression Kriging (RK).

Also have a look here: https://en.wikipedia.org/wiki/Regression-kriging

There a separate section deals with these differences.

Cheers, Sebastian

ehxan139 commented 3 years ago

Hmmm... this makes sense now. I missed the part that the drift function is actually included in the kriging matrix. I will look into regression kriging as well to see if it fits my problem better. Thank you for such an awesome job and contribution.