How to make Ordinary Kriging by using gstat predict

前端 未结 1 599
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-04 21:14

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

相关标签:
1条回答
  • 2021-02-04 21:29

    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.

    0 讨论(0)
提交回复
热议问题