I am trying to write a code in R that use gstat library in order to create an interpolation. I have already read the gstat manual and based on some examples on internet I had ma
You need to include the creation of the gstat object, not in de prediction phase:
g <- gstat(id="tec", formula=TEC ~ 1, data=data, model = v.fit)
However, I would recommend using the standard interface for gstat
using krige
. This combines the building of the gstat
object and the prediction into one functions. Very rarely do you need to build gstat
objects yourself. For example:
data(meuse)
coordinates(meuse) = ~x+y
data(meuse.grid)
gridded(meuse.grid) = ~x+y
m <- vgm(.59, "Sph", 874, .04)
# OK:
x <- krige(log(zinc)~1, meuse, meuse.grid, model = m)
You could also use the automap
package (which I am the author of) and let the variogram model be automatically fitted to the data. For example using the meuse
dataset:
library(automap)
kr = autoKrige(log(zinc)~1, meuse, meuse.grid)
This will automatically build a sample variogram, and fit a variogram model to that sample variogram.