# Example of simple kriging with varying local means in R

I'm looking for an example of how to use simple kriging with varying local means in R.

I've tried google, a few books (for example Aplied Spatial Data Analysis with R) and I've found almost nothing. The only useful thing I've found is the Figure 2.1 on page 13 of Gstat user's manual (http://www.gstat.org/gstat.pdf).

Could someone provide an example of simple kriging with varying local means in R?

Here is an R example that corresponds to the example in the manual you point to:

``````> library(sp)
> demo(meuse, ask=FALSE, echo=FALSE)
> coef = lm(log(zinc)~sqrt(dist), meuse)\$coef
> coef
(Intercept)  sqrt(dist)
6.994379   -2.549200
> library(gstat)
> k = krige(log(zinc)~sqrt(dist), meuse, meuse.grid, vgm(.6, "Sph", 900), beta = coef)
[using simple kriging]
``````

In the kriging step, the trend value is assumed to be known, the kriging error only refers to predicting the residual, and does not include the estimation error for the trend coefficients, as you would get with universal kriging:

``````> k = krige(log(zinc)~sqrt(dist), meuse, meuse.grid, vgm(.6, "Sph", 900))
[using universal kriging]
``````

where the trend is estimated as part of the kriging (by generalized least squares).