# Calculating coefficient of variation from gstat output to create uncertainty map in R

I was asked by my supervisor to create uncertainty maps of kriging interpolation based on the coefficient of variation ((sd/mean)*100%). I used `krige` function from `gstat` package to perform the interpolation.

``````#interpolation using kriging with external drift
krig1 <- krige(xSO4.2009. ~ easting+lograin.2009., dat1, grid.uk, model=fitvar1)
``````

The output produce the prediction values (`var1.pred`) and the prediction variances (`var1.var`).

If I want to create the uncertainty map based on the coefficient of variation (COV), does it mean that I just need to use the prediction values and the variance to calculate COV then map it?

``````pred<-krig1@data\$var1.pred
var<-krig1@data\$var1.var
krig1\$cov<-(sqrt(var)/mean(pred))*100
``````

Almost. Since the output from kriging is a distribution at every prediction point, you want to divide the `sd` by the prediction at each point:
`````` krig1\$cov = 100 * sqrt( krig1\$var1.var) / krig1\$var1.pred
`````` krig1\$cov = 100 * sqrt( krig1\$var1.var) / mean(krig1\$var1.pred)