View source: R/semivariogram.R
semivariogram | R Documentation |
This function creates semivariogram plots. It creates empirical semivariogram
for raw data and lm
object or parametric exponential semivariogram based
on the estimation from metropolis.krige
. Based on the user's chosen level
of coarsening, the semivariogram is presented for various distances.
semivariogram(x, ...) ## S3 method for class 'krige' semivariogram(x, ..., bins = 13, terms = "all", type, pch, lty, legend, col) ## S3 method for class 'krige' plot(...) ## S3 method for class 'lm' semivariogram( x, ..., coords, bins = 13, terms = c("raw", "residual"), east, north, type, legend, col, pch, lty ) ## Default S3 method: semivariogram( x, ..., coords, data, bins = 13, east, north, type, pch, lty, col ) ## S3 method for class 'semivariance' semivariogram(x, ..., type, pch, lty, legend, col) ## S3 method for class 'semivariance' plot(x, ..., type, pch, lty, legend, col)
x |
An object for which a semivariogram is desired. The object can
be a |
... |
Additional arguments to be passed to |
bins |
Number of bins into which distances should be divided. The observed distances will be split at equal intervals, and the semivariance will be computed within each interval. Defaults to 13 intervals. |
terms |
A vector of strings specifies for which the semivariogram is created.
Options are "raw" (the semivariogram for raw data), "residual" (the semivariogram
for residuals from linear regression). "parametric" (the parametric powered
exponential semivariogram based on the estimation from |
type |
A vector specify the type of plots for each term. Options are "l"
(line plot) and "p" (scatter plot). Defaults to |
pch |
A vector specify the points symbols for scatter plot. Suppressed for line plot. |
lty |
A vector specify the line type for line plot. Suppressed for scatter plot. |
legend |
A logical argument for whether legend should be presented. Defaults to |
col |
A vector specify the color for each term. Defaults to |
coords |
A matrix of coordinates for all observations or a vector of variable
names indicating the coordinates variables in the data. Alternatively, the
coordinates can also be specified separately using |
east |
Alternative specification for the vector of eastings for all observations. |
north |
Alternative specification for the vector of northing for all observations. |
data |
If object is a variable name, a data frame must be provided. |
The function creates semivariograms for diagnosing the spatial relationship that best describes the data and for diagnosing the degree to which the model fits the spatial relationship. With a view of the empirical semivariogram, a user can consult images of parametric semivariograms to determine whether an exponential, Gaussian, or other powered expoential function fit the data well, or if another style of semivariogram works better. Examining this also allows the user to develop priors such as the approximate split in variance between the nugget and partial sill as well as the approximate distance of the effective range. Semivariograms are explicitly tied to a corresponding spatial correlation function, so determining the former automatically implies the latter. See Banerjee, Carlin, and Gelfand for a fuller explanation, as well as a guidebook to semivariogram diagnosis (2015, 26-30).
The function can be applied to a variable, a fitted linear model (lm
object) before fitting a spatial model or to a krige
object or semivariance
object to assess the model fit. When applying to a variable, it will describes
the raw data; for a lm
object, the default will present empirical
semivariogram for both the raw data and linear residuals; when applying to a
krige
object, the default will present empirical semivariogram for the
raw data and the residuals from linear fit, and the parametric semivariogram
given the estimates from the geospatial model fitted in metropolis.krige
;
for a semivariance
object, it will present a plot(s) for whichever the
semivariance is calculated. Users can also specify which semivariogram is needed
in the terms
argument if there are multiple kinds of semivariogram can
be plotted. The plots are compatible to the arguments used in base R
base graphics.
An semivariogram plot. For krige
object, it will return empirical
semivariograms for raw data and residuals of linear regression as well as a
parametric powered exponential semivariogram given the values of the estimates
from metropolis.krige
as default.
Sudipto Banerjee, Bradley P. Carlin, and Alan E. Gelfand. 2015. Hierarchical Modeling and Analysis for Spatial Data. 2nd ed. Boca Raton, FL: CRC Press.
semivariance
, exponential.semivariance
## Not run: # Summarize Data summary(ContrivedData) # Empirical semivariagram for variable y semivariogram(x=ContrivedData$y, coords = cbind(ContrivedData$s.1, ContrivedData$s.2)) # Initial OLS Model contrived.ols<-lm(y~x.1+x.2,data=ContrivedData) # Empirical semivariagram for ols fit semivariogram(contrived.ols, coords = c("s.1","s.2"), bins=13) # Set seed set.seed(1241060320) M <- 100 #M<-10000 contrived.run <- metropolis.krige(y ~ x.1 + x.2, coords = c("s.1","s.2"), data = ContrivedData, n.iter = M, range.tol = 0.05) # Parametric semivariagram semivariogram(contrived.run, bins=13, terms = c("raw", "residual", "parametric"), type= c(raw = "p", residual = "p", parametric = "l"), legend = TRUE, col = c("black", "blue", "red"), pch = c(1,3,NA), lty = c(NA,NA,1)) # Alternatively, the generic function plot can also be applied to krige object plot(contrived.run) # Plot semivariance object plot(semivariance(contrived.run, bins=13)) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.