I have a dataframe with columns COORDS_X1, COORDS_X2, y. The dataframe has 14 observations located in a small region in Spain and I want to interpolate the unobserved locations in the region. Here is my current dataset df:
df = read.table(header = TRUE, text = "
COORDS_X1 COORDS_X2 y
1 280561. 4798452. 23
2 267718. 4804594. 19
3 270456. 4805417. 34
4 281943. 4824197. 25
5 283965. 4823130. 32
6 282627. 4796964. 20
7 286191. 4823939. 24.5
8 289349. 4794697. 23.5
9 267259. 4806210. 20
10 274674. 4792999. 24
11 284148. 4821649. 24
12 273031. 4809218. 38
13 282651. 4822399. 22
14 281779. 4798643. 38 ")
I am no expert on this tipoc but I saw that kriging was standard methodology for this. So I am trying to use the following piece of code:
library(sp) # e.g. coordinates()
library(gstat) # e.g. variogram()
coordinates(df) <- ~ COORDS_X1 + COORDS_X2
vgm <- variogram(y ~ 1, df)
fit <- fit.variogram(vgm, model = vgm(1, "Sph", 300, 1))
grd <- expand.grid(COORDS_X1 = seq(min(df$COORDS_X1), max(df$COORDS_X1), length.out = 100),
COORDS_X2 = seq(min(df$COORDS_X2), max(df$COORDS_X2), length.out = 100))
coordinates(grd) <- ~COORDS_X1 + COORDS_X2
gridded(grd) <- TRUE
krg <- krige(y ~ 1, df, grd, model = fit)
If I have a look to as.data.frame(krg), this piece of code is returning the exact same value for all the unobserved locations. Actually, if I plot the results I obtain this:

I suspect the issue is trying to fit a complicated model to a small number of data points in
fit <- fit.variogram(vgm, model = vgm(1, "Sph", 300, 1)). Replacing this with a simpler model, e.g.fit <- fit.variogram(vgm, model = vgm("Gau")), may give better results.From
?fit.variogram: