0

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

link: https://www.r-exercises.com/2018/03/31/advanced-techniques-with-raster-data-part-3-regression-kriging/?cf_chl_jschl_tk=6311eac67bd8c8522c68f83f62be077ef572ca2c-1588325277-0-AaBAYr6yFHMceWCKlsRhOxbdPIKI3oKq6c8PVrtfzQaBgUDqBu3-QG8E1z94b3ygHSpaaYMPtHYo4ThfcJWwsn2p1ZxcvutlBdn-nh0wKILVFc3xrLHUzNqxRqJlY9sjRcHDft9tn9PFPngo06AonPkEkCUIHtQ1mgjz3Kgt9zTp93OJyJEgAp0XRAvc1pzE8MTXv-fAwlkWki21vE9RYiZEgss5m5AYJ-fppvRUL2ckSTl0W765HVVeH3GySp6nuoTvmvaocZ_Q8axMB_za2Iiiwb2iar_h-9s8fOZXh5QbQc-9PojDlPBfU-nxy4E1gGHjFyfXNvnkghKYqZaz6fr4pQ7u7K3R-GglVx2vPlEmIfuIzHYdhAC4oJd84hKMvg)

  • Could you provide a minimal reproducible example? – Alexandre Wadoux May 19 '20 at 06:27
  • Hi Alexandre, Thanks for giving me an answer. After many days of struggle I finally managed to solve my problem : I created a grid based on my initial data. Then I created rasters (using stack) for every column of data (existing or created during GAM and kriging) and its now working. Each raster absolutely needed to have the exact same form (number of columns and raws), keeping the exact same names during the all process and be included in a same global raster. Best, Céline – Céline Albert May 20 '20 at 07:38

0 Answers0