Local Block Kriging with Local Variogram with gstat
<p>I have been unable to find any information specific to local block kriging with a local variogram using the gstat package in R. There is freeware called VESPER from the Australian Center for Precision Agriculture that is able to do this, and from what I have read it should be possible in R, I could just use some help with putting together a for-loop to make the gstat functions work locally.</p>

<p>Using the meuse data set as an example, I have been able to calculate and fit a global variogram to a data set:</p>

<pre><code>    library(gstat)
    data(meuse)
    coordinates(meuse) = ~x+y
    data(meuse.grid)
    gridded(meuse.grid) = ~x+y

    logzinc_vgm&lt;- variogram(log(zinc)~1, meuse)
    logzinc_vgm_fit &lt;- fit.variogram(logzinc_vgm, model=vgm("Sph", "Exp"))
    logzinc_vgm_fit

    plot(logzinc_vgm, logzinc_vgm_fit)
</code></pre>

<p>This gives a nice plot of the variogram for the whole data set with the fitted model. Then I can use this to perform block kriging over the entire data set:</p>

<pre><code>    logzinc_blkkrig &lt;- krige(log(zinc)~1, meuse, meuse.grid, model = logzinc_vgm_fit, block=c(100,100))
    spplot(logzinc_blkkrig["var1.pred"], main = "ordinary kriging predictions")
    spplot(logzinc_blkkrig["var1.var"],  main = "ordinary kriging variance")
</code></pre>

<p>This produces a plot of the interpolated data as well as a plot of the variance for each predicted point. So this would be perfect if I wanted these functions to work once for my entire data set...</p>

<p>But I have been unable to generate a for-loop to handle these functions on a local level. </p>

<p>My goals are:
     1. For each point in my grid file (which I have tried as both a data frame and SpatialPointsDataFrame), I would like to subset from my data file points within the distance diagonally of the range given in the global variogram (easy to call this location (i.e. logzinc_vgm_fit[2,3]))
     2. On this subset of data, I would like to calculate the variogram (as above) and fit a model to it (as above)
     3. Based on this model, I would like to perform block kriging to get a predicted value and variance at that grid point
     4. Build the above three steps into a for-loop to predict values at each grid point based on the local variogram around each grid point</p>

<p>note: as with the meuse data set built into the gstat package, the dimensions of my grid and data data frames are different</p>

<p>Thank you very much for chiming in if anyone is able to tackle this question. Happy to post the code I am working with so far if it would be useful.</p>