I am struggling with a Kriging + GAM problem since a while and hope someone will be able to help me.
I am trying to make interpolation of a pollutant into an area. To do so, I use ordinary kriging from gstat, in addition to GAM, based on this method (link where I found it is below):
GAM <- gam(formula = pollutant ~ 1+ s(Long, Lat) + s(Individual, bs="re"), data = dataset)
GAMPredictions <- predict(mydataset, GAM, type="response")
residKrigMap <- krige(formula = residuals(GAM) ,
locations = mydataset,
model = myVariogram,
newdata = MyGrid)
residKrigRstLayer <- as(residKrigMap, "RasterLayer")
gamKrigMap <- GAMPredictions + residKrigRstLayer
All the kriging part is doing ok, but when I try to this:
gamKrigMap <- GAMPredictions + residKrigRstLayer
it does not work. And I am quite sure it's because of the grid I am doing my interpolation on. Indeed, I am using a rds file on which are the areas I want to interpolate. But you can't make the prediction in such a file, as it does not contain the information from the dataset. Also, I have 760 observations from my dataset, but over 6000 from my grid, so there is a mistmatch. So far, for what I have been reeding, I should create a grid based on my dataset.
So my questions are:
how can I create a grid from my data set with R? All the method I see include existing raster or shapefile that I don't have (or know how to create).
from then, how can I add the country boundaries (interpolation is made in the north atlantic and I want to add the country that are surrounding the area)
Of course let me know if you need more info.
Best,
Céline