I would like to make some kriging in a belgian territory.
I got a data set called clean.donnees.Ni
after removing outliers and NA
values.
I first tried simply with this, but got this warning as result :
Ni.krig <- krige(formula = Ni~1,
data = clean.donnees.Ni,
locations = ~x+y,
newdata = krig.grid,
model = Ni.vg.fit)
Warnings : Covariance matrix singular at location [50686, 156893,0]: skipping
I found on other topics that I probably got points at the same location.
(R gstat krige() – Covariance matrix singular at location [5.88,47.4,0]: skipping)
They advice to use this to remove points on the same location:
clean.donnees.Ni <- clean.donnees.Ni[-zerodist(clean.donnees.Ni)[,1],]
When I did this, I finally thought I could make krige() work, but instead it nows returns me this error :
Ni.krig <- krige(formula = Ni~1,
data = clean.donnees.Ni,
locations = ~x+y,
newdata = krig.grid,
model = Ni.vg.fit)
Error in `coordinates<-`(`*tmp*`, value = locations) :
setting coordinates cannot be done on Spatial objects, where they have already been set
Because I had to transform clean.donnees.Ni
in a SpatialPointsDataFrame, locations can't read ~x+y anymore.
Does anyone knows how to makes kriging work ?
Best Answer
If your data is a spatial data object then you give it to the
locations
argument - you only dolocations = ~x+y
if you have a non-spatial data frame with coordinates in those columns. So I think:will work for you.
I can reproduce your error with a test dataset, and make it work:
From the help: