autofitVariogram {automap}R Documentation

Automatically fitting a variogram


Automatically fitting a variogram to the data on which it is applied. The automatic fitting is done through fit.variogram. In fit.variogram the user had to supply an initial estimate for the sill, range etc. autofitVariogram provides this estimate based on the data and then calls fit.variogram.


         model = c("Sph", "Exp", "Gau", "Ste"),
         kappa = c(0.05, seq(0.2, 2, 0.1), 5, 10), 
         fix.values = c(NA,NA,NA),
         verbose = FALSE, 
         GLS.model = NA,
         start_vals = c(NA,NA,NA),
         miscFitOptions = list(),



formula that defines the dependent variable as a linear model of independent variables; suppose the dependent variable has name 'z', for ordinary and simple kriging use the formula 'z~1'; for simple kriging also define 'beta' (see below); for universal kriging, suppose 'z' is linearly dependent on 'x' and 'y', use the formula 'z~x+y'.


An object of SpatialPointsDataFrame-class.


The list of variogrammodels that will be tested.


Smoothing parameter of the Matern model. Provide a list if you want to check more than one value.


Can be used to fix a variogram parameter to a certain value. It consists of a list with a length of three. The items describe the fixed value for the nugget, range and sill respectively. They need to be given in that order. Setting the value to NA means that the value is not fixed.


logical, if TRUE the function will give extra feedback on the fitting process


If a variogram model is passed on through this parameter a Generalized Least Squares sample variogram is calculated.


Can be used to give the starting values for the variogram fitting. The items describe the fixed value for the nugget, range and sill respectively. They need to be given in that order. Setting the value to NA means that the value will be automatically chosen.


A list with named arguments that provide additional control over the fitting process. For example: list(merge.small.bins = TRUE). If the list is empty, autofitVariogram uses default values. The following parameters can be set:


logical, when TRUE, the function checks if there are bins with less than 5 points. If so, the first two bins are merged and the check is repeated. This is done until all bins have more than points.

integer, the minimum number of points allowed in a bin before we start merging bins. See also merge.small.bins.


parameters that are passed on to variogram when calculating the sample variogram.


Geostatistical routines are used from package gstat.

A few simple choices are made when estimating the inital guess for fit.variogram. The initial sill is estimated as the mean of the max and the median of the semi-variance. The inital range is defined as 0.10 times the diagonal of the bounding box of the data. The initial nugget is defined as the min of the the semi-variance.

There are five different types of models that are often used:


A shperical model.


An exponential model.


A gaussian model.


A model of the Matern familiy


Matern, M. Stein's parameterization

A list of all permitted variogram models is available by typing vgm() into the R console. autofitVariogram iterates over the variogram models listed in model and picks the model that has the smallest residual sum of squares with the sample variogram. For the Matern model, all the kappa values in kappa are tested.

Note that when using the power model, and not specifying starting values yourself, the sill is set to 1, the range to 1 and the nugget to 0. This is because the normal initial values for those paramters don't work well with the power model. I consider this a temporary solution, any suggestions are appreciated.

It is possible to pass anisotropy parameters to autofitVariogram. However, autofitVariogram does not fit anisotropic variogram models. The function sees the anisotropic sample variogram as one big sample variogram. So it fits an average isotropic variogram model from the anisotropic sample variogram. A warning is issued when a users passes alpha to autofitVariogram.


An object of type autofitVariogram is returned. This object contains the experimental variogram, the fitted variogram model and the sums of squares (sserr) between the sample variogram and the fitted variogram model.


autofitVariogram is mostly used indirectly through the function autoKrige


Paul Hiemstra,

See Also

fit.variogram, autoKrige, posPredictionInterval


coordinates(meuse) =~ x+y
variogram = autofitVariogram(zinc~1,meuse)

# Residual variogram
coordinates(meuse) =~ x+y
variogram = autofitVariogram(zinc ~ soil + ffreq + dist, meuse)

# Settings additional fitting options
variogram = autofitVariogram(zinc ~ soil + ffreq + dist, meuse, 
    miscFitOptions = list(merge.small.bins = FALSE))

# Settings the minimum number of pairs per bin quite high
# to see the effect of merging bins
variogram = autofitVariogram(zinc ~ soil + ffreq + dist, meuse, 
    miscFitOptions = list( = 500))

# ...and disable the merging, note the difference between the two plots
variogram = autofitVariogram(zinc ~ soil + ffreq + dist, meuse, 
    miscFitOptions = list( = 500, merge.small.bins = FALSE))

## Not run: 
# An example of autofitVariogram with anisotropic sample variogram.
# This is not supported, see details section.
vm.isotropic = autofitVariogram(log(zinc) ~ dist, meuse)
vm.anisotropic = autofitVariogram(log(zinc) ~ dist, meuse, alpha = c(0,45,90,135))

## End(Not run)

[Package automap version 1.0-14 Index]