This function was originally sourced from the `automap` package (version 1.1-16), which is no longer available on CRAN. It is provided here with minimal modification for internal use in this package.
`autofitVariogram()` automates the fitting of a variogram model to spatial input data by testing a range of model types and kappa values (for Matern and Stein models), and selecting the best-fit model based on the sum of squared errors.
Dependencies from `gstat`, `sp`, and `sf` are required for this function to operate correctly.
autofitVariogram(
formula,
input_data,
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(),
...
)
a list with class `"autofitVariogram"` containing:
the empirical variogram
the best-fit variogram model object
sum of squared errors for the best model
model formula for the variogram (e.g., `z ~ 1`)
an `sf` or `Spatial*` object containing the spatial data
a character vector of variogram model names (e.g., `"Sph"`, `"Exp"`)
vector of kappa values for Matern/Stein models
optional vector of fixed values for nugget, range, sill
logical; if `TRUE`, prints additional output
optional variogram model for Generalized Least Squares
optional vector of starting values for nugget, range, sill
named list of additional control options
additional arguments passed to `gstat::variogram()`
if (FALSE) {
result <- autofitVariogram(z ~ 1, input_data)
plot(result$exp_var)
plot(result$var_model)
}
Run the code above in your browser using DataLab