gstat (version 2.0-3)

fit.variogram: Fit a Variogram Model to a Sample Variogram


Fit ranges and/or sills from a simple or nested variogram model to a sample variogram


fit.variogram(object, model, fit.sills = TRUE, fit.ranges = TRUE,
	fit.method = 7, debug.level = 1, warn.if.neg = FALSE, fit.kappa = FALSE)



sample variogram, output of variogram


variogram model, output of vgm; see Details below for details on how NA values in model are initialised.


logical; determines whether the partial sill coefficients (including nugget variance) should be fitted; or logical vector: determines for each partial sill parameter whether it should be fitted or fixed.


logical; determines whether the range coefficients (excluding that of the nugget component) should be fitted; or logical vector: determines for each range parameter whether it should be fitted or fixed.


fitting method, used by gstat. The default method uses weights $N_h/h^2$ with $N_h$ the number of point pairs and $h$ the distance. This criterion is not supported by theory, but by practice. For other values of fit.method, see details.


integer; set gstat internal debug level


logical; if TRUE a warning is issued whenever a sill value of a direct variogram becomes negative


logical; if TRUE, a sequence of 0.3, 0.4,...,5 will be searched for optimal fit; alternatively another sequence can be given to this argument


returns a fitted variogram model (of class variogramModel).

This is a data.frame with two attributes: (i) singular a logical attribute that indicates whether the non-linear fit converged (FALSE), or ended in a singularity (TRUE), and (ii) SSErr a numerical attribute with the (weighted) sum of squared errors of the fitted model. See Notes below.


If any of the initial parameters of model are NA, they are given default values as follows. The range parameter is given one third of the maximum value of object$dist. The nugget value is given the mean value of the first three values of object$gamma. The partial sill is given the mean of the last five values of object$gamma.

Values for fit.method are 1: weights equal to $N_j$; 2: weights equal to $N_j/((gamma(h_j))^2)$; 5 (ignore, use fit.variogram.reml); 6: unweighted (OLS); 7: $N_j/(h_j^2)$. (from:, table 4.2).


Pebesma, E.J., 2004. Multivariable geostatistics in S: the gstat package. Computers \& Geosciences, 30: 683-691.

See Also

variogram, vgm


Run this code
coordinates(meuse) = ~x+y
vgm1 <- variogram(log(zinc)~1, meuse)
fit.variogram(vgm1, vgm(1, "Sph", 300, 1))
fit.variogram(vgm1, vgm("Sph"))

# optimize the value of kappa in a Matern model, using ugly <<- side effect:
f = function(x) attr( <<- fit.variogram(vgm1, vgm(,"Mat",nugget=NA,kappa=x)),"SSErr")
optimize(f, c(0.1, 5))
# best fit from the (0.3, 0.4, 0.5. ... , 5) sequence:
(m <- fit.variogram(vgm1, vgm("Mat"), fit.kappa = TRUE))
attr(m, "SSErr")
# }

Run the code above in your browser using DataCamp Workspace