Title: | Analysis of Geostatistical Data |
---|---|
Description: | Geostatistical analysis including variogram-based, likelihood-based and Bayesian methods. Software companion for Diggle and Ribeiro (2007) <doi:10.1007/978-0-387-48536-2>. |
Authors: | Paulo Justiniano Ribeiro Jr [aut, cre] <[email protected]>, Peter Diggle [aut, cre] <[email protected]>, Ole Christensen [ctb], Martin Schlather [ctb], Roger Bivand [ctb], Brian Ripley [ctb] |
Maintainer: | Paulo Justiniano Ribeiro Jr <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.9-4 |
Built: | 2024-11-12 06:29:24 UTC |
Source: | CRAN |
This function adapts the R function nlm
to allow for
constraints (upper and/or lower bounds) in the values of the parameters.
.nlmP(objfunc, params, lower=rep(-Inf, length(params)), upper=rep(+Inf, length(params)), ...)
.nlmP(objfunc, params, lower=rep(-Inf, length(params)), upper=rep(+Inf, length(params)), ...)
objfunc |
the function to be minimized. |
params |
starting values for the parameters. |
lower |
lower bounds for the variables. Defaults to |
upper |
upper bounds for the variables. Defaults to |
... |
further arguments to be passed to the function
|
Constraints on the parameter values are internally imposed by using exponential, logarithmic, and logit transformation of the parameter values.
The output is the same as for the function nlm
.
Patrick E. Brown [email protected].
Adapted and included in geoR by
Paulo Justiniano Ribeiro Jr. [email protected]
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
The default method converts a matrix or a data-frame
to an object of the
class
"geodata"
.
Objects of the class "geodata"
are lists with two obligatory
components: coords
and data
.
Optional components are allowed and a typical example is a vector or
matrix with covariate(s) values.
as.geodata(obj, ...) ## Default S3 method: as.geodata(obj, coords.col = 1:2, data.col = 3, data.names = NULL, covar.col = NULL, covar.names = "obj.names", units.m.col = NULL, realisations = NULL, na.action = c("ifany", "ifdata", "ifcovar", "none"), rep.data.action, rep.covar.action, rep.units.action, ...) ## S3 method for class 'geodata' as.data.frame(x, ..., borders = TRUE) ## S3 method for class 'geodata.frame' as.geodata(obj, ...) ## S3 method for class 'SpatialPointsDataFrame' as.geodata(obj, data.col = 1, ...) is.geodata(x)
as.geodata(obj, ...) ## Default S3 method: as.geodata(obj, coords.col = 1:2, data.col = 3, data.names = NULL, covar.col = NULL, covar.names = "obj.names", units.m.col = NULL, realisations = NULL, na.action = c("ifany", "ifdata", "ifcovar", "none"), rep.data.action, rep.covar.action, rep.units.action, ...) ## S3 method for class 'geodata' as.data.frame(x, ..., borders = TRUE) ## S3 method for class 'geodata.frame' as.geodata(obj, ...) ## S3 method for class 'SpatialPointsDataFrame' as.geodata(obj, data.col = 1, ...) is.geodata(x)
obj |
a matrix or data-frame where each line corresponds to one
spatial location. It should contain values of 2D coordinates,
data and, optionally, covariate(s) value(s) at the locations.
A method for |
coords.col |
a vector with the column numbers corresponding to the spatial coordinates. |
data.col |
a scalar or vector with column number(s) corresponding to the data. |
data.names |
optional. A string or vector of strings with names for the data columns. Only valid if there is more than one column of data. By default, takes the names from the original object. |
covar.col |
optional. A scalar or numeric vector with the column number(s) corresponding to the covariate(s). Alternativelly can be a character vector with the names of the covariates. |
covar.names |
optional. A string or vector of strings with the name(s) of the covariates. By default take the names from the original object. |
units.m.col |
optional. A scalar with the column number corresponding to the offset variable. Alternativelly can be a character vector with the name of the offset. This option is particularly relevant when using the package geoRglm. All values must be greater then zero. |
realisations |
optional. A vector indicating the realisation
number or a number indicating a column in |
na.action |
string defining action to be taken in the presence of
|
rep.data.action |
a string or a function. Defines action to be taken when there is more than
one data at the same location. The default option |
rep.covar.action |
idem to |
x |
an object which is tested for the class |
rep.units.action |
a string or a function.
Defines action to be taken on the element |
borders |
logical. If TRUE the element borders in the
|
... |
values to be passed for the methods. |
Objects of the class "geodata"
contain data for
geostatistical analysis using the package geoR.
Storing data in this format facilitates the usage of the functions in geoR.
However, conversion of objects to this class is not obligatory
to carry out the analysis.
NA
's are not allowed in the coordinates. By default the
respective rows will not be included in the output.
Realisations
Tipically geostatistical data correspond to a unique realisation of
the spatial process.
However, sometimes different "realisations" are possible.
For instance, if data are collected in the same area at different
points in time and independence between time points is assumed,
each time can be considered a different "replicate" or "realisation"
of the same process. The argument realisations
takes a vector
indication the replication number and can be passed to other geoR
functions as, for instance, likfit
.
The data format is similar to the usual geodata
format in
geoR.
Suppose there are realisations (times)
and for each realisations
observations are available.
The coordinates for different realisations
should be combined in a single
object,
where
.
Similarly for the data vector and covariates (if any).
grf objects
If an object of the class grf
is provided the functions just
extracts the elements coords
and data
of this object.
An object of the class
"geodata"
which is a list
with two obligatory components (coords and data)
and other optional components:
coords |
an |
data |
a vector of length |
covariates |
a vector of length |
realisations |
a vector on size |
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
read.geodata
for reading data from an
ASCII file and list
for general information on lists.
## Not run: ## converting the data-set "topo" from the package MASS (VR's bundle) ## to the geodata format: if(require(MASS)){ topo topogeo <- as.geodata(topo) names(topogeo) topogeo } ## End(Not run)
## Not run: ## converting the data-set "topo" from the package MASS (VR's bundle) ## to the geodata format: if(require(MASS)){ topo topogeo <- as.geodata(topo) names(topogeo) topogeo } ## End(Not run)
Functions related with the Box-Cox family of transformations.
Density and random generation for the Box-Cox transformed normal
distribution with mean
equal to mean
and standard deviation equal to sd
, in the normal scale.
rboxcox(n, lambda, lambda2 = NULL, mean = 0, sd = 1) dboxcox(x, lambda, lambda2 = NULL, mean = 0, sd = 1)
rboxcox(n, lambda, lambda2 = NULL, mean = 0, sd = 1) dboxcox(x, lambda, lambda2 = NULL, mean = 0, sd = 1)
lambda |
numerical value(s) for the transformation parameter
|
lambda2 |
logical or numerical value(s) of the additional transformation
(see DETAILS below). Defaults to |
n |
number of observations to be generated. |
x |
a vector of quantiles ( |
mean |
a vector of mean values at the normal scale. |
sd |
a vector of standard deviations at the normal scale. |
Denote the variable at the original scale and
the
transformed variable. The Box-Cox transformation is defined by:
.
An additional shifting parameter can be
included in which case the transformation is given by:
.
The function rboxcox
samples from the normal distribution using
the function
rnorm
and backtransform the values according to the
equations above to obtain values of .
If necessary the back-transformation truncates the values such that
results in
in the original scale.
Increasing the value of the mean and/or reducing the variance might help to avoid truncation.
The functions returns the following results:
rboxcox |
a vector of random deviates. |
dboxcox |
a vector of densities. |
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Box, G.E.P. and Cox, D.R.(1964) An analysis of transformations. JRSS B 26:211–246.
The parameter estimation function is boxcoxfit
.
Other packages has BoxCox related functions such as boxcox
in the package MASS and
the function box.cox
in the package ‘car’.
## Simulating data simul <- rboxcox(100, lambda=0.5, mean=10, sd=2) ## ## Comparing models with different lambdas, ## zero means and unit variances curve(dboxcox(x, lambda=-1), 0, 8) for(lambda in seq(-.5, 1.5, by=0.5)) curve(dboxcox(x, lambda), 0, 8, add = TRUE)
## Simulating data simul <- rboxcox(100, lambda=0.5, mean=10, sd=2) ## ## Comparing models with different lambdas, ## zero means and unit variances curve(dboxcox(x, lambda=-1), 0, 8) for(lambda in seq(-.5, 1.5, by=0.5)) curve(dboxcox(x, lambda), 0, 8, add = TRUE)
Method for Box-Cox transformation for objects of the class
geodata
assuming the data are independent.
Computes and optionally plots profile log-likelihoods for the parameter of the Box-Cox simple power transformation .
## S3 method for class 'geodata' boxcox(object, trend = "cte", ...)
## S3 method for class 'geodata' boxcox(object, trend = "cte", ...)
object |
an object of the class geodata. See |
trend |
specifies the mean part of the model. See
|
... |
arguments to be passed for the function
|
This is just a wrapper for the function boxcox
facilitating its usage with geodata
objects.
Notice this assume independent observations which is typically
not the case for geodata
objects.
A list of the lambda
vector and the computed profile log-likelihood vector, invisibly if the result is plotted.
boxcox
for
parameter estimation results for independent data and
likfit
for parameter estimation
within the geostatistical model.
if(require(MASS)){ boxcox(wolfcamp) data(ca20) boxcox(ca20, trend = ~altitude) }
if(require(MASS)){ boxcox(wolfcamp) data(ca20) boxcox(ca20, trend = ~altitude) }
Parameter estimation and plotting of the results for the Box-Cox transformed normal distribution.
boxcoxfit(object, xmat, lambda, lambda2 = NULL, add.to.data = 0, ...) ## S3 method for class 'boxcoxfit' print(x, ...) ## S3 method for class 'boxcoxfit' plot(x, hist = TRUE, data = eval(x$call$object), ...) ## S3 method for class 'boxcoxfit' lines(x, data = eval(x$call$object), ...)
boxcoxfit(object, xmat, lambda, lambda2 = NULL, add.to.data = 0, ...) ## S3 method for class 'boxcoxfit' print(x, ...) ## S3 method for class 'boxcoxfit' plot(x, hist = TRUE, data = eval(x$call$object), ...) ## S3 method for class 'boxcoxfit' lines(x, data = eval(x$call$object), ...)
object |
a vector with the data. |
xmat |
a matrix with covariates values. Defaults to |
lambda |
numerical value(s) for the transformation parameter
|
lambda2 |
logical or numerical value(s) of the additional transformation
(see DETAILS below). Defaults to |
add.to.data |
a constant value to be added to the data. |
x |
a list, typically an output of the function
|
hist |
logical indicating whether histograms should to be plotted. |
data |
data values. |
... |
extra parameters to be passed to the minimization
function |
The functions returns the following results:
boxcoxfit |
a list with estimated parameters and results on the numerical minimization. |
print.boxcoxfit |
print estimated parameters. No values returned. |
plot.boxcoxfit |
plots histogram of the data (optional) and
the model. No values returned. This function is only valid if
covariates are not included in |
lines.boxcoxfit |
adds a line with the fitted model to the
current plot. No values returned. This function is only valid if
covariates are not included in |
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Box, G.E.P. and Cox, D.R.(1964) An analysis of transformations. JRSS B 26:211–246.
rboxcox
and dboxcox
for the
expression and more on the Box-Cox transformation.
Parameter(s) are estimated using the minimization function optim
.
Other packages have BoxCox related functions such as boxcox
in the package MASS and
the function box.cox
in the package ‘car’.
set.seed(384) ## Simulating data simul <- rboxcox(100, lambda=0.5, mean=10, sd=2) ## Finding the ML estimates ml <- boxcoxfit(simul) ml ## Ploting histogram and fitted model plot(ml) ## ## Comparing models with different lambdas, ## zero means and unit variances curve(dboxcox(x, lambda=-1), 0, 8) for(lambda in seq(-.5, 1.5, by=0.5)) curve(dboxcox(x, lambda), 0, 8, add = TRUE) ## ## Another example, now estimating lambda2 ## simul <- rboxcox(100, lambda=0.5, mean=10, sd=2) ml <- boxcoxfit(simul, lambda2 = TRUE) ml plot(ml) ## ## An example with a regression model ## boxcoxfit(object = trees[,3], xmat = trees[,1:2])
set.seed(384) ## Simulating data simul <- rboxcox(100, lambda=0.5, mean=10, sd=2) ## Finding the ML estimates ml <- boxcoxfit(simul) ml ## Ploting histogram and fitted model plot(ml) ## ## Comparing models with different lambdas, ## zero means and unit variances curve(dboxcox(x, lambda=-1), 0, 8) for(lambda in seq(-.5, 1.5, by=0.5)) curve(dboxcox(x, lambda), 0, 8, add = TRUE) ## ## Another example, now estimating lambda2 ## simul <- rboxcox(100, lambda=0.5, mean=10, sd=2) ml <- boxcoxfit(simul, lambda2 = TRUE) ml plot(ml) ## ## An example with a regression model ## boxcoxfit(object = trees[,3], xmat = trees[,1:2])
This data set contains the calcium content measured in soil samples taken from the 0-20cm layer at 178 locations within a certain study area divided in three sub-areas. The elevation at each location was also recorded.
The first region is typically flooded during the rain season and not used as an experimental area. The calcium levels would represent the natural content in the region. The second region has received fertilisers a while ago and is typically occupied by rice fields. The third region has received fertilisers recently and is frequently used as an experimental area.
data(ca20)
data(ca20)
The object ca20
belongs to the class geodata
and is a list
with the following elements:
coords
a matrix with the coordinates of the soil samples.
data
calcium content measured in .
covariate
a data-frame with the covariates
altitude
a vector with the elevation of each
sampling location, in meters ().
area
a factor indicating the sub area to which the locations belongs.
borders
a matrix with the coordinates defining the borders of the area.
reg1
a matrix with the coordinates of the limits of the sub-area 1.
reg1
a matrix with the coordinates of the limits of the sub-area 2.
reg1
a matrix with the coordinates of the limits of the sub-area 3.
The data was collected by researchers from PESAGRO and EMBRAPA-Solos, Rio de Janeiro, Brasil and provided by Dra. Maria Cristina Neves de Oliveira.
Capeche, C.L.; Macedo, J.R.; Manzatto, H.R.H.; Silva, E.F. (1997) Caracterização pedológica da fazenda Angra - PESAGRO/RIO - Estação experimental de Campos (RJ). (compact disc). In: Congresso BRASILEIRO de Ciência do Solo. 26., Informação, globalização, uso do solo; Rio de Janeiro, 1997. trabalhos. Rio de Janeiro: Embrapa/SBCS.
Oliveira, M.C.N. (2003) Métodos de estimação de parâmetros em modelos geoestatísticos com diferentes estruturas de covariâncias: uma aplicação ao teor de cálcio no solo. Tese de Doutorado, ESALQ/USP/Brasil.
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
This data set contains the calcium content measured in soil samples taken from the 0-20cm layer at 178 locations within a certain study area divided in three sub-areas. The elevation at each location was also recorded.
The first region is tipically flooded during the rain season and not used as an experimental area. The calcium levels would represent the natural content in the region. The second region has received fertilizers a while ago and is tipically occupied by rice fields. The third region has recieved fertilizers recently and is frequently used as an experimental area.
data(camg)
data(camg)
A data frame with 178 observations on the following 10 variables.
east-west coordinates, in meters.
north-south coordinates, in meters.
elevation, in meters
a factor where numbers indicate different sub-regions within the area
calcium content in the 0-20cm soil layer, measured in .
calcium content in the 0-20cm soil layer, measured in .
calcium content in the 0-20cm soil layer.
calcium content in the 20-40cm soil layer, measured in .
calcium content in the 20-40cm soil layer, measured in .
calcium content in the 20-40cm soil layer.
More details about this data-set, including coordinates of the region
and sub-region borders
can be found in the data object ca20
.
The data was collected by researchers from PESAGRO and EMBRAPA-Solos, Rio de Janeiro, Brasil and provided by Dra. Maria Cristina Neves de Oliveira.
Capeche, C.L.; Macedo, J.R.; Manzatto, H.R.H.; Silva, E.F. (1997) Caracterização pedológica da fazenda Angra - PESAGRO/RIO - Estação experimental de Campos (RJ). (compact disc). In: Congresso BRASILEIRO de Ciência do Solo. 26., Informação, globalização, uso do solo; Rio de Janeiro, 1997. trabalhos. Rio de Janeiro: Embrapa/SBCS.
plot(camg[-(1:2),]) mg20 <- as.geodata(camg, data.col=6) plot(mg20) points(mg20)
plot(camg[-(1:2),]) mg20 <- as.geodata(camg, data.col=6) plot(mg20) points(mg20)
Transforms or back-transforms a set of coordinates according to the geometric anisotropy parameters.
coords.aniso(coords, aniso.pars, reverse = FALSE)
coords.aniso(coords, aniso.pars, reverse = FALSE)
coords |
an |
aniso.pars |
a vector with two elements, |
reverse |
logical. Defaults to |
Geometric anisotropy is defined by two parameters:
defined here as the azimuth angle of the direction with greater spatial continuity, i.e. the angle between the y-axis and the direction with the maximum range.
defined here as the ratio between the ranges of the directions with greater and smaller continuity, i.e. the ratio between maximum and minimum ranges. Therefore, its value is always greater or equal to one.
If reverse = FALSE
(the default) the
coordinates are transformed from the anisotropic space to the isotropic
space.
The transformation consists in multiplying the original
coordinates by a rotation matrix
and a
shrinking matrix
, as follows:
where is a matrix with the modified coordinates (isotropic
space) ,
is a matrix with original coordinates (anisotropic
space),
rotates coordinates according to the anisotropy angle
and
shrinks the coordinates according to
the anisotropy ratio
.
If reverse = TRUE
, the back-transformation is performed, i.e.
transforming the coordinates from the isotropic space to the
anisotropic space by computing:
An matrix with the transformed coordinates.
Paulo Justiniano Ribeiro Jr. [email protected]
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
op <- par(no.readonly = TRUE) par(mfrow=c(3,2)) par(mar=c(2.5,0,0,0)) par(mgp=c(2,.5,0)) par(pty="s") ## Defining a set of coordinates coords <- expand.grid(seq(-1, 1, l=3), seq(-1, 1, l=5)) plot(c(-1.5, 1.5), c(-1.5, 1.5), xlab="", ylab="", type="n") text(coords[,1], coords[,2], 1:nrow(coords)) ## Transforming coordinates according to some anisotropy parameters coordsA <- coords.aniso(coords, aniso.pars=c(0, 2)) plot(c(-1.5, 1.5), c(-1.5, 1.5), xlab="", ylab="", type="n") text(coordsA[,1], coordsA[,2], 1:nrow(coords)) ## coordsB <- coords.aniso(coords, aniso.pars=c(pi/2, 2)) plot(c(-1.5, 1.5), c(-1.5, 1.5), xlab="", ylab="", type="n") text(coordsB[,1], coordsB[,2], 1:nrow(coords)) ## coordsC <- coords.aniso(coords, aniso.pars=c(pi/4, 2)) plot(c(-1.5, 1.5), c(-1.5, 1.5), xlab="", ylab="", type="n") text(coordsC[,1], coordsC[,2], 1:nrow(coords)) ## coordsD <- coords.aniso(coords, aniso.pars=c(3*pi/4, 2)) plot(c(-1.5, 1.5), c(-1.5, 1.5), xlab="", ylab="", type="n") text(coordsD[,1], coordsD[,2], 1:nrow(coords)) ## coordsE <- coords.aniso(coords, aniso.pars=c(0, 5)) plot(c(-1.5, 1.5), c(-1.5, 1.5), xlab="", ylab="", type="n") text(coordsE[,1], coordsE[,2], 1:nrow(coords)) ## par(op)
op <- par(no.readonly = TRUE) par(mfrow=c(3,2)) par(mar=c(2.5,0,0,0)) par(mgp=c(2,.5,0)) par(pty="s") ## Defining a set of coordinates coords <- expand.grid(seq(-1, 1, l=3), seq(-1, 1, l=5)) plot(c(-1.5, 1.5), c(-1.5, 1.5), xlab="", ylab="", type="n") text(coords[,1], coords[,2], 1:nrow(coords)) ## Transforming coordinates according to some anisotropy parameters coordsA <- coords.aniso(coords, aniso.pars=c(0, 2)) plot(c(-1.5, 1.5), c(-1.5, 1.5), xlab="", ylab="", type="n") text(coordsA[,1], coordsA[,2], 1:nrow(coords)) ## coordsB <- coords.aniso(coords, aniso.pars=c(pi/2, 2)) plot(c(-1.5, 1.5), c(-1.5, 1.5), xlab="", ylab="", type="n") text(coordsB[,1], coordsB[,2], 1:nrow(coords)) ## coordsC <- coords.aniso(coords, aniso.pars=c(pi/4, 2)) plot(c(-1.5, 1.5), c(-1.5, 1.5), xlab="", ylab="", type="n") text(coordsC[,1], coordsC[,2], 1:nrow(coords)) ## coordsD <- coords.aniso(coords, aniso.pars=c(3*pi/4, 2)) plot(c(-1.5, 1.5), c(-1.5, 1.5), xlab="", ylab="", type="n") text(coordsD[,1], coordsD[,2], 1:nrow(coords)) ## coordsE <- coords.aniso(coords, aniso.pars=c(0, 5)) plot(c(-1.5, 1.5), c(-1.5, 1.5), xlab="", ylab="", type="n") text(coordsE[,1], coordsE[,2], 1:nrow(coords)) ## par(op)
Functions for shifting, zooming and envolving rectangle of a set of coordinates.
coords2coords(coords, xlim, ylim, xlim.ori, ylim.ori) zoom.coords(x, ...) ## Default S3 method: zoom.coords(x, xzoom, yzoom, xlim.ori, ylim.ori, xoff=0, yoff=0, ...) ## S3 method for class 'geodata' zoom.coords(x, ...) rect.coords(coords, xzoom = 1, yzoom=xzoom, add.to.plot=TRUE, quiet = FALSE, ...)
coords2coords(coords, xlim, ylim, xlim.ori, ylim.ori) zoom.coords(x, ...) ## Default S3 method: zoom.coords(x, xzoom, yzoom, xlim.ori, ylim.ori, xoff=0, yoff=0, ...) ## S3 method for class 'geodata' zoom.coords(x, ...) rect.coords(coords, xzoom = 1, yzoom=xzoom, add.to.plot=TRUE, quiet = FALSE, ...)
coords , x
|
two column matrix or data-frame with coordinates. |
xlim |
range of the new x-coordinates. |
ylim |
range of the new y-coordinates. |
xlim.ori |
optional. Range of the original x-coordinates, by default the range of the original x-coordinates. |
ylim.ori |
optional. Range of the original y-coordinates, by default the range of the original y-coordinates. |
xzoom |
scalar, expanding factor in the x-direction. |
yzoom |
scalar, expanding factor in the y-direction. |
xoff |
scalar, shift in the x-direction. |
yoff |
scalar, shift in the y-direction. |
add.to.plot |
logical, if |
quiet |
logical, none is returned. |
... |
further arguments to be passed to |
coords2coords and zoom.coords |
return an object of the same type as given in the argument
|
rect.coords |
returns a matrix with the 4 coordinates of the rectangle defined by the coordinates. |
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
foo <- matrix(c(4,6,6,4,2,2,4,4), nc=2) foo1 <- zoom.coords(foo, 2) foo1 foo2 <- coords2coords(foo, c(6,10), c(6,10)) foo2 plot(1:10, 1:10, type="n") polygon(foo) polygon(foo1, lty=2) polygon(foo2, lwd=2) arrows(foo[,1], foo[,2],foo1[,1],foo1[,2], lty=2) arrows(foo[,1], foo[,2],foo2[,1],foo2[,2]) legend("topleft", c("foo", "foo1 (zoom.coords)", "foo2 (coords2coords)"), lty=c(1,2,1), lwd=c(1,1,2)) ## "zooming" part of The Gambia map gb <- gambia.borders/1000 gd <- gambia[,1:2]/1000 plot(gb, ty="l", asp=1, xlab="W-E (kilometres)", ylab="N-S (kilometres)") points(gd, pch=19, cex=0.5) r1b <- gb[gb[,1] < 420,] rc1 <- rect.coords(r1b, lty=2) r1bn <- zoom.coords(r1b, 1.8, xoff=90, yoff=-90) rc2 <- rect.coords(r1bn, xz=1.05) segments(rc1[c(1,3),1],rc1[c(1,3),2],rc2[c(1,3),1],rc2[c(1,3),2], lty=3) lines(r1bn) r1d <- gd[gd[,1] < 420,] r1dn <- zoom.coords(r1d, 1.7, xlim.o=range(r1b[,1],na.rm=TRUE), ylim.o=range(r1b[,2], na.rm=TRUE), xoff=90, yoff=-90) points(r1dn, pch=19, cex=0.5) text(450,1340, "Western Region", cex=1.5)
foo <- matrix(c(4,6,6,4,2,2,4,4), nc=2) foo1 <- zoom.coords(foo, 2) foo1 foo2 <- coords2coords(foo, c(6,10), c(6,10)) foo2 plot(1:10, 1:10, type="n") polygon(foo) polygon(foo1, lty=2) polygon(foo2, lwd=2) arrows(foo[,1], foo[,2],foo1[,1],foo1[,2], lty=2) arrows(foo[,1], foo[,2],foo2[,1],foo2[,2]) legend("topleft", c("foo", "foo1 (zoom.coords)", "foo2 (coords2coords)"), lty=c(1,2,1), lwd=c(1,1,2)) ## "zooming" part of The Gambia map gb <- gambia.borders/1000 gd <- gambia[,1:2]/1000 plot(gb, ty="l", asp=1, xlab="W-E (kilometres)", ylab="N-S (kilometres)") points(gd, pch=19, cex=0.5) r1b <- gb[gb[,1] < 420,] rc1 <- rect.coords(r1b, lty=2) r1bn <- zoom.coords(r1b, 1.8, xoff=90, yoff=-90) rc2 <- rect.coords(r1bn, xz=1.05) segments(rc1[c(1,3),1],rc1[c(1,3),2],rc2[c(1,3),1],rc2[c(1,3),2], lty=3) lines(r1bn) r1d <- gd[gd[,1] < 420,] r1dn <- zoom.coords(r1d, 1.7, xlim.o=range(r1b[,1],na.rm=TRUE), ylim.o=range(r1b[,2], na.rm=TRUE), xoff=90, yoff=-90) points(r1dn, pch=19, cex=0.5) text(450,1340, "Western Region", cex=1.5)
Computes the covariances for pairs variables, given the separation distance of their locations. Options for different correlation functions are available. The results can be seen as a change of metric, from the Euclidean distances to covariances.
cov.spatial(obj, cov.model= "matern", cov.pars=stop("no cov.pars argument provided"), kappa = 0.5)
cov.spatial(obj, cov.model= "matern", cov.pars=stop("no cov.pars argument provided"), kappa = 0.5)
obj |
a numeric object (vector or matrix), typically with values of distances between pairs of spatial locations. |
cov.model |
string indicating the type of the correlation
function. Available choices are: "matern", "exponential", "gaussian",
"spherical", "circular", "cubic", "wave",
"power", "powered.exponential", "cauchy", "gencauchy",
"gneiting", "gneiting.matern", "pure.nugget".
See section |
cov.pars |
a vector with 2 elements or an |
kappa |
numerical value for the additional smoothness parameter of the
correlation function.
Only required by the following correlation
functions: |
Covariance functions return the value of the covariance
between a pair variables located at points separated by the
distance
.
The covariance function can be written as a product of a variance
parameter
times a positive definite
correlation function
:
The expressions of the covariance functions available in geoR are given below. We recommend the LaTeX (and/or the corresponding .dvi, .pdf or .ps) version of this document for better visualization of the formulas.
Denote the basic parameter of the correlation
function and name it the range parameter.
Some of the correlation functions will have an extra parameter
, the smoothness parameter.
denotes the modified Bessel
function of the third kind of order
. See
documentation of the function
besselK
for further details.
In the equations below the functions are valid for and
, unless stated otherwise.
cauchy
gencauchy (generalised Cauchy)
circular
Let and
Then, the circular model is given by:
cubic
gaussian
exponential
matern
spherical
power (and linear)
The parameters of the this model
and
can not be
interpreted as partial sill and range
as for the other models.
This model implies an unlimited dispersion and,
therefore, has no sill and corresponds to a process which is only
intrinsically stationary.
The variogram function is given by:
Since the corresponding process is not second order stationary the covariance and correlation functions are not defined. For internal calculations the geoR functions uses the fact the this model possesses locally stationary representations with covariance functions of the form:
,
where is a suitable constant as given in
Chiles & Delfiner (pag. 511, eq. 7.35).
The linear model corresponds a particular case with
.
powered.exponential (or stable)
gneiting
where
.
For further details see documentation of the function
CovarianceFct
in the package
RandomFields
from where we extract the following :
It is an alternative to the gaussian
model since
its graph is visually hardly distinguishable from the graph of
the Gaussian model, but possesses neither the mathematical and nor the
numerical disadvantages of the Gaussian model.
gneiting.matern
Let ,
denotes the
model
and
the Gneiting model. Then the
is given by
wave
pure.nugget
where k is a constant value. This model corresponds to
no spatial correlation.
Nested models
Models with several structures
usually called nested models
in the geostatistical literature are also allowed.
In this case the argument cov.pars
takes a matrix and
cov.model
and lambda
can either have length equal to
the number of rows of this matrix or length 1.
For the latter cov.model and/or lambda are recycled, i.e. the same
value is used for all structures.
The function returns values of the covariances corresponding to the
given distances.
The type of output is the same as the type of the object provided in the
argument obj
, typically a vector, matrix or array.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
For a review on correlation functions:
Schlather, M. (1999) An introduction to positive definite functions and to unconditional
simulation of random fields. Technical report ST 99-10, Dept. of Maths and Statistics,
Lancaster University.
Chilès, J.P. and Delfiner, P. (1999) Geostatistics: Modelling Spatial Uncertainty, Wiley.
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
matern
for computation of the
model,
besselK
for
computation of the Bessel function and
varcov.spatial
for computations related to the covariance matrix.
# # Variogram models with the same "practical" range: # v.f <- function(x, ...){1-cov.spatial(x, ...)} # curve(v.f(x, cov.pars=c(1, .2)), from = 0, to = 1, xlab = "distance", ylab = expression(gamma(h)), main = "variograms with equivalent \"practical range\"") curve(v.f(x, cov.pars = c(1, .6), cov.model = "sph"), 0, 1, add = TRUE, lty = 2) curve(v.f(x, cov.pars = c(1, .6/sqrt(3)), cov.model = "gau"), 0, 1, add = TRUE, lwd = 2) legend("topleft", c("exponential", "spherical", "gaussian"), lty=c(1,2,1), lwd=c(1,1,2)) # # Matern models with equivalent "practical range" # and varying smoothness parameter # curve(v.f(x, cov.pars = c(1, 0.25), kappa = 0.5),from = 0, to = 1, xlab = "distance", ylab = expression(gamma(h)), lty = 2, main = "models with equivalent \"practical\" range") curve(v.f(x, cov.pars = c(1, 0.188), kappa = 1),from = 0, to = 1, add = TRUE) curve(v.f(x, cov.pars = c(1, 0.14), kappa = 2),from = 0, to = 1, add = TRUE, lwd=2, lty=2) curve(v.f(x, cov.pars = c(1, 0.117), kappa = 2),from = 0, to = 1, add = TRUE, lwd=2) legend("bottomright", expression(list(kappa == 0.5, phi == 0.250), list(kappa == 1, phi == 0.188), list(kappa == 2, phi == 0.140), list(kappa == 3, phi == 0.117)), lty=c(2,1,2,1), lwd=c(1,1,2,2)) # plotting a nested variogram model curve(v.f(x, cov.pars = rbind(c(.4, .2), c(.6,.3)), cov.model = c("sph","exp")), 0, 1, ylab='nested model')
# # Variogram models with the same "practical" range: # v.f <- function(x, ...){1-cov.spatial(x, ...)} # curve(v.f(x, cov.pars=c(1, .2)), from = 0, to = 1, xlab = "distance", ylab = expression(gamma(h)), main = "variograms with equivalent \"practical range\"") curve(v.f(x, cov.pars = c(1, .6), cov.model = "sph"), 0, 1, add = TRUE, lty = 2) curve(v.f(x, cov.pars = c(1, .6/sqrt(3)), cov.model = "gau"), 0, 1, add = TRUE, lwd = 2) legend("topleft", c("exponential", "spherical", "gaussian"), lty=c(1,2,1), lwd=c(1,1,2)) # # Matern models with equivalent "practical range" # and varying smoothness parameter # curve(v.f(x, cov.pars = c(1, 0.25), kappa = 0.5),from = 0, to = 1, xlab = "distance", ylab = expression(gamma(h)), lty = 2, main = "models with equivalent \"practical\" range") curve(v.f(x, cov.pars = c(1, 0.188), kappa = 1),from = 0, to = 1, add = TRUE) curve(v.f(x, cov.pars = c(1, 0.14), kappa = 2),from = 0, to = 1, add = TRUE, lwd=2, lty=2) curve(v.f(x, cov.pars = c(1, 0.117), kappa = 2),from = 0, to = 1, add = TRUE, lwd=2) legend("bottomright", expression(list(kappa == 0.5, phi == 0.250), list(kappa == 1, phi == 0.188), list(kappa == 2, phi == 0.140), list(kappa == 3, phi == 0.117)), lty=c(2,1,2,1), lwd=c(1,1,2,2)) # plotting a nested variogram model curve(v.f(x, cov.pars = rbind(c(.4, .2), c(.6,.3)), cov.model = c("sph","exp")), 0, 1, ylab='nested model')
This funtions takes an object with 2-D coordinates and returns the
positions of the duplicated coordinates. Also sets a method
for duplicated
dup.coords(x, ...) ## Default S3 method: dup.coords(x, ...) ## S3 method for class 'geodata' dup.coords(x, incomparables, ...) ## S3 method for class 'geodata' duplicated(x, incomparables, ...)
dup.coords(x, ...) ## Default S3 method: dup.coords(x, ...) ## S3 method for class 'geodata' dup.coords(x, incomparables, ...) ## S3 method for class 'geodata' duplicated(x, incomparables, ...)
x |
a two column numeric matrix or data frame. |
incomparables |
unused. Just for compatibility with
the generic function |
... |
arguments passed to |
Function and methods returns NULL
if there are no duplicates
locations.
Otherwise, the default method returns a list where each component is a vector with the positions or the rownames, if available, of the duplicates coordinates.
The method for geodata
returns a data-frame with
rownames equals to the positions of the duplicated coordinates,
the first column is a factor indicating duplicates and
the remaning are output of as.data.frame.geodata
.
Paulo Justiniano Ribeiro Jr. [email protected]
Peter J. Diggle [email protected].
as.geodata
for the definition of geodata class,
duplicated
for the base function to identify duplicated
values and jitterDupCoords
for a function which jitters
duplicated coordinates.
## simulating data dt <- grf(30, cov.p=c(1, .3)) ## "forcing" some duplicated locations dt$coords[4,] <- dt$coords[14,] <- dt$coords[24,] <- dt$coords[2,] dt$coords[17,] <- dt$coords[23,] <- dt$coords[8,] ## output of the method for geodata dup.coords(dt) ## which is the same as a method for duplicated() duplicated(dt) ## the default method: dup.coords(dt$coords)
## simulating data dt <- grf(30, cov.p=c(1, .3)) ## "forcing" some duplicated locations dt$coords[4,] <- dt$coords[14,] <- dt$coords[24,] <- dt$coords[2,] dt$coords[17,] <- dt$coords[23,] <- dt$coords[8,] ## output of the method for geodata dup.coords(dt) ## which is the same as a method for duplicated() duplicated(dt) ## the default method: dup.coords(dt$coords)
Surface elevation data taken from Davis (1972).
An onject of the class geodata
with elevation values at 52 locations.
data(elevation)
data(elevation)
An object of the class geodata
which is a list with the
following elements:
coords
x-y coordinates (multiples of 50 feet).
data
elevations (multiples of 10 feet).
Davis, J.C. (1973) Statistics and Data Analysis in Geology. Wiley.
summary(elevation) plot(elevation)
summary(elevation) plot(elevation)
Function to fit an empirical variogram "by eye" using an interactive Tcl-Tk interface.
eyefit(vario, silent = FALSE)
eyefit(vario, silent = FALSE)
vario |
An empirical variogram object as returned by the function
|
silent |
logical indicating wheather or not the fitted variogram must be returned. |
Returns a list of list with the model parameters for each of the saved fit(s).
Andreas Kiefer [email protected]
Paulo Justiniano Ribeiro Junior [email protected].
variofit
for least squares variogram fit,
likfit
for likelihood based parameter estimation
and krige.bayes
to obtain the posterior distribution for the model parameters.
Malaria prevalence in children recorded at villages in The Gambia, Africa.
data(gambia)
data(gambia)
Two objects are made available:
gambia
A data frame with 2035 observations on the following 8 variables.
x-coordinate of the village (UTM).
y-coordinate of the village (UTM).
presence (1) or absence (0) of malaria in a blood sample taken from the child.
age of the child, in days
indicator variable denoting whether (1) or not (0) the child regularly sleeps under a bed-net.
indicator variable denoting whether (1) or not (0) the bed-net is treated (coded 0 if netuse=0).
satellite-derived measure of the green-ness of vegetation in the immediate vicinity of the village (arbitrary units).
indicator variable denoting the presence (1) or absence (0) of a health center in the village.
gambia.borders
A data frame with 2 variables:
x-coordinate of the country borders.
y-coordinate of the country borders.
Thomson, M., Connor, S., D Alessandro, U., Rowlingson, B., Diggle, P., Cresswell, M. & Greenwood, B. (1999). Predicting malaria infection in Gambian children from satellite data and bednet use surveys: the importance of spatial correlation in the interpretation of results. American Journal of Tropical Medicine and Hygiene 61: 2–8.
Diggle, P., Moyeed, R., Rowlingson, B. & Thomson, M. (2002). Childhood malaria in The Gambia: a case-study in model-based geostatistics, Applied Statistics.
plot(gambia.borders, type="l", asp=1) points(gambia[,1:2], pch=19) # a built-in function for a zoomed map gambia.map() # Building a "village-level" data frame ind <- paste("x",gambia[,1], "y", gambia[,2], sep="") village <- gambia[!duplicated(ind),c(1:2,7:8)] village$prev <- as.vector(tapply(gambia$pos, ind, mean)) plot(village$green, village$prev)
plot(gambia.borders, type="l", asp=1) points(gambia[,1:2], pch=19) # a built-in function for a zoomed map gambia.map() # Building a "village-level" data frame ind <- paste("x",gambia[,1], "y", gambia[,2], sep="") village <- gambia[!duplicated(ind),c(1:2,7:8)] village$prev <- as.vector(tapply(gambia$pos, ind, mean)) plot(village$green, village$prev)
The functions listed here are no longer part of the package geoR as they are no longer needed.
geoRdefunct()
geoRdefunct()
The following functions are now defunct:
functionality incorporated by variofit
starting from package version ‘1.0-6’.
functionality incorporated by variofit
starting from package version ‘1.0-6’.
functionality incorporated by likfit
starting from package version ‘1.0-6’.
The related functions were also made defunct: likfit.nospatial
, loglik.spatial
,
proflik.nug
, proflik.phi
, proflik.ftau
.
functionally is redundant with dist
.
Global variance computation for a set of locations using the covarianve model
globalvar(geodata, locations, coords = geodata$coords, krige)
globalvar(geodata, locations, coords = geodata$coords, krige)
geodata |
an object of the class |
locations |
n by 2 matrix with a set of locations, typically a prediction grid |
coords |
data coordinates |
krige |
a list defining the model components and the type of
kriging. It can take an output to a call to |
An scalar with the value of the global variance
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Isaaks, E.S and Srivastava, R.M. (1989) An Introduction to Applied Geostatistics, pag. 508, eq. 20.7. Oxford University Press.
krige.conv
for the kriging algorithm.
grf()
generates (unconditional)
simulations of Gaussian random fields for
given covariance parameters.
grf(n, grid = "irreg", nx, ny, xlims = c(0, 1), ylims = c(0, 1), borders, nsim = 1, cov.model = "matern", cov.pars = stop("missing covariance parameters sigmasq and phi"), kappa = 0.5, nugget = 0, lambda = 1, aniso.pars, mean = 0, method, messages)
grf(n, grid = "irreg", nx, ny, xlims = c(0, 1), ylims = c(0, 1), borders, nsim = 1, cov.model = "matern", cov.pars = stop("missing covariance parameters sigmasq and phi"), kappa = 0.5, nugget = 0, lambda = 1, aniso.pars, mean = 0, method, messages)
n |
number of points (spatial locations) in each simulations. |
grid |
optional. An |
nx |
optional. Number of points in the X direction. |
ny |
optional. Number of points in the Y direction. |
xlims |
optional. Limits of the area in the X direction. Defaults
to |
ylims |
optional. Limits of the area in the Y direction. Defaults
to |
borders |
optional. Typically a two coluns matrix especifying a polygon. See DETAILS below. |
nsim |
Number of simulations. Defaults to 1. |
cov.model |
correlation function. See |
cov.pars |
a vector with 2 elements or an |
kappa |
additional smoothness parameter required only for the
following correlation
functions: |
nugget |
the value of the nugget effect parameter |
lambda |
value of the Box-Cox transformation parameter. The value |
aniso.pars |
geometric anisotropy parameters. By default an
isotropic field is assumed and this argument is ignored.
If a vector with 2 values is provided, with values for the
anisotropy angle |
mean |
a numerical vector, scalar or the same length of the data to be simulated. Defaults to zero. |
method |
simulation method with options for
|
messages |
logical, indicating
whether or not status messages are printed on the screen (or output device)
while the function is running. Defaults to |
For the methods "cholesky"
, "svd"
and "eigen"
the
simulation consists of multiplying a vector of standardized
normal deviates by a square root of the covariance matrix.
The square root of a matrix is not uniquely defined. These
three methods differs in the way they compute the
square root of the (positive definite) covariance matrix.
The argument borders
, if provides takes a
polygon data set following argument poly
for the splancs' function csr
, in case of
grid="reg"
or gridpts
, in case of
grid="irreg"
. For the latter the simulation will have
approximately “n” points.
grf
returns a list with the components:
coords |
an |
data |
a vector (if |
cov.model |
a string with the name of the correlation function. |
nugget |
the value of the nugget parameter. |
cov.pars |
a vector with the values of |
kappa |
value of the parameter |
lambda |
value of the Box-Cox transformation parameter
|
aniso.pars |
a vector with values of the anisotropy parameters, if provided in the function call. |
method |
a string with the name of the simulation method used. |
sim.dim |
a string "1d" or "2d" indicating the spatial dimension of the simulation. |
.Random.seed |
the random seed by the time the function was called. |
messages |
messages produced by the function describing the simulation. |
call |
the function call. |
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Wood, A.T.A. and Chan, G. (1994) Simulation of stationary Gaussian
process in .
Journal of Computatinal and Graphical Statistics, 3, 409–432.
Schlather, M. (1999) Introduction to positive definite functions and to unconditional simulation of random fields. Tech. Report ST–99–10, Dept Maths and Stats, Lancaster University.
Schlather, M. (2001) Simulation and Analysis of Random Fields. R-News 1 (2), p. 18-20.
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
plot.grf
and image.grf
for graphical output,
coords.aniso
for anisotropy coordinates transformation and chol
,
svd
and eigen
for methods of matrix
decomposition.
sim1 <- grf(100, cov.pars = c(1, .25)) # a display of simulated locations and values points(sim1) # empirical and theoretical variograms plot(sim1) ## alternative way plot(variog(sim1, max.dist=1)) lines.variomodel(sim1) # # a "smallish" simulation sim2 <- grf(441, grid = "reg", cov.pars = c(1, .25)) image(sim2) ## ## 1-D simulations using the same seed and different noise/signal ratios ## set.seed(234) sim11 <- grf(100, ny=1, cov.pars=c(1, 0.25), nug=0) set.seed(234) sim12 <- grf(100, ny=1, cov.pars=c(0.75, 0.25), nug=0.25) set.seed(234) sim13 <- grf(100, ny=1, cov.pars=c(0.5, 0.25), nug=0.5) ## par.ori <- par(no.readonly = TRUE) par(mfrow=c(3,1), mar=c(3,3,.5,.5)) yl <- range(c(sim11$data, sim12$data, sim13$data)) image(sim11, type="l", ylim=yl) image(sim12, type="l", ylim=yl) image(sim13, type="l", ylim=yl) par(par.ori) ## simulating within borders data(parana) pr1 <- grf(100, cov.pars=c(200, 40), borders=parana$borders, mean=500) points(pr1) pr1 <- grf(100, grid="reg", cov.pars=c(200, 40), borders=parana$borders) points(pr1) pr1 <- grf(100, grid="reg", nx=10, ny=5, cov.pars=c(200, 40), borders=parana$borders) points(pr1)
sim1 <- grf(100, cov.pars = c(1, .25)) # a display of simulated locations and values points(sim1) # empirical and theoretical variograms plot(sim1) ## alternative way plot(variog(sim1, max.dist=1)) lines.variomodel(sim1) # # a "smallish" simulation sim2 <- grf(441, grid = "reg", cov.pars = c(1, .25)) image(sim2) ## ## 1-D simulations using the same seed and different noise/signal ratios ## set.seed(234) sim11 <- grf(100, ny=1, cov.pars=c(1, 0.25), nug=0) set.seed(234) sim12 <- grf(100, ny=1, cov.pars=c(0.75, 0.25), nug=0.25) set.seed(234) sim13 <- grf(100, ny=1, cov.pars=c(0.5, 0.25), nug=0.5) ## par.ori <- par(no.readonly = TRUE) par(mfrow=c(3,1), mar=c(3,3,.5,.5)) yl <- range(c(sim11$data, sim12$data, sim13$data)) image(sim11, type="l", ylim=yl) image(sim12, type="l", ylim=yl) image(sim13, type="l", ylim=yl) par(par.ori) ## simulating within borders data(parana) pr1 <- grf(100, cov.pars=c(200, 40), borders=parana$borders, mean=500) points(pr1) pr1 <- grf(100, grid="reg", cov.pars=c(200, 40), borders=parana$borders) points(pr1) pr1 <- grf(100, grid="reg", nx=10, ny=5, cov.pars=c(200, 40), borders=parana$borders) points(pr1)
Measurements of potentiometric head at 29 locations in a regional confined sandstone aquifer. Extract from Kitanidis' book.
data(head)
data(head)
An object of the class geodata
which is a list with the elements:
coordinates of the data location.
the data vector with head measurements (feet).
Kitanidis, P.K. Introduction to geostatistics - applications in hidrology (1997). Cambridge University Press.
summary(head) plot(head)
summary(head) plot(head)
Plots histograms and/or density estimation with samples from the posterior distribution of the model parameters
## S3 method for class 'krige.bayes' hist(x, pars, density.est = TRUE, histogram = TRUE, ...)
## S3 method for class 'krige.bayes' hist(x, pars, density.est = TRUE, histogram = TRUE, ...)
x |
an object of the class |
pars |
a vector with the names of one or more of the model parameters. Defaults to all model parameters. Setting to -1 excludes the intercept. |
density.est |
logical indication whether a line with the density estimation should be added to the plot. |
histogram |
logical indicating whether the histogram is included in the plot. |
... |
further arguments for the plotting functions and or for the density estimation. |
Produces a plot in the currently graphics device.
Returns a invisible
list with the components:
histogram |
with the output of the function |
density.estimation |
with the output of the function
|
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
## See documentation for krige.bayes()
## See documentation for krige.bayes()
The hoef
data frame has 25 rows and 5 columns.
The data consists of a uniformity trial for which artificial
treatment effects were assign to the plots.
data(hoef)
data(hoef)
This data frame contains the following columns:
x-coordinate of the plot.
y-coordinate of the plot.
the artificial data.
the treatment number.
the data from the uniformity trial, without the treatment effect.
The treatment effects assign to the plots are:
Treatment 1:
Treatment 2:
Treatment 3:
Treatment 4:
Treatment 5:
Ver Hoef, J.M. & Cressie, N. (1993) Spatial statistics: analysis of field experiments. In Scheiner S.M. and Gurevitch, J. (Eds) Design and Analysis of Ecological Experiments. Chapman and Hall.
hoef.geo <- as.geodata(hoef, covar.col=4) summary(hoef) summary(hoef.geo) points(hoef.geo, cex.min=2, cex.max=2, pt.div="quintiles")
hoef.geo <- as.geodata(hoef, covar.col=4) summary(hoef) summary(hoef.geo) points(hoef.geo, cex.min=2, cex.max=2, pt.div="quintiles")
Methods for image, contour or perspective plot of a
realisation of a Gaussian
random field, simulated using the function grf
.
## S3 method for class 'grf' image(x, sim.number = 1, borders, x.leg, y.leg, ...) ## S3 method for class 'grf' contour(x, sim.number = 1, borders, filled = FALSE, ...) ## S3 method for class 'grf' persp(x, sim.number = 1, borders, ...)
## S3 method for class 'grf' image(x, sim.number = 1, borders, x.leg, y.leg, ...) ## S3 method for class 'grf' contour(x, sim.number = 1, borders, filled = FALSE, ...) ## S3 method for class 'grf' persp(x, sim.number = 1, borders, ...)
x |
an object of the class |
sim.number |
simulation number. Indicates the number of the simulation top be plotted. Only valid if the object contains more than one simulation. Defaults to 1. |
borders |
optional. Typically a two coluns matrix especifying a
polygon. Points outside the borders will be set no |
x.leg , y.leg
|
limits for the legend in the horizontal and vertical directions. |
filled |
logical. If |
... |
further arguments to be passed to the functions
|
An image or perspective plot is produced on the current graphics device. No values are returned.
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information about the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
grf
for simulation of Gaussian random fields,
image
and persp
for the generic plotting
functions.
# generating 4 simulations of a Gaussian random field sim <- grf(441, grid="reg", cov.pars=c(1, .25), nsim=4) op <- par(no.readonly = TRUE) par(mfrow=c(2,2), mar=c(3,3,1,1), mgp = c(2,1,0)) for (i in 1:4) image(sim, sim.n=i) par(op)
# generating 4 simulations of a Gaussian random field sim <- grf(441, grid="reg", cov.pars=c(1, .25), nsim=4) op <- par(no.readonly = TRUE) par(mfrow=c(2,2), mar=c(3,3,1,1), mgp = c(2,1,0)) for (i in 1:4) image(sim, sim.n=i) par(op)
This function produces an image or perspective plot of a selected
element
of the predictive distribution
returned by the function krige.bayes
.
## S3 method for class 'krige.bayes' image(x, locations, borders, values.to.plot=c("mean", "variance", "mean.simulations", "variance.simulations", "quantiles", "probabilities", "simulation"), number.col, coords.data, x.leg, y.leg, messages, ...) ## S3 method for class 'krige.bayes' contour(x, locations, borders, values.to.plot = c("mean", "variance", "mean.simulations", "variance.simulations", "quantiles", "probabilities", "simulation"), filled=FALSE, number.col, coords.data, x.leg, y.leg, messages, ...) ## S3 method for class 'krige.bayes' persp(x, locations, borders, values.to.plot=c("mean", "variance", "mean.simulations", "variance.simulations", "quantiles", "probabilities", "simulation"), number.col, messages, ...)
## S3 method for class 'krige.bayes' image(x, locations, borders, values.to.plot=c("mean", "variance", "mean.simulations", "variance.simulations", "quantiles", "probabilities", "simulation"), number.col, coords.data, x.leg, y.leg, messages, ...) ## S3 method for class 'krige.bayes' contour(x, locations, borders, values.to.plot = c("mean", "variance", "mean.simulations", "variance.simulations", "quantiles", "probabilities", "simulation"), filled=FALSE, number.col, coords.data, x.leg, y.leg, messages, ...) ## S3 method for class 'krige.bayes' persp(x, locations, borders, values.to.plot=c("mean", "variance", "mean.simulations", "variance.simulations", "quantiles", "probabilities", "simulation"), number.col, messages, ...)
x |
an object of the class |
locations |
an |
borders |
an |
values.to.plot |
select the element of the predictive distribution to be plotted. See DETAILS below. |
filled |
logical. If |
number.col |
Specifies the number of the column to be plotted.
Only used if previous argument is set to one of |
coords.data |
optional. If an |
x.leg , y.leg
|
limits for the legend in the horizontal and vertical directions. |
messages |
logical, if TRUE status messages are printed while running the function. |
... |
extra arguments to be passed to the plotting function
|
The function krige.bayes
returns
summaries and other results about the predictive distributions.
The argument values.to.plot
specifies which result will be
plotted. It can be passed to the function in two different forms:
a vector with the object containing the values to be plotted, or
one of the following options: "moments.mean"
,
"moments.variance"
,
"mean.simulations"
,
"variance.simulations"
,
"quantiles"
,
"probability"
or
"simulation"
.
For the last three options, if the results are stored in matrices,
a column number must be provided using the argument number.col
.
The documentation for the function krige.bayes
provides
further details about these options.
An image
or persp
plot is produced on the
current graphics device. No values are returned.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
krige.bayes
for Bayesian Kriging computations and, image
and persp
for the generic plotting functions.
#See examples in the documentation for the function krige.bayes().
#See examples in the documentation for the function krige.bayes().
Plots image or perspective plots with results of the kriging calculations.
## S3 method for class 'kriging' image(x, locations, borders, values = x$predict, coords.data, x.leg, y.leg, ...) ## S3 method for class 'kriging' contour(x, locations, borders, values = x$predict, coords.data, filled=FALSE, ...) ## S3 method for class 'kriging' persp(x, locations, borders, values = x$predict, ...)
## S3 method for class 'kriging' image(x, locations, borders, values = x$predict, coords.data, x.leg, y.leg, ...) ## S3 method for class 'kriging' contour(x, locations, borders, values = x$predict, coords.data, filled=FALSE, ...) ## S3 method for class 'kriging' persp(x, locations, borders, values = x$predict, ...)
x |
an object of the class |
locations |
an |
borders |
an |
values |
a vector with values to be plotted. Defaults to |
coords.data |
optional. If an |
x.leg , y.leg
|
limits for the legend in the horizontal and vertical directions. |
filled |
logical. If |
... |
further arguments to be passed to the functions
|
plot1d
and prepare.graph.kriging
are auxiliary functions
called by the others.
An image or perspective plot is produced o the current graphics device. No values are returned.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
krige.conv
and ksline
for kriging
calculations. Documentation for
image
, contour
, filled.contour
and persp
contain basic information
on the plotting functions.
loci <- expand.grid(seq(0,1,l=51), seq(0,1,l=51)) kc <- krige.conv(s100, loc=loci, krige=krige.control(cov.pars=c(1, .25))) image(kc) contour(kc) image(kc) contour(kc, add=TRUE, nlev=21) persp(kc, theta=20, phi=20) contour(kc, filled=TRUE) contour(kc, filled=TRUE, color=terrain.colors) contour(kc, filled=TRUE, col=gray(seq(1,0,l=21))) # adding data locations image(kc, coords.data=s100$coords) contour(kc,filled=TRUE,coords.data=s100$coords,color=terrain.colors) # # now dealing with borders # bor <- matrix(c(.4,.1,.3,.9,.9,.7,.9,.7,.3,.2,.5,.8), ncol=2) # plotting just inside borders image(kc, borders=bor) contour(kc, borders=bor) image(kc, borders=bor) contour(kc, borders=bor, add=TRUE) contour(kc, borders=bor, filled=TRUE, color=terrain.colors) # kriging just inside borders kc1 <- krige.conv(s100, loc=loci, krige=krige.control(cov.pars=c(1, .25)), borders=bor) image(kc1) contour(kc1) # avoiding the borders image(kc1, borders=NULL) contour(kc1, borders=NULL) op <- par(no.readonly = TRUE) par(mfrow=c(1,2), mar=c(3,3,0,0), mgp=c(1.5, .8,0)) image(kc) image(kc, val=sqrt(kc$krige.var)) # different ways to add the legends and pass arguments: image(kc, ylim=c(-0.2, 1), x.leg=c(0,1), y.leg=c(-0.2, -0.1)) image(kc, val=kc$krige.var, ylim=c(-0.2, 1)) legend.krige(y.leg=c(-0.2,-0.1), x.leg=c(0,1), val=sqrt(kc$krige.var)) image(kc, ylim=c(-0.2, 1), x.leg=c(0,1), y.leg=c(-0.2, -0.1), cex=1.5) image(kc, ylim=c(-0.2, 1), x.leg=c(0,1), y.leg=c(-0.2, -0.1), offset.leg=0.5) image(kc, xlim=c(0, 1.2)) legend.krige(x.leg=c(1.05,1.1), y.leg=c(0,1), kc$pred, vert=TRUE) image(kc, xlim=c(0, 1.2)) legend.krige(x.leg=c(1.05,1.1), y.leg=c(0,1),kc$pred, vert=TRUE, off=1.5, cex=1.5) par(op)
loci <- expand.grid(seq(0,1,l=51), seq(0,1,l=51)) kc <- krige.conv(s100, loc=loci, krige=krige.control(cov.pars=c(1, .25))) image(kc) contour(kc) image(kc) contour(kc, add=TRUE, nlev=21) persp(kc, theta=20, phi=20) contour(kc, filled=TRUE) contour(kc, filled=TRUE, color=terrain.colors) contour(kc, filled=TRUE, col=gray(seq(1,0,l=21))) # adding data locations image(kc, coords.data=s100$coords) contour(kc,filled=TRUE,coords.data=s100$coords,color=terrain.colors) # # now dealing with borders # bor <- matrix(c(.4,.1,.3,.9,.9,.7,.9,.7,.3,.2,.5,.8), ncol=2) # plotting just inside borders image(kc, borders=bor) contour(kc, borders=bor) image(kc, borders=bor) contour(kc, borders=bor, add=TRUE) contour(kc, borders=bor, filled=TRUE, color=terrain.colors) # kriging just inside borders kc1 <- krige.conv(s100, loc=loci, krige=krige.control(cov.pars=c(1, .25)), borders=bor) image(kc1) contour(kc1) # avoiding the borders image(kc1, borders=NULL) contour(kc1, borders=NULL) op <- par(no.readonly = TRUE) par(mfrow=c(1,2), mar=c(3,3,0,0), mgp=c(1.5, .8,0)) image(kc) image(kc, val=sqrt(kc$krige.var)) # different ways to add the legends and pass arguments: image(kc, ylim=c(-0.2, 1), x.leg=c(0,1), y.leg=c(-0.2, -0.1)) image(kc, val=kc$krige.var, ylim=c(-0.2, 1)) legend.krige(y.leg=c(-0.2,-0.1), x.leg=c(0,1), val=sqrt(kc$krige.var)) image(kc, ylim=c(-0.2, 1), x.leg=c(0,1), y.leg=c(-0.2, -0.1), cex=1.5) image(kc, ylim=c(-0.2, 1), x.leg=c(0,1), y.leg=c(-0.2, -0.1), offset.leg=0.5) image(kc, xlim=c(0, 1.2)) legend.krige(x.leg=c(1.05,1.1), y.leg=c(0,1), kc$pred, vert=TRUE) image(kc, xlim=c(0, 1.2)) legend.krige(x.leg=c(1.05,1.1), y.leg=c(0,1),kc$pred, vert=TRUE, off=1.5, cex=1.5) par(op)
Density and random generation for the scaled inverse chi-squared
() distribution with
df
degrees of freedom and optional non-centrality parameter
scale
.
dinvchisq(x, df, scale, log = FALSE) rinvchisq(n, df, scale = 1/df)
dinvchisq(x, df, scale, log = FALSE) rinvchisq(n, df, scale = 1/df)
x |
vector of quantiles. |
n |
number of observations. If |
df |
degrees of freedom. |
scale |
scale parameter. |
log |
logical; if TRUE, densities d are given as log(d). |
The inverse chi-squared distribution with df
degrees of freedom has density
for .
The mean and variance are
and
.
The non-central chi-squared distribution with df
degrees of freedom and non-centrality parameter
scale
has density
,
for .
The first is a particular case of the latter for
.
dinvchisq
gives the density and rinvchisq
generates random deviates.
rchisq
for the chi-squared distribution which
is the basis for this function.
set.seed(1234); rinvchisq(5, df=2) set.seed(1234); 1/rchisq(5, df=2) set.seed(1234); rinvchisq(5, df=2, scale=5) set.seed(1234); 5*2/rchisq(5, df=2) ## inverse Chi-squared is a particular case x <- 1:10 all.equal(dinvchisq(x, df=2), dinvchisq(x, df=2, scale=1/2))
set.seed(1234); rinvchisq(5, df=2) set.seed(1234); 1/rchisq(5, df=2) set.seed(1234); rinvchisq(5, df=2, scale=5) set.seed(1234); 5*2/rchisq(5, df=2) ## inverse Chi-squared is a particular case x <- 1:10 all.equal(dinvchisq(x, df=2), dinvchisq(x, df=2, scale=1/2))
Toy example used in the book An Introduction to Geostatistics to illustrate the effects of different models and parameters in the kriging results when predicting at a given point.
data(isaaks)
data(isaaks)
An object of the class geodata
which is a list with the elements:
coordinates of the data location.
the data vector.
coordinate of the prediction point.
Isaaks, E.H. & Srisvastava, R.M. (1989) An Introduction to Applied Geostatistics. Oxford University Press.
isaaks summary(isaaks) plot(isaaks$coords, asp=1, type="n") text(isaaks$coords, as.character(isaaks$data)) points(isaaks$x0, pch="?", cex=2, col=2)
isaaks summary(isaaks) plot(isaaks$coords, asp=1, type="n") text(isaaks$coords, as.character(isaaks$data)) points(isaaks$x0, pch="?", cex=2, col=2)
Jitters 2D coordinates uniformily on a region around (duplicated) points.
jitter2d(coords, max, min = 0.2 * max, fix.one = TRUE, which.fix = c("random", "first", "last")) jitterDupCoords(x, ...) ## Default S3 method: jitterDupCoords(x, ...) ## S3 method for class 'geodata' jitterDupCoords(x, ...)
jitter2d(coords, max, min = 0.2 * max, fix.one = TRUE, which.fix = c("random", "first", "last")) jitterDupCoords(x, ...) ## Default S3 method: jitterDupCoords(x, ...) ## S3 method for class 'geodata' jitterDupCoords(x, ...)
x , coords
|
a matrix or data frame with 2D coordinates or geodata object. |
max |
numeric scalar defining maximum jittering distance. |
min |
numeric scalar defining minimum jittering distance. |
fix.one |
logical. Whether or not one of the coordinates should not be jittered. |
which.fix |
single element vector of integer or character,
defining which coordinate won't be jittered. Only used if |
... |
arguments passed to |
jitter2d
returns an object of the same type fo the input with
jittered values
jitterDupCoords
returns an object of the same type fo the input with
jittered coordinate values only at the duplicated locations
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
dup.coords
, duplicated.geodata
for
functions identifying duplicated locations.
## simulating data dt <- grf(30, cov.p=c(1, .3)) dt$coords <- round(dt$coords, dig=2) ## "forcing" some duplicated locations dt$coords[4,] <- dt$coords[14,] <- dt$coords[24,] <- dt$coords[2,] dt$coords[17,] <- dt$coords[23,] <- dt$coords[8,] ## jittering a matrix of duplicated coordinates dt$coords[c(2,4,14,24),] jitter2d(dt$coords[c(2,4,14,24),], max=0.01) ## jittering only the duplicated locations and comparing with original cbind(dt$coords, jitterDupCoords(dt$coords, max=0.01)) ## creating a now geodata object jittering the duplicated locations of the original one: dup.coords(dt) dt1 <- jitterDupCoords(dt, max=0.01) dup.coords(dt1)
## simulating data dt <- grf(30, cov.p=c(1, .3)) dt$coords <- round(dt$coords, dig=2) ## "forcing" some duplicated locations dt$coords[4,] <- dt$coords[14,] <- dt$coords[24,] <- dt$coords[2,] dt$coords[17,] <- dt$coords[23,] <- dt$coords[8,] ## jittering a matrix of duplicated coordinates dt$coords[c(2,4,14,24),] jitter2d(dt$coords[c(2,4,14,24),], max=0.01) ## jittering only the duplicated locations and comparing with original cbind(dt$coords, jitterDupCoords(dt$coords, max=0.01)) ## creating a now geodata object jittering the duplicated locations of the original one: dup.coords(dt) dt1 <- jitterDupCoords(dt, max=0.01) dup.coords(dt1)
Salinity measurements at the Kattegat basin, Denmark.
data(kattegat)
data(kattegat)
An object of the class
"geodata"
,
which is list with three components:
coords
the coordinates of the data locations. The distance are given in kilometers.
data
values of the piezometric head. The unit is heads to meters.
dk
a list with cooordinates of lines defining borders and islands across the study area.
National Environmental Research Institute, Arhus University, Denmark and the Swedish Meteorological and Hydrological Institute.
Diggle, P. J. and Lophaven, S. (2006). Bayesian geostatistical design. Scandinavian Journal of Statistics, 33: 55-64.
plot(c(550,770),c(6150,6420),type="n",xlab="X UTM",ylab="Y UTM") points(kattegat, add=TRUE) lapply(kattegat$dk, lines, lwd=2)
plot(c(550,770),c(6150,6420),type="n",xlab="X UTM",ylab="Y UTM") points(kattegat, add=TRUE) lapply(kattegat$dk, lines, lwd=2)
The function krige.bayes
performs Bayesian analysis of
geostatistical data allowing specifications of
different levels of uncertainty in the model parameters.
It returns results on the posterior distributions for the model
parameters and on the predictive distributions for prediction
locations (if provided).
krige.bayes(geodata, coords = geodata$coords, data = geodata$data, locations = "no", borders, model, prior, output) model.control(trend.d = "cte", trend.l = "cte", cov.model = "matern", kappa = 0.5, aniso.pars = NULL, lambda = 1) prior.control(beta.prior = c("flat", "normal", "fixed"), beta = NULL, beta.var.std = NULL, sigmasq.prior = c("reciprocal", "uniform", "sc.inv.chisq", "fixed"), sigmasq = NULL, df.sigmasq = NULL, phi.prior = c("uniform", "exponential","fixed", "squared.reciprocal", "reciprocal"), phi = NULL, phi.discrete = NULL, tausq.rel.prior = c("fixed", "uniform", "reciprocal"), tausq.rel, tausq.rel.discrete = NULL) post2prior(obj)
krige.bayes(geodata, coords = geodata$coords, data = geodata$data, locations = "no", borders, model, prior, output) model.control(trend.d = "cte", trend.l = "cte", cov.model = "matern", kappa = 0.5, aniso.pars = NULL, lambda = 1) prior.control(beta.prior = c("flat", "normal", "fixed"), beta = NULL, beta.var.std = NULL, sigmasq.prior = c("reciprocal", "uniform", "sc.inv.chisq", "fixed"), sigmasq = NULL, df.sigmasq = NULL, phi.prior = c("uniform", "exponential","fixed", "squared.reciprocal", "reciprocal"), phi = NULL, phi.discrete = NULL, tausq.rel.prior = c("fixed", "uniform", "reciprocal"), tausq.rel, tausq.rel.discrete = NULL) post2prior(obj)
geodata |
a list containing elements |
coords |
an |
data |
a vector with n data values. By default it takes the
component |
locations |
an |
borders |
optional. If missing,
by default reads the element |
model |
a list defining the fixed components of the model.
It can take an output to a call to |
prior |
a list with the specification of priors for the model
parameters.
It can take an output to a call to |
output |
a list specifying output options.
It can take an output to a call to |
trend.d |
specifies the trend (covariates) values at the data
locations. See documentation
of |
trend.l |
specifies the trend (covariates) at the prediction
locations. Must be of the same type as defined for |
cov.model |
string indicating the name of the model for the correlation function. Further details in the
documentation for |
kappa |
additional smoothness parameter. Only used if the
correlation function is one of: |
aniso.pars |
fixed parameters for geometric anisotropy
correction. If |
lambda |
numerical value of the Box-Cox transformation parameter.
The value |
beta.prior |
prior distribution for the mean (vector)
parameter |
beta |
mean hyperparameter for the distribution of the mean (vector) parameter |
beta.var.std |
standardised (co)variance hyperparameter(s)
for the prior for the mean
(vector) parameter |
sigmasq.prior |
specifies the prior for the parameter
|
sigmasq |
fixed value of the sill parameter
|
df.sigmasq |
numerical. Number of degrees of freedom for the
prior for the parameter |
phi.prior |
prior distribution for the range parameter
|
phi |
fixed value of the range parameter |
phi.discrete |
support points of the discrete prior
for the range parameter |
tausq.rel.prior |
specifies a prior distribution for the
relative nugget parameter
|
tausq.rel |
fixed value for the relative nugget parameter.
Only used if
|
tausq.rel.discrete |
support points of the discrete prior
for the relative nugget parameter |
obj |
an object of the class |
krige.bayes
is a generic function for Bayesian geostatistical
analysis of (transformed) Gaussian where predictions take into account the parameter
uncertainty.
It can be set to run conventional kriging methods which
use known parameters or plug-in estimates. However, the
functions krige.conv
and ksline
are preferable for
prediction with fixed parameters.
PRIOR SPECIFICATION
The basis of the Bayesian algorithm is the discretisation of the prior
distribution for the parameters and
.
The Tech. Report (see
References
below)
provides details on the results used in the current implementation.
The expressions of the implemented priors for the parameter
are:
.
.
.
.
fixed known or estimated value of .
The expressions of the implemented priors for the parameter
are:
fixed known or estimated value of
. Defaults to zero.
.
.
Apart from those a user defined prior can be specifyed by
entering a vector of probabilities for a discrete distribution
with suport points given by the argument phi.discrete
and/or
tausq.rel.discrete
.
CONTROL FUNCTIONS
The function call includes auxiliary control functions which allows
the user to specify and/or change the specification of model
components
(using model.control
), prior
distributions (using prior.control
) and
output options (using output.control
).
Default options are available in most of the cases.
An object with class
"krige.bayes"
and
"kriging"
.
The attribute prediction.locations
containing the name of the
object with the coordinates of the prediction locations (argument
locations
) is assigned to the object.
Returns a list with the following components:
posterior |
results on on the posterior distribution of the
model parameters. A list with the following possible components: |
summary information on the posterior distribution
of the mean parameter .
summary information on the posterior distribution
of the variance parameter (partial sill).
summary information on the posterior distribution
of the correlation parameter (range parameter) .
summary information on the posterior distribution
of the relative nugget variance parameter
.
information on discrete the joint distribution of these parameters.
a data.frame with a sample from the posterior distribution. Each column corresponds to one of the basic model parameters.
predictive |
results on the predictive distribution at the prediction locations, if provided. A list with the following possible components: |
expected values.
expected variance.
type of posterior distribution.
mean of the simulations at each locations.
variance of the simulations at each locations.
quantiles computed from the the simulations.
probabilities computed from the simulations.
simulations from the predictive distribution.
prior |
a list with information on the prior distribution
and hyper-parameters of the model parameters ( |
model |
model specification as defined by |
.Random.seed |
system random seed before running the function.
Allows reproduction of results. If
the |
max.dist |
maximum distance found between two data locations. |
call |
the function call. |
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Diggle, P.J. & Ribeiro Jr, P.J. (2002) Bayesian inference in Gaussian model-based geostatistics. Geographical and Environmental Modelling, Vol. 6, No. 2, 129-146.
The technical details about the implementation of krige.bayes
can be
found at:
Ribeiro, P.J. Jr. and Diggle, P.J. (1999) Bayesian inference in
Gaussian model-based geostatistics. Tech. Report ST-99-08, Dept
Maths and Stats, Lancaster University.
Available at:
http://www.leg.ufpr.br/geoR/geoRdoc/bayeskrige.pdf
Further information about geoR can be found at:
http://www.leg.ufpr.br/geoR/.
For a extended list of examples of the usage see http://www.leg.ufpr.br/geoR/tutorials/examples.krige.bayes.R and/or the geoR tutorials page at http://www.leg.ufpr.br/geoR/tutorials/.
lines.variomodel.krige.bayes
,
plot.krige.bayes
for outputs related to the
parameters in the model,
image.krige.bayes
and
persp.krige.bayes
for graphical output of
prediction results.
krige.conv
and
ksline
for conventional kriging methods.
## Not run: # generating a simulated data-set ex.data <- grf(70, cov.pars=c(10, .15), cov.model="matern", kappa=2) # # defining the grid of prediction locations: ex.grid <- as.matrix(expand.grid(seq(0,1,l=21), seq(0,1,l=21))) # # computing posterior and predictive distributions # (warning: the next command can be time demanding) ex.bayes <- krige.bayes(ex.data, loc=ex.grid, model = model.control(cov.m="matern", kappa=2), prior = prior.control(phi.discrete=seq(0, 0.7, l=51), phi.prior="reciprocal")) # # Prior and posterior for the parameter phi plot(ex.bayes, type="h", tausq.rel = FALSE, col=c("red", "blue")) # # Plot histograms with samples from the posterior par(mfrow=c(3,1)) hist(ex.bayes) par(mfrow=c(1,1)) # Plotting empirical variograms and some Bayesian estimates: # Empirical variogram plot(variog(ex.data, max.dist = 1), ylim=c(0, 15)) # Since ex.data is a simulated data we can plot the line with the "true" model lines.variomodel(ex.data, lwd=2) # adding lines with summaries of the posterior of the binned variogram lines(ex.bayes, summ = mean, lwd=1, lty=2) lines(ex.bayes, summ = median, lwd=2, lty=2) # adding line with summary of the posterior of the parameters lines(ex.bayes, summary = "mode", post = "parameters") # Plotting again the empirical variogram plot(variog(ex.data, max.dist=1), ylim=c(0, 15)) # and adding lines with median and quantiles estimates my.summary <- function(x){quantile(x, prob = c(0.05, 0.5, 0.95))} lines(ex.bayes, summ = my.summary, ty="l", lty=c(2,1,2), col=1) # Plotting some prediction results op <- par(no.readonly = TRUE) par(mfrow=c(2,2), mar=c(4,4,2.5,0.5), mgp = c(2,1,0)) image(ex.bayes, main="predicted values") image(ex.bayes, val="variance", main="prediction variance") image(ex.bayes, val= "simulation", number.col=1, main="a simulation from the \npredictive distribution") image(ex.bayes, val= "simulation", number.col=2, main="another simulation from \nthe predictive distribution") # par(op) ## End(Not run) ## ## For a extended list of exemples of the usage of krige.bayes() ## see http://www.leg.ufpr.br/geoR/tutorials/examples.krige.bayes.R ##
## Not run: # generating a simulated data-set ex.data <- grf(70, cov.pars=c(10, .15), cov.model="matern", kappa=2) # # defining the grid of prediction locations: ex.grid <- as.matrix(expand.grid(seq(0,1,l=21), seq(0,1,l=21))) # # computing posterior and predictive distributions # (warning: the next command can be time demanding) ex.bayes <- krige.bayes(ex.data, loc=ex.grid, model = model.control(cov.m="matern", kappa=2), prior = prior.control(phi.discrete=seq(0, 0.7, l=51), phi.prior="reciprocal")) # # Prior and posterior for the parameter phi plot(ex.bayes, type="h", tausq.rel = FALSE, col=c("red", "blue")) # # Plot histograms with samples from the posterior par(mfrow=c(3,1)) hist(ex.bayes) par(mfrow=c(1,1)) # Plotting empirical variograms and some Bayesian estimates: # Empirical variogram plot(variog(ex.data, max.dist = 1), ylim=c(0, 15)) # Since ex.data is a simulated data we can plot the line with the "true" model lines.variomodel(ex.data, lwd=2) # adding lines with summaries of the posterior of the binned variogram lines(ex.bayes, summ = mean, lwd=1, lty=2) lines(ex.bayes, summ = median, lwd=2, lty=2) # adding line with summary of the posterior of the parameters lines(ex.bayes, summary = "mode", post = "parameters") # Plotting again the empirical variogram plot(variog(ex.data, max.dist=1), ylim=c(0, 15)) # and adding lines with median and quantiles estimates my.summary <- function(x){quantile(x, prob = c(0.05, 0.5, 0.95))} lines(ex.bayes, summ = my.summary, ty="l", lty=c(2,1,2), col=1) # Plotting some prediction results op <- par(no.readonly = TRUE) par(mfrow=c(2,2), mar=c(4,4,2.5,0.5), mgp = c(2,1,0)) image(ex.bayes, main="predicted values") image(ex.bayes, val="variance", main="prediction variance") image(ex.bayes, val= "simulation", number.col=1, main="a simulation from the \npredictive distribution") image(ex.bayes, val= "simulation", number.col=2, main="another simulation from \nthe predictive distribution") # par(op) ## End(Not run) ## ## For a extended list of exemples of the usage of krige.bayes() ## see http://www.leg.ufpr.br/geoR/tutorials/examples.krige.bayes.R ##
This function performs spatial prediction for fixed covariance parameters using global neighbourhood.
Options available implement the following types of kriging: SK (simple kriging), OK (ordinary kriging), KTE (external trend kriging) and UK (universal kriging).
krige.conv(geodata, coords=geodata$coords, data=geodata$data, locations, borders, krige, output) krige.control(type.krige = "ok", trend.d = "cte", trend.l = "cte", obj.model = NULL, beta, cov.model, cov.pars, kappa, nugget, micro.scale = 0, dist.epsilon = 1e-10, aniso.pars, lambda)
krige.conv(geodata, coords=geodata$coords, data=geodata$data, locations, borders, krige, output) krige.control(type.krige = "ok", trend.d = "cte", trend.l = "cte", obj.model = NULL, beta, cov.model, cov.pars, kappa, nugget, micro.scale = 0, dist.epsilon = 1e-10, aniso.pars, lambda)
geodata |
a list containing elements |
coords |
an |
data |
a vector with n data values. By default it takes the
component |
locations |
an |
borders |
optional. By default reads the element |
krige |
a list defining the model components and the type of
kriging. It can take an output to a call to |
output |
a list specifying output options.
It can take an output to a call to |
type.krige |
type of kriging to be performed. Options are
|
trend.d |
specifies the trend (covariate) values at the data
locations.
See documentation of |
trend.l |
specifies the trend (covariate) values at prediction
locations. It must be of the same type as for |
obj.model |
a list with the model parameters. Typically an
output of |
beta |
numerical value of the mean (vector) parameter.
Only used if |
cov.model |
string indicating the name of the model for the
correlation function. Further details can be found in the
documentation of the function
|
cov.pars |
a 2 elements vector with values of the covariance parameters |
kappa |
additional smoothness parameter required by the following correlation
functions: |
nugget |
the value of the nugget variance parameter |
micro.scale |
micro-scale variance. If different from zero, the
nugget variance is divided into 2 terms: micro-scale variance
and measurement error. This affect the precision of the predictions.
Often in practice, these two variance components are indistinguishable but the
distinction can be made here if justifiable. See the section
|
dist.epsilon |
a numeric value. Locations which are separated by a distance less than this value are considered co-located. |
aniso.pars |
parameters for geometric anisotropy
correction. If |
lambda |
numeric value of the Box-Cox transformation parameter.
The value |
According to the arguments provided, one of the following different types of kriging: SK, OK, UK or KTE is performed. Defaults correspond to ordinary kriging.
An object of the class
kriging
.
The attribute prediction.locations
containing the name of the
object with the coordinates of the prediction locations (argument
locations
) is assigned to the object.
Returns a list with the following components:
predict |
a vector with predicted values. |
krige.var |
a vector with predicted variances. |
beta.est |
estimates of the |
simulations |
an |
message |
messages about the type of prediction performed. |
call |
the function call. |
Other results can be included depending on the options passed to
output.control
.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
output.control
sets output options,
image.kriging
and persp.kriging
for graphical output of the results,
krige.bayes
for Bayesian prediction and ksline
for a different implementation of kriging allowing for moving
neighborhood. For model fitting see likfit
or variofit
.
## Not run: # Defining a prediction grid loci <- expand.grid(seq(0,1,l=21), seq(0,1,l=21)) # predicting by ordinary kriging kc <- krige.conv(s100, loc=loci, krige=krige.control(cov.pars=c(1, .25))) # mapping point estimates and variances par.ori <- par(no.readonly = TRUE) par(mfrow=c(1,2), mar=c(3.5,3.5,1,0), mgp=c(1.5,.5,0)) image(kc, main="kriging estimates") image(kc, val=sqrt(kc$krige.var), main="kriging std. errors") # Now setting the output to simulate from the predictive # (obtaining conditional simulations), # and to compute quantile and probability estimators s.out <- output.control(n.predictive = 1000, quant=0.9, thres=2) set.seed(123) kc <- krige.conv(s100, loc = loci, krige = krige.control(cov.pars = c(1,.25)), output = s.out) par(mfrow=c(2,2)) image(kc, val=kc$simul[,1], main="a cond. simul.") image(kc, val=kc$simul[,1], main="another cond. simul.") image(kc, val=(1 - kc$prob), main="Map of P(Y > 2)") image(kc, val=kc$quant, main="Map of y s.t. P(Y < y) = 0.9") par(par.ori) ## End(Not run)
## Not run: # Defining a prediction grid loci <- expand.grid(seq(0,1,l=21), seq(0,1,l=21)) # predicting by ordinary kriging kc <- krige.conv(s100, loc=loci, krige=krige.control(cov.pars=c(1, .25))) # mapping point estimates and variances par.ori <- par(no.readonly = TRUE) par(mfrow=c(1,2), mar=c(3.5,3.5,1,0), mgp=c(1.5,.5,0)) image(kc, main="kriging estimates") image(kc, val=sqrt(kc$krige.var), main="kriging std. errors") # Now setting the output to simulate from the predictive # (obtaining conditional simulations), # and to compute quantile and probability estimators s.out <- output.control(n.predictive = 1000, quant=0.9, thres=2) set.seed(123) kc <- krige.conv(s100, loc = loci, krige = krige.control(cov.pars = c(1,.25)), output = s.out) par(mfrow=c(2,2)) image(kc, val=kc$simul[,1], main="a cond. simul.") image(kc, val=kc$simul[,1], main="another cond. simul.") image(kc, val=(1 - kc$prob), main="Map of P(Y > 2)") image(kc, val=kc$quant, main="Map of y s.t. P(Y < y) = 0.9") par(par.ori) ## End(Not run)
Computes the weights assign for each data point in simple and ordinary krigring
krweights(coords, locations, krige)
krweights(coords, locations, krige)
coords |
matrix with data coordinates |
locations |
matrix with coordinates of the prediciton points |
krige |
kriging parameters. See krige.control in krige.conv |
A matrix of weights
## Figure 8.4 in Webster and Oliver (2001), see help(wo) attach(wo) par(mfrow=c(2,2)) plot(c(-10,130), c(-10,130), ty="n", asp=1) points(rbind(coords, x1)) KC1 <- krige.control(cov.pars=c(0.382,90.53)) w1 <- krweights(wo$coords, loc=x1, krige=KC1) text(coords[,1], 5+coords[,2], round(w1, dig=3)) ## plot(c(-10,130), c(-10,130), ty="n", asp=1) points(rbind(coords, x1)) KC2 <- krige.control(cov.pars=c(0.282,90.53), nug=0.1) w2 <- krweights(wo$coords, loc=x1, krige=KC2) text(coords[,1], 5+coords[,2], round(w2, dig=3)) ## plot(c(-10,130), c(-10,130), ty="n", asp=1) points(rbind(coords, x1)) KC3 <- krige.control(cov.pars=c(0.082,90.53), nug=0.3) w3 <- krweights(wo$coords, loc=x1, krige=KC3) text(coords[,1], 5+coords[,2], round(w3, dig=3)) ## plot(c(-10,130), c(-10,130), ty="n", asp=1) points(rbind(coords, x1)) KC4 <- krige.control(cov.pars=c(0,90.53), nug=0.382, micro=0.382) w4 <- krweights(wo$coords, loc=x1, krige=KC4) text(coords[,1], 5+coords[,2], round(w4, dig=3)) ## ## SK vs OK ## plot(c(-10,130), c(-10,130), ty="n", asp=1) points(rbind(coords, x1)) KC5 <- krige.control(cov.pars=c(0.382,50)) w5 <- krweights(wo$coords, loc=x1, krige=KC5) KC6 <- krige.control(type="sk", beta=2, cov.pars=c(0.382,50)) w6 <- krweights(wo$coords, loc=x1, krige=KC6) text(coords[,1], 5+coords[,2], round(w5, dig=3)) text(coords[,1], -5+coords[,2], round(w6, dig=3)) ## plot(c(-10,130), c(-10,130), ty="n", asp=1) points(rbind(coords, x1)) KC7 <- krige.control(cov.pars=c(0.382,0)) w7 <- krweights(wo$coords, loc=x1, krige=KC7) KC8 <- krige.control(type="sk", beta=2, cov.pars=c(0.382,0)) w8 <- krweights(wo$coords, loc=x1, krige=KC8) text(coords[,1], 5+coords[,2], round(w7, dig=3)) text(coords[,1], -5+coords[,2], round(w8, dig=3))
## Figure 8.4 in Webster and Oliver (2001), see help(wo) attach(wo) par(mfrow=c(2,2)) plot(c(-10,130), c(-10,130), ty="n", asp=1) points(rbind(coords, x1)) KC1 <- krige.control(cov.pars=c(0.382,90.53)) w1 <- krweights(wo$coords, loc=x1, krige=KC1) text(coords[,1], 5+coords[,2], round(w1, dig=3)) ## plot(c(-10,130), c(-10,130), ty="n", asp=1) points(rbind(coords, x1)) KC2 <- krige.control(cov.pars=c(0.282,90.53), nug=0.1) w2 <- krweights(wo$coords, loc=x1, krige=KC2) text(coords[,1], 5+coords[,2], round(w2, dig=3)) ## plot(c(-10,130), c(-10,130), ty="n", asp=1) points(rbind(coords, x1)) KC3 <- krige.control(cov.pars=c(0.082,90.53), nug=0.3) w3 <- krweights(wo$coords, loc=x1, krige=KC3) text(coords[,1], 5+coords[,2], round(w3, dig=3)) ## plot(c(-10,130), c(-10,130), ty="n", asp=1) points(rbind(coords, x1)) KC4 <- krige.control(cov.pars=c(0,90.53), nug=0.382, micro=0.382) w4 <- krweights(wo$coords, loc=x1, krige=KC4) text(coords[,1], 5+coords[,2], round(w4, dig=3)) ## ## SK vs OK ## plot(c(-10,130), c(-10,130), ty="n", asp=1) points(rbind(coords, x1)) KC5 <- krige.control(cov.pars=c(0.382,50)) w5 <- krweights(wo$coords, loc=x1, krige=KC5) KC6 <- krige.control(type="sk", beta=2, cov.pars=c(0.382,50)) w6 <- krweights(wo$coords, loc=x1, krige=KC6) text(coords[,1], 5+coords[,2], round(w5, dig=3)) text(coords[,1], -5+coords[,2], round(w6, dig=3)) ## plot(c(-10,130), c(-10,130), ty="n", asp=1) points(rbind(coords, x1)) KC7 <- krige.control(cov.pars=c(0.382,0)) w7 <- krweights(wo$coords, loc=x1, krige=KC7) KC8 <- krige.control(type="sk", beta=2, cov.pars=c(0.382,0)) w8 <- krweights(wo$coords, loc=x1, krige=KC8) text(coords[,1], 5+coords[,2], round(w7, dig=3)) text(coords[,1], -5+coords[,2], round(w8, dig=3))
The data consists of 32 measurements of the saturated hydraulic conductivity of a soil.
data(Ksat)
data(Ksat)
The object Ksat
is a list of the class geodata
with the following elements:
coords
a matrix with the coordinates of the soil samples.
data
measurements of the saturated hidraulic conductivity.
borders
a data-frame with the coordinates of a polygon defining the borders of the area.
Data provided by Dr. Décio Cruciani, ESALQ/USP, Brasil.
summary(Ksat) plot(Ksat)
summary(Ksat) plot(Ksat)
This function performs spatial prediction for given covariance parameters. Options implement the following kriging types: SK (simple kriging), OK (ordinary kriging), KTE (external trend kriging) and UK (universal kriging).
The function krige.conv
should be preferred, unless
moving neighborhood is to be used.
ksline(geodata, coords = geodata$coords, data = geodata$data, locations, borders = NULL, cov.model = "matern", cov.pars=stop("covariance parameters (sigmasq and phi) needed"), kappa = 0.5, nugget = 0, micro.scale = 0, lambda = 1, m0 = "ok", nwin = "full", n.samples.backtransform = 500, trend = 1, d = 2, ktedata = NULL, ktelocations = NULL, aniso.pars = NULL, signal = FALSE, dist.epsilon = 1e-10, messages)
ksline(geodata, coords = geodata$coords, data = geodata$data, locations, borders = NULL, cov.model = "matern", cov.pars=stop("covariance parameters (sigmasq and phi) needed"), kappa = 0.5, nugget = 0, micro.scale = 0, lambda = 1, m0 = "ok", nwin = "full", n.samples.backtransform = 500, trend = 1, d = 2, ktedata = NULL, ktelocations = NULL, aniso.pars = NULL, signal = FALSE, dist.epsilon = 1e-10, messages)
geodata |
a list containing elements |
coords |
an |
data |
a vector with n data values. By default it takes the
component |
locations |
an |
borders |
optional. If a two column matrix defining a polygon is provided the prediction is performed only at locations inside this polygon. |
cov.pars |
a vector with 2 elements or an |
nugget |
the value of the nugget variance parameter |
micro.scale |
micro-scale variance. If different from zero, the nugget variance is divided into 2 terms: micro-scale variance and measurement error. This might affect the precision of the predictions. In practice, these two variance components are usually indistinguishable but the distinction can be made here if justifiable. |
cov.model |
string indicating the name of the model for the
correlation function. Further details in the
documentation for
|
kappa |
additional smoothness parameter required by the following correlation
functions: |
lambda |
numeric value of the Box-Cox transformation parameter.
The value |
m0 |
The default value |
nwin |
If |
n.samples.backtransform |
number of samples used in the
back-transformation. When transformations are used
(specified by an argument |
trend |
only required if |
d |
spatial dimension, |
ktedata |
only required if |
ktelocations |
only required if |
aniso.pars |
parameters for geometric anisotropy
correction. If |
signal |
logical. If |
dist.epsilon |
a numeric value. Points which are separated by a distance less than this value are considered co-located. |
messages |
logical. Indicates whether or not status messages are printed on the screen (or other output device) while the function is running. |
An object of the class
kriging
which is a list
with the following components:
predict |
the predicted values. |
krige.var |
the kriging variances. |
dif |
the difference between the predicted value and the global mean. Represents the contribution to the neighboring data to the prediction at each point. |
summary |
values of the arithmetic and weighted mean of the data and standard deviations. The weighted mean corresponds to the estimated value of the global mean. |
ktrend |
the matrix with trend if |
ktetrend |
the matrix with trend if |
beta |
the value of the mean which is implicitly estimated for
|
wofmean |
weight of mean. The predicted value is an weighted average between the global mean and the values at the neighboring locations. The value returned is the weight of the mean. |
locations |
the coordinates of the prediction locations. |
message |
status messages returned by the algorithm. |
call |
the function call. |
This is a preliminary and inefficient function implementing kriging methods.
For predictions using global neighborhood the function
krige.conv
should be used instead.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
krige.conv
for a more efficient implementation of
conventional kriging methods, krige.bayes
for Bayesian prediction.
loci <- expand.grid(seq(0,1,l=31), seq(0,1,l=31)) kc <- ksline(s100, loc=loci, cov.pars=c(1, .25)) par(mfrow=c(1,2)) image(kc, main="kriging estimates") image(kc, val=sqrt(kc$krige.var), main="kriging std. errors")
loci <- expand.grid(seq(0,1,l=31), seq(0,1,l=31)) kc <- ksline(s100, loc=loci, cov.pars=c(1, .25)) par(mfrow=c(1,2)) image(kc, main="kriging estimates") image(kc, val=sqrt(kc$krige.var), main="kriging std. errors")
Artificial or non-specified data from Paulo Landim's book
data(landim1)
data(landim1)
A data frame with 38 observations on the following 4 variables.
EW
a numeric vector with the east-west coordinates.
NS
a numeric vector with the north-south coordinates.
A
a numeric vector with data on a first variable.
B
a numeric vector with data on a second variable.
Landim, P. M. B. (2004) Análise estatística de dados geológicos. Editora Unesp. Data from Table~1, pg.12.
data(landim) plot(as.geodata(landim1, data.col=3)) plot(as.geodata(landim1, data.col=4))
data(landim) plot(as.geodata(landim1, data.col=3)) plot(as.geodata(landim1, data.col=4))
This function allows adds a legend to an image plot generated by
image.kriging
or image.krige.bayes
.
It can be called internally by these functions or directly by the user.
legend.krige(x.leg, y.leg, values, scale.vals, vertical = FALSE, offset.leg = 1, ...)
legend.krige(x.leg, y.leg, values, scale.vals, vertical = FALSE, offset.leg = 1, ...)
x.leg |
limits for the legend in the |
y.leg |
limits for the legend in the |
values |
values plotted in the image. |
scale.vals |
optional. Values to appear in the legend.
If not provided the function |
vertical |
If |
offset.leg |
numeric value controlling the distance between the legend text and the legend box. |
... |
further arguments to be passed to the function
|
A legend is added to the current plot. No values are returned.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
image.kriging
, image.krige.bayes
.
# See examples in the documentation for image.kriging
# See examples in the documentation for image.kriging
Maximum likelihood (ML) or restricted maximum likelihood (REML) parameter estimation for (transformed) Gaussian random fields.
likfit(geodata, coords = geodata$coords, data = geodata$data, trend = "cte", ini.cov.pars, fix.nugget = FALSE, nugget = 0, fix.kappa = TRUE, kappa = 0.5, fix.lambda = TRUE, lambda = 1, fix.psiA = TRUE, psiA = 0, fix.psiR = TRUE, psiR = 1, cov.model, realisations, lik.method = "ML", components = TRUE, nospatial = TRUE, limits = pars.limits(), print.pars = FALSE, messages, ...) ## S3 method for class 'likGRF' fitted(object, spatial = TRUE, ...) ## S3 method for class 'likGRF' resid(object, spatial = FALSE, ...)
likfit(geodata, coords = geodata$coords, data = geodata$data, trend = "cte", ini.cov.pars, fix.nugget = FALSE, nugget = 0, fix.kappa = TRUE, kappa = 0.5, fix.lambda = TRUE, lambda = 1, fix.psiA = TRUE, psiA = 0, fix.psiR = TRUE, psiR = 1, cov.model, realisations, lik.method = "ML", components = TRUE, nospatial = TRUE, limits = pars.limits(), print.pars = FALSE, messages, ...) ## S3 method for class 'likGRF' fitted(object, spatial = TRUE, ...) ## S3 method for class 'likGRF' resid(object, spatial = FALSE, ...)
geodata |
a list containing elements |
coords |
an |
data |
a vector with n data values. By default it takes the
component |
trend |
specifies the mean part of the model. See documentation
of |
ini.cov.pars |
initial values for the covariance parameters:
|
fix.nugget |
logical, indicating whether the parameter
|
nugget |
value of the nugget parameter.
Regarded as a fixed value if |
fix.kappa |
logical, indicating whether the extra parameter
|
kappa |
value of the extra parameter |
fix.lambda |
logical, indicating whether the Box-Cox transformation parameter
|
lambda |
value of the Box-Cox transformation parameter
|
fix.psiA |
logical, indicating whether the anisotropy angle parameter
|
psiA |
value (in radians) for the anisotropy angle parameter
|
fix.psiR |
logical, indicating whether the anisotropy ratio parameter
|
psiR |
value, always greater than 1, for the anisotropy ratio parameter
|
cov.model |
a string specifying the model for the correlation
function. For further details see documentation for |
realisations |
optional. Logical or a vector indicating the number of replication
for each datum. For further information see |
lik.method |
(formely method.lik) options are |
components |
an |
nospatial |
logical. If |
limits |
values defining lower and upper limits for the model
parameters used in the numerical minimisation.
The auxiliary function |
print.pars |
logical. If |
messages |
logical. Indicates whether status messages should be printed on the screen (or output device) while the function is running. |
... |
additional parameters to be passed to the minimisation
function. Typically arguments of the type |
object |
an object with output of the function |
spatial |
logical, determines whether the spatial component of the model in included in the output. The geostatistical model components are: trend, spatial and residulas. See DETAILS. |
This function estimate the parameters of the Gaussian random field model, specified as:
where
defines a spatial location. Typically Euclidean
coordinates on a plane.
is the variable been observed.
is the mean component of
the model (trend).
is a stationary Gaussian process with variance
(partial sill) and a correlation function parametrized in its
simplest form by
(the range parameter). Possible extra parameters
for the correlation function are the smoothness parameter
and the anisotropy parameters
and
(anisotropy ratio and angle, respectively).
is the error term with variance parameter
(nugget variance).
The additional parameter allows for the Box-Cox
transformation of the response variable.
If used (i.e. if
)
above is replaced by
such that
Two particular cases are
which indicates no transformation and
indicating the log-transformation.
Numerical minimization
In general parameter estimation is performed numerically using the R
function optim
to minimise the
negative log-likelihood computed by the function negloglik.GRF
.
If the nugget, anisotropy (),
smoothness (
) and transformation (
) parameters
are held fixed then the numerical minimisation can be reduced to
one-dimension and the function
optimize
is used instead
of optim
. In this case initial values are irrelevant.
Limits
Lower and upper limits for parameter values can be
individually specified using the function link{pars.limits}
.
For example, including the following in the function call:limits = pars.limits(phi=c(0, 10), lambda=c(-2.5, 2.5))
,
will change the limits for the parameters and
.
Default values are used if the argument
limits
is not provided.
There are internal reparametrisation depending on the options for
parameters to be estimated.
For instance for the common situation when fix.nugget=FALSE
the
minimisation is performed in a reduced
parameter space using
.
In this case values of
and
are then given by
analytical expressions which are function of the two parameters
remaining parameters and limits for these two parameters will be ignored.
Since parameter values are found by numerical optimization using
the function optim
,
in given circunstances the algorithm may not converge to correct
parameter values when called with default options and the user may
need to pass extra options for the optimizer. For instance the
function optim
takes a control
argument.
The user should try different initial values and if the parameters have
different orders of magnitude may need to use options to scale the parameters.
Some possible workarounds in case of problems include:
rescale you data values (dividing by a constant, say)
rescale your coordinates (subtracting values and/or dividing by constants)
Use the mechanism to pass control()
options for the
optimiser internally
Transformation
If the fix.lambda = FALSE
and nospatial = FALSE
the
Box-Cox parameter for the model without the spatial component is
obtained numerically, with log-likelihood computed by the function
boxcox.ns
.
Multiple initial values can be specified providing a matrix for the argument
ini.cov.pars
and/or
providing a vector for the values of the remaining model parameters.
In this case the log-likelihood is computed for all combinations of
the model parameters. The parameter set which maximises the
value of the log-likelihood is then used to start the
minimisation algorithm.
Alternatively the argument ini.cov.pars
can take an object of
the class eyefit
or variomodel
. This allows the usage
of an output of the functions eyefit
, variofit
or
likfit
be used as initial value.
The argument realisations allows sets of data assumed to be
independent replications of the same process.
Data on different realisations may or may not be co-located.
For instance, data collected at different times
can be pooled together in the parameter estimation assuming
time independence.
The argument realisations
takes a vector indicating the
replication number (e.g. the times).
If realisations = TRUE
the code looks for an element
named realisations
in the geodata
object.
The log-likelihoods are computed for each replication and added together.
An object of the classes "likGRF"
and "variomodel"
.
The function summary.likGRF
is used to print a summary
of the fitted model.
The object is a list with the following components:
cov.model |
a string with the name of the correlation function. |
nugget |
value of the nugget parameter |
cov.pars |
a vector with the estimates of the parameters
|
kappa |
value of the smoothness parameter. Valid only if
the correlation function is one of: |
beta |
estimate of mean parameter |
beta.var |
estimated variance (or covariance matrix) for the mean
parameter |
lambda |
values of the Box-Cox transformation parameter. A fixed value if
|
aniso.pars |
fixed values or estimates of the anisotropy parameters, according to the function call. |
method.lik |
estimation method used, |
loglik |
the value of the maximized likelihood. |
npars |
number of estimated parameters. |
AIC |
value of the Akaike Information Criteria, |
BIC |
value of the Bayesian Information Criteria,
|
parameters.summary |
a data-frame with all model parameters, their status (estimated or fixed) and values. |
info.minimisation |
results returned by the minimisation function. |
max.dist |
maximum distance between 2 data points. This
information relevant for other functions which use outputs from
|
trend |
the trend (covariates) matrix |
log.jacobian |
numerical value of the logarithm of the Jacobian of the transformation. |
nospatial |
estimates for the model without the spatial component. |
call |
the function call. |
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package
geoR
can be found at:
http://www.leg.ufpr.br/geoR/.
summary.likGRF
for summary of the results,
plot.variogram
, lines.variogram
and
lines.variomodel
for graphical output,
proflik
for computing profile likelihoods,
variofit
and for other estimation methods,
and optim
for the numerical minimisation function.
## Not run: ml <- likfit(s100, ini=c(0.5, 0.5), fix.nug = TRUE) ml summary(ml) reml <- likfit(s100, ini=c(0.5, 0.5), fix.nug = TRUE, lik.met = "REML") summary(reml) plot(variog(s100)) lines(ml) lines(reml, lty = 2) ## End(Not run)
## Not run: ml <- likfit(s100, ini=c(0.5, 0.5), fix.nug = TRUE) ml summary(ml) reml <- likfit(s100, ini=c(0.5, 0.5), fix.nug = TRUE, lik.met = "REML") summary(reml) plot(variog(s100)) lines(ml) lines(reml, lty = 2) ## End(Not run)
Computes maximum likelihood estimates of the bivariate Gaussian common component geostatistical model.
likfitBGCCM(geodata1, geodata2, ini.sigmasq, ini.phi, cov0.model="matern", cov1.model="matern", cov2.model="matern", kappa0=0.5, kappa1=0.5, kappa2=0.5, fc.min = c("optim", "nlminb"), ...)
likfitBGCCM(geodata1, geodata2, ini.sigmasq, ini.phi, cov0.model="matern", cov1.model="matern", cov2.model="matern", kappa0=0.5, kappa1=0.5, kappa2=0.5, fc.min = c("optim", "nlminb"), ...)
geodata1 |
an object of the class |
geodata2 |
an object of the class |
ini.sigmasq |
optional, a vector with initial values for the variance parameters. If not provided default values are used. |
ini.phi |
optional, a vector with initial values for the correlation range parameters. If not provided default values are used. |
cov0.model , cov1.model , cov2.model
|
covariance model for each of
the processes. See |
kappa0 , kappa1 , kappa2
|
extra parameter for some covariance models. |
fc.min |
a string indication which function should be used to minimise the negative of the log-likelihood. |
... |
A list with model fitting information to which
the class BGCCM
is assigned.
mu |
a 2 elements vector with mean estimates. |
sigmasq |
a 4 elements vector with variance estimates. |
phi |
a 3 elements vector with estimated correlation parameters values. |
loglik |
a scalar. Maximised value of the log-likelihood. |
optim |
|
... |
and other information related to the model fitting. |
This is a new function and still in draft format and pretty much untested.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
optim
, nlminb
,
varcovBGCCM
,
as.geodata
, likfit
.
# see http://www.leg.ufpr.br/geoR/tutorials/CCM.R
# see http://www.leg.ufpr.br/geoR/tutorials/CCM.R
A sample (empirical) variogram computed using the
function variog
is added to the current plot.
## S3 method for class 'variogram' lines(x, max.dist, type = "o", scaled = FALSE, pts.range.cex, ...)
## S3 method for class 'variogram' lines(x, max.dist, type = "o", scaled = FALSE, pts.range.cex, ...)
x |
an object of the class |
max.dist |
maximum distance for the x-axis. By default takes the maximum distance for which the sample variogram was computed. |
type |
type of line for the empirical variogram. The default is
|
scaled |
logical. If |
pts.range.cex |
optional. A two elements vector with maximum and
minimum values for the caracter expansion factor |
... |
other arguments to be passed to the function
|
A line with the empirical variogram is added to the plot in the current graphics device. No values are returned.
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
variog
, lines.variogram
,
lines.variomodel
, variog.model.env
,
variog.mc.env
, plot.grf
, lines
.
Variogram envelopes computed by variog.model.env
or
variog.mc.env
are added to the current variogram plot.
## S3 method for class 'variogram.envelope' lines(x, lty = 3, ...)
## S3 method for class 'variogram.envelope' lines(x, lty = 3, ...)
x |
an object of the class |
lty |
line type. Defaults to 3. |
... |
arguments to be passed to the function |
Lines defining the variogram envelope are added to the plotin the current graphics device.
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
variog
for variogram computation,
variog.model.env
and variog.mc.env
for
computation of variogram envelopes, and lines
for the
generic function.
s100.vario <- variog(s100, max.dist = 1) s100.ml <- likfit(s100, ini=c(.5, .5)) s100.mod.env <- variog.model.env(s100, obj.variog = s100.vario, model = s100.ml) s100.mc.env <- variog.mc.env(s100, obj.variog = s100.vario) plot(s100.vario) lines(s100.mod.env) lines(s100.mc.env, lwd=2)
s100.vario <- variog(s100, max.dist = 1) s100.ml <- likfit(s100, ini=c(.5, .5)) s100.mod.env <- variog.model.env(s100, obj.variog = s100.vario, model = s100.ml) s100.mc.env <- variog.mc.env(s100, obj.variog = s100.vario) plot(s100.vario) lines(s100.mod.env) lines(s100.mc.env, lwd=2)
This function adds a line with a variogram model specifyed by the user to a current variogram plot. The variogram is specifyed either by passing a list with values for the variogram elements or using each argument in the function.
## S3 method for class 'variomodel' lines(x, ...) ## Default S3 method: lines.variomodel(x, cov.model, cov.pars, nugget, kappa, max.dist, scaled = FALSE, ...)
## S3 method for class 'variomodel' lines(x, ...) ## Default S3 method: lines.variomodel(x, cov.model, cov.pars, nugget, kappa, max.dist, scaled = FALSE, ...)
x |
a list with the values for the following components: |
cov.model |
a string with the type of the variogram function. See
documentation of |
cov.pars |
a vector or matrix with the values for the partial sill
( |
nugget |
a scalar with the value of the nugget
( |
kappa |
a scalar with the value of the smoothness
( |
max.dist |
maximum distance (x-axis) to compute and draw the line
representing the variogram model.
If a list is provided in |
scaled |
logical. If |
... |
arguments to be passed to the function
|
Adds a line with a variogram model to a plot.
In conjuction with plot.variogram
can be
used for instance to compare sample variograms against fitted models returned by
variofit
and/or likfit
.
A line with a variogram model is added to a plot on the current graphics device. No values are returned.
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
lines.variomodel.krige.bayes
,
lines.variomodel.grf
,
lines.variomodel.variofit
,
lines.variomodel.likGRF
,
plot.variogram
, lines.variogram
,
variofit
, likfit
, curve
.
# computing and ploting empirical variogram vario <- variog(s100, max.dist = 1) plot(vario) # estimating parameters by weighted least squares vario.wls <- variofit(vario, ini = c(1, .3), fix.nugget = TRUE) # adding fitted model to the plot lines(vario.wls) # # Ploting different variogram models plot(0:1, 0:1, type="n") lines.variomodel(cov.model = "exp", cov.pars = c(.7, .25), nug = 0.3, max.dist = 1) # an alternative way to do this is: my.model <- list(cov.model = "exp", cov.pars = c(.7, .25), nugget = 0.3, max.dist = 1) lines.variomodel(my.model, lwd = 2) # now adding another model lines.variomodel(cov.m = "mat", cov.p = c(.7, .25), nug = 0.3, max.dist = 1, kappa = 1, lty = 2) # adding the so-called "nested" models # two exponential structures lines.variomodel(seq(0,1,l=101), cov.model="exp", cov.pars=rbind(c(0.6,0.15),c(0.4,0.25)), nug=0, col=2) ## exponential and spherical structures lines.variomodel(seq(0,1,l=101), cov.model=c("exp", "sph"), cov.pars=rbind(c(0.6,0.15), c(0.4,0.75)), nug=0, col=3)
# computing and ploting empirical variogram vario <- variog(s100, max.dist = 1) plot(vario) # estimating parameters by weighted least squares vario.wls <- variofit(vario, ini = c(1, .3), fix.nugget = TRUE) # adding fitted model to the plot lines(vario.wls) # # Ploting different variogram models plot(0:1, 0:1, type="n") lines.variomodel(cov.model = "exp", cov.pars = c(.7, .25), nug = 0.3, max.dist = 1) # an alternative way to do this is: my.model <- list(cov.model = "exp", cov.pars = c(.7, .25), nugget = 0.3, max.dist = 1) lines.variomodel(my.model, lwd = 2) # now adding another model lines.variomodel(cov.m = "mat", cov.p = c(.7, .25), nug = 0.3, max.dist = 1, kappa = 1, lty = 2) # adding the so-called "nested" models # two exponential structures lines.variomodel(seq(0,1,l=101), cov.model="exp", cov.pars=rbind(c(0.6,0.15),c(0.4,0.25)), nug=0, col=2) ## exponential and spherical structures lines.variomodel(seq(0,1,l=101), cov.model=c("exp", "sph"), cov.pars=rbind(c(0.6,0.15), c(0.4,0.75)), nug=0, col=3)
This functions adds to the graphics device a line with the theoretical
(true) variogram used when generating simulations with
the function grf
.
## S3 method for class 'grf' lines.variomodel(x, max.dist, n = 100, ...)
## S3 method for class 'grf' lines.variomodel(x, max.dist, n = 100, ...)
x |
an object from the class |
max.dist |
maximum distance to compute and plot the true variogram. Defaults to the maximum distance between two data locations. |
n |
number of points used to compute and draw the variogram line. |
... |
further arguments to be passed to the function
|
A line with the true variogram model is added to the current plot on the graphics device. No values are returned.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
lines.variomodel
,
grf
, plot.grf
, curve
.
sim <- grf(100, cov.pars=c(1, .25)) # simulates data plot(variog(sim, max.dist=1)) # plot empirical variogram
sim <- grf(100, cov.pars=c(1, .25)) # simulates data plot(variog(sim, max.dist=1)) # plot empirical variogram
Adds a Bayesian estimate of the variogram model to a plot typically with an empirical variogram.
The estimate is a chosen summary (mean, mode or mean) of the
posterior distribution returned by the function krige.bayes
.
## S3 method for class 'krige.bayes' lines.variomodel(x, summary.posterior, max.dist, uvec, posterior = c("variogram", "parameters"), ...)
## S3 method for class 'krige.bayes' lines.variomodel(x, summary.posterior, max.dist, uvec, posterior = c("variogram", "parameters"), ...)
x |
an object of the class |
summary.posterior |
specify which summary of the posterior
distribution should be used as the parameter estimate.
Options are |
max.dist |
numerical, the maximum distance for the x-axis. |
uvec |
a numerical vector with support points to compute the
variogram values. Only used if |
posterior |
indicates whether the the variogram line is based on the posterior of the variogram function (default) or the posterior of the model parameters. |
... |
The function krige.bayes
returns samples from the
posterior distribution of the parameters .
This function allows for two basic options to draw a line with a summary of the variogram function.
for each sample of the parameters the variogram
function is computed at the support points defined in the
argument uvec
. Then a function provided by the user in the
argument summary.posterior
is used to compute a summary of
the values obtained at each support point.
in this case summaries of the posterior
distribution of the model parameters as “plugged-in” in the
variogram function.
One of the options "mode"
(default) ,"median"
or "mean"
can be provided in the argument summary.posterior
.
The option mode
, uses the mode of and the mode of
of
conditional on the modes of the former parameters.
For the options
mean
and median
these summaries are
computed from the samples of the posterior.
A line with the estimated variogram plot is added to the plot in the current graphics device. No values are returned.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
lines.variomodel
, krige.bayes
and lines
.
#See examples in the documentation of the function krige.bayes().
#See examples in the documentation of the function krige.bayes().
This function adds a fitted variogram based on the estimates of the
model parameters returned by the function likfit
to a current variogram plot.
## S3 method for class 'likGRF' lines.variomodel(x, max.dist, scaled = FALSE, ...)
## S3 method for class 'likGRF' lines.variomodel(x, max.dist, scaled = FALSE, ...)
x |
an object of the class |
max.dist |
maximum distance (x-axis) to compute and draw the line
representing the variogram model.
The default is the distance given by |
scaled |
logical. If |
... |
arguments to be passed to the function
|
Adds variogram model(s) to a plot.
In conjuction with plot.variogram
can be
used to compare sample variograms against fitted models returned by
likfit
.
A line with a variogram model is added to a plot on the current graphics device. No values are returned.
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
lines.variomodel
,
lines.variomodel.variofit
,
plot.variogram
, lines.variogram
,
variofit
, likfit
, curve
.
# compute and plot empirical variogram vario <- variog(s100, max.dist = 1) plot(vario) # estimate parameters vario.ml <- likfit(s100, ini = c(1, .3), fix.nugget = TRUE) # adds fitted model to the plot lines(vario.ml)
# compute and plot empirical variogram vario <- variog(s100, max.dist = 1) plot(vario) # estimate parameters vario.ml <- likfit(s100, ini = c(1, .3), fix.nugget = TRUE) # adds fitted model to the plot lines(vario.ml)
This function adds a line with the variogram model
fitted by the function
variofit
to a current variogram plot.
## S3 method for class 'variofit' lines.variomodel(x, max.dist, scaled = FALSE, ...)
## S3 method for class 'variofit' lines.variomodel(x, max.dist, scaled = FALSE, ...)
x |
an object of the class |
max.dist |
maximum distance (x-axis) to compute and draw the line
representing the variogram model.
The default is the distance given by |
scaled |
logical. If |
... |
arguments to be passed to the function
|
Adds fitted variogram model to a plot.
In conjuction with plot.variogram
can be
used to compare empirical variograms against fitted models returned by
variofit
.
A line with a variogram model is added to a plot on the current graphics device. No values are returned.
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
lines.variomodel
,
lines.variomodel.likGRF
,
plot.variogram
, lines.variogram
,
variofit
, likfit
, curve
.
# compute and plot empirical variogram vario <- variog(s100, max.dist = 1) plot(vario) # estimate parameters vario.wls <- variofit(vario, ini = c(1, .3), fix.nugget = TRUE) # adds fitted model to the plot lines(vario.wls)
# compute and plot empirical variogram vario <- variog(s100, max.dist = 1) plot(vario) # estimate parameters vario.wls <- variofit(vario, ini = c(1, .3), fix.nugget = TRUE) # adds fitted model to the plot lines(vario.wls)
Selects the prediction locations located inside a polygon defining
borders of a region where prediction is aimed.
Typically internally called by geoR functions
krige.bayes
, krige.conv
,
ksline
.
locations.inside(locations, borders, as.is = TRUE, ...)
locations.inside(locations, borders, as.is = TRUE, ...)
locations |
a two columns matrix or dqata frame with coordinates of the prediction locations. |
borders |
a two column matrix or data-frame with coordinates of a polygon defining the borders of the region. |
as.is |
logical defining if the returned object of of the same
type (list, data-frame or matrix) as the provided in
|
... |
arguments to be passed to the internal function
|
A two columns matrix, data-frame or a list with 2 elements with coordinates of points inside the borders.
over
,coordinates
,
SpatialPoints
.
gr <- pred_grid(parana$borders, by=20) plot(gr, asp=1, pch="+") polygon(parana$borders) gr.in <- locations.inside(gr, parana$borders) points(gr.in, col=2, pch="+")
gr <- pred_grid(parana$borders, by=20) plot(gr, asp=1, pch="+") polygon(parana$borders) gr.in <- locations.inside(gr, parana$borders) points(gr.in, col=2, pch="+")
This function computes the value of the log-likelihood for a Gaussian random field.
loglik.GRF(geodata, coords = geodata$coords, data = geodata$data, obj.model = NULL, cov.model = "exp", cov.pars, nugget = 0, kappa = 0.5, lambda = 1, psiR = 1, psiA = 0, trend = "cte", method.lik = "ML", compute.dists = TRUE, realisations = NULL)
loglik.GRF(geodata, coords = geodata$coords, data = geodata$data, obj.model = NULL, cov.model = "exp", cov.pars, nugget = 0, kappa = 0.5, lambda = 1, psiR = 1, psiA = 0, trend = "cte", method.lik = "ML", compute.dists = TRUE, realisations = NULL)
geodata |
a list containing elements |
coords |
an |
data |
a vector with data values. By default it takes the
element |
obj.model |
a object of the class |
cov.model |
a string specifying the model for the correlation
function. For further details see
documentation for |
cov.pars |
a vector with 2 elements with values of the covariance parameters
|
nugget |
value of the nugget parameter. Defaults to |
kappa |
value of the smoothness parameter. Defaults to
|
lambda |
value of the Box-Cox tranformation parameter. Defaults
to |
psiR |
value of the anisotropy ratio parameter. Defaults to
|
psiA |
value (in radians) of the anisotropy rotation parameter. Defaults to zero. |
trend |
specifies the mean part of the model.
The options are:
|
method.lik |
options are |
compute.dists |
for internal use with other function. Don't change the default unless you know what you are doing. |
realisations |
optional. A vector indicating replication number
for each data. For more details see |
The expression log-likelihood is:
where is the size of the data vector
,
is the mean (vector) parameter with dimention
,
is the covariance
matrix and
is the matrix with the values of the covariates (a
vector of
's if the mean is constant.
The expression restricted log-likelihood is:
The numerical value of the log-likelihood.
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
likfit
for likelihood-based parameter estimation.
loglik.GRF(s100, cov.pars=c(0.8, .25), nugget=0.2) loglik.GRF(s100, cov.pars=c(0.8, .25), nugget=0.2, met="RML") ## Computing the likelihood of a model fitted by ML s100.ml <- likfit(s100, ini=c(1, .5)) s100.ml s100.ml$loglik loglik.GRF(s100, obj=s100.ml) ## Computing the likelihood of a variogram fitted model s100.v <- variog(s100, max.dist=1) s100.vf <- variofit(s100.v, ini=c(1, .5)) s100.vf loglik.GRF(s100, obj=s100.vf)
loglik.GRF(s100, cov.pars=c(0.8, .25), nugget=0.2) loglik.GRF(s100, cov.pars=c(0.8, .25), nugget=0.2, met="RML") ## Computing the likelihood of a model fitted by ML s100.ml <- likfit(s100, ini=c(1, .5)) s100.ml s100.ml$loglik loglik.GRF(s100, obj=s100.ml) ## Computing the likelihood of a variogram fitted model s100.v <- variog(s100, max.dist=1) s100.vf <- variofit(s100.v, ini=c(1, .5)) s100.vf loglik.GRF(s100, obj=s100.vf)
This function computes values of the
correlation function
for given distances and parameters.
matern(u, phi, kappa)
matern(u, phi, kappa)
u |
a vector, matrix or array with values of the distances between pairs of data locations. |
phi |
value of the range parameter |
kappa |
value of the smoothness parameter |
The model is defined as:
where and
are parameters and
denotes the modified Bessel function of the third
kind of order
.
The family is valid for
and
.
A vector matrix or array, according to the argument u
, with the
values of the
correlation function for the given distances.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
cov.spatial
for the correlation functions
implemented in geoR, and besselK
for computation
of the Bessel functions.
# # Models with fixed range and varying smoothness parameter # curve(matern(x, phi= 0.25, kappa = 0.5),from = 0, to = 1.5, xlab = "distance", ylab = expression(rho(h)), lty = 2, main=expression(paste("varying ", kappa, " and fixed ", phi))) curve(matern(x, phi= 0.25, kappa = 1),from = 0, to = 1.5, add = TRUE) curve(matern(x, phi= 0.25, kappa = 2),from = 0, to = 1.5, add = TRUE, lwd = 2, lty=2) curve(matern(x, phi= 0.25, kappa = 3),from = 0, to = 1.5, add = TRUE, lwd = 2) legend("topright", expression(kappa==0.5, kappa==1.5, kappa==2, kappa==3), lty=c(2,1,2,1), lwd=c(1,1,2,2)) # # Correlations with equivalent "practical range" # and varying smoothness parameter # curve(matern(x, phi = 0.25, kappa = 0.5),from = 0, to = 1, xlab = "distance", ylab = expression(gamma(h)), lty = 2, main = "models with equivalent \"practical\" range") curve(matern(x, phi = 0.188, kappa = 1),from = 0, to = 1, add = TRUE) curve(matern(x, phi = 0.14, kappa = 2),from = 0, to = 1, add = TRUE, lwd=2, lty=2) curve(matern(x, phi = 0.117, kappa = 2), from = 0, to = 1, add = TRUE, lwd=2) legend("topright", expression(list(kappa == 0.5, phi == 0.250), list(kappa == 1, phi == 0.188), list(kappa == 2, phi == 0.140), list(kappa == 3, phi == 0.117)), lty=c(2,1,2,1), lwd=c(1,1,2,2))
# # Models with fixed range and varying smoothness parameter # curve(matern(x, phi= 0.25, kappa = 0.5),from = 0, to = 1.5, xlab = "distance", ylab = expression(rho(h)), lty = 2, main=expression(paste("varying ", kappa, " and fixed ", phi))) curve(matern(x, phi= 0.25, kappa = 1),from = 0, to = 1.5, add = TRUE) curve(matern(x, phi= 0.25, kappa = 2),from = 0, to = 1.5, add = TRUE, lwd = 2, lty=2) curve(matern(x, phi= 0.25, kappa = 3),from = 0, to = 1.5, add = TRUE, lwd = 2) legend("topright", expression(kappa==0.5, kappa==1.5, kappa==2, kappa==3), lty=c(2,1,2,1), lwd=c(1,1,2,2)) # # Correlations with equivalent "practical range" # and varying smoothness parameter # curve(matern(x, phi = 0.25, kappa = 0.5),from = 0, to = 1, xlab = "distance", ylab = expression(gamma(h)), lty = 2, main = "models with equivalent \"practical\" range") curve(matern(x, phi = 0.188, kappa = 1),from = 0, to = 1, add = TRUE) curve(matern(x, phi = 0.14, kappa = 2),from = 0, to = 1, add = TRUE, lwd=2, lty=2) curve(matern(x, phi = 0.117, kappa = 2), from = 0, to = 1, add = TRUE, lwd=2) legend("topright", expression(list(kappa == 0.5, phi == 0.250), list(kappa == 1, phi == 0.188), list(kappa == 2, phi == 0.140), list(kappa == 3, phi == 0.117)), lty=c(2,1,2,1), lwd=c(1,1,2,2))
Produces a list with the names of the main elements of
geodata
object: coords, data, units.m, covariate and
realisation.
Can be useful to list names before using {subset.geodata}
.
## S3 method for class 'geodata' names(x)
## S3 method for class 'geodata' names(x)
x |
an object of the class |
A list with
coords |
names of the coordinates in the geodata object. |
data |
name(s) of the data elements in the geodata object. |
units.m |
returns the string |
covariates |
return the covariate(s) name(s) if present
in the |
realisations |
returns the string |
other |
other elements in the |
names
, subset.geodata
, as.geodata
.
names(ca20)
names(ca20)
For a given set of points and locations identified by 2D coordinates this function finds the nearest location of each point
nearloc(points, locations, positions = FALSE)
nearloc(points, locations, positions = FALSE)
points |
a matrix, data-frame or list with the 2D coordinates of a set of points for which you want to find the nearest location. |
locations |
a matrix, data-frame or list with the 2D coordinates of a set of locations. |
positions |
logical defining what to be returned. If |
If positions = FALSE
the function returns
a matrix, data-frame or list of the same type and size
as the object provided in the argument points
with the
coordinates of the nearest locations.
If positions = FALSE
the function returns a vector with the
position of the nearest points in the locations
object.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
set.seed(276) gr <- expand.grid(seq(0,1, l=11), seq(0,1, l=11)) plot(gr, asp=1) pts <- matrix(runif(10), nc=2) points(pts, pch=19) near <- nearloc(points=pts, locations=gr) points(near, pch=19, col=2) rownames(near) nearloc(points=pts, locations=gr, pos=TRUE)
set.seed(276) gr <- expand.grid(seq(0,1, l=11), seq(0,1, l=11)) plot(gr, asp=1) pts <- matrix(runif(10), nc=2) points(pts, pch=19) near <- nearloc(points=pts, locations=gr) points(near, pch=19, col=2) rownames(near) nearloc(points=pts, locations=gr, pos=TRUE)
Auxiliary function defining output options for
krige.bayes
and krige.conv
.
output.control(n.posterior, n.predictive, moments, n.back.moments, simulations.predictive, mean.var, quantile, threshold, sim.means, sim.vars, signal, messages)
output.control(n.posterior, n.predictive, moments, n.back.moments, simulations.predictive, mean.var, quantile, threshold, sim.means, sim.vars, signal, messages)
n.posterior |
number of samples to be taken from the posterior distribution. Defaults to 1000. |
n.predictive |
number of samples to be taken from the
predictive distribution. Default equals to
|
moments |
logical. Indicates whether the moments of the
predictive distribution are returned. If |
n.back.moments |
number of sample to back-transform moments by simulation. Defaults to 1000. |
simulations.predictive |
logical. Defines whether to draw simulations
from the predictive distribution.
Only considered if prediction
locations are provided in the argument |
mean.var |
logical (optional). Indicates whether mean and variances of the simulations of the predictive distributions are computed and returned. |
quantile |
a (optional) numeric vector.
If provided indicates whether quantiles of the
simulations from the
predictive distribution are computed and returned.
If a vector with numbers in the interval
|
threshold |
Optional. A numerical vector.
If one or more values are provided, an object named
|
sim.means |
logical (optional). Indicates whether mean
of each of the conditional simulations of the predictive
distribution should be computed and returned. Defaults to
|
sim.vars |
logical (optional). Indicates whether variance
of each of the conditional simulations of the predictive
distribution should be computed and returned. Defaults to |
signal |
logical indicating whether the signal or the variable is
to be predicted. Different defaults are set internally by
functions calling |
messages |
logical. Indicates
whether or not status messages are printed on the output device
while the function is running. Defaults to |
SIGNAL
This function is typically called by the geoR's prediction functions
krige.bayes
and krige.conv
defining the output.
By default, krige.bayes
sets signal = TRUE
and krige.conv
sets signal = FALSE
.
The underlying model
assumes that observations are noisy
versions of a signal
and
is the nugget variance.
If the
and
are
indistiguishable.
If and regarded as measurement error, the
option
signal
defines whether the (
signal =
TRUE
) or the variable (
signal = FALSE
) is to be
predicted.
For the latter the predictions will "honor" the data,
i.e. predicted values will coincide with the data, at data locations.
For unsampled locations and untransformed data,
the predicted values equals data
regardless signal = TRUE
or FALSE
, however
predictions variances will differ.
The function krige.conv
has an argument
micro.scale
. If the error term is
divided as
and the nugget variance is divided into two terms: micro-scale variance
and measurement error.
If signal = TRUE
the term is
regarded as part of the signal and consequently the micro-scale variance is added to
the prediction variance.
If signal = FALSE
the total error variance
is added to the prediction variance.
A list with processed arguments to be passed to the main function.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
The prediction functions krige.bayes
and krige.conv
.
This data-set was used by Diggle and Ribeiro (2001) to illustrate the methods discussed in the paper. The data reported analysis was carried out using the package geoR.
The data refers to average rainfall over different years for the period May-June
(dry-season). It was collected at 143 recording stations throughout State,
Brasil.
data(parana)
data(parana)
The object parana
of the class geodata
, which is a list
containing the following components:
coords
a matrix with the coordinates of the recording stations.
data
a vector with the average recorded rainfall for the May-June period.
borders
a matrix with the coordinates defining the borders of
state.
loci.paper
a matrix with the coordinates of the four prediction locations discussed in the paper.
The data were collected at several recording stations at
State, Brasil, belonging to the following companies:
COPEL, IAPAR, DNAEE, SUREHMA and INEMET.
The data base was organized by Laura Regina Bernardes Kiihl (IAPAR,
Instituto do
, Londrina, Brasil)
and the fraction of the data included in this data-set was
provided by Jacinta Loudovico Zamboti (Universidade Estadual de
Londrina, Brasil).
The coordinates of the borders of
State were provided
by
Henrique Caviglione (IAPAR).
Diggle, P.J. & Ribeiro Jr, P.J. (2002) Bayesian inference in Gaussian model-based geostatistics. Geographical and Environmental Modelling, Vol. 6, No. 2, 129-146.
summary(parana) plot(parana)
summary(parana) plot(parana)
The functions likfit
and variofit
in the
package geoR
pars.limits(phi = c(lower = 0, upper = +Inf), sigmasq = c(lower = 0, upper = +Inf), nugget.rel = c(lower = 0, upper = +Inf), kappa = c(lower = 0, upper = +Inf), kappa2 = c(lower = 0, upper = +Inf), lambda = c(lower = -3, upper = 3), psiR = c(lower = 1, upper = +Inf), psiA = c(lower = 0, upper = 2 * pi), tausq.rel = nugget.rel)
pars.limits(phi = c(lower = 0, upper = +Inf), sigmasq = c(lower = 0, upper = +Inf), nugget.rel = c(lower = 0, upper = +Inf), kappa = c(lower = 0, upper = +Inf), kappa2 = c(lower = 0, upper = +Inf), lambda = c(lower = -3, upper = 3), psiR = c(lower = 1, upper = +Inf), psiA = c(lower = 0, upper = 2 * pi), tausq.rel = nugget.rel)
phi |
a two elements vector with limits for the parameter phi. Defaults to [0, +Inf] |
sigmasq |
idem for sigmasq. Defaults to [0, +Inf] |
nugget.rel |
idem for nugget.rel. Defaults to [0, +Inf] |
kappa , kappa2
|
idem. Defaults to [0, +Inf] |
lambda |
idem for lambda. Defaults to [-3, +3]. Only used in
|
psiR |
idem for psiR. Defaults to [1, +Inf]. Only used in
|
psiA |
idem for psiA. Defaults to [0, 2 pi]. Only used in
|
tausq.rel |
idem for tausq.rel. Defaults to [0, +Inf] |
Lower and upper limits for parameter values can be
individually specified.
For example, including the following in the function call in
likfit
or variofit
:limits = pars.limits(phi=c(0, 10), lambda=c(-2.5, 2.5))
,
will change the limits for the parameters and
.
Default values are used if the argument
limits
is not provided.
A list of a 2 elements vector with limits for each parameters
pars.limits(phi=c(0,10)) pars.limits(phi=c(0,10), sigmasq=c(0, 100))
pars.limits(phi=c(0,10)) pars.limits(phi=c(0,10), sigmasq=c(0, 100))
This function produces a display
with the following plots:
the first indicates the spatial locations assign different
colors to data
in different quartiles,
the next two shows data against the X and
Y coordinates and the last is an histogram of the data values or optionally,
a 3-D plot with spatial locations and associated data values.
## S3 method for class 'geodata' plot(x, coords=x$coords, data = x$data, borders, trend="cte", lambda = 1, col.data = 1, weights.divide = "units.m", lowess = FALSE, scatter3d = FALSE, density = TRUE, rug = TRUE, qt.col, ...)
## S3 method for class 'geodata' plot(x, coords=x$coords, data = x$data, borders, trend="cte", lambda = 1, col.data = 1, weights.divide = "units.m", lowess = FALSE, scatter3d = FALSE, density = TRUE, rug = TRUE, qt.col, ...)
x |
a list containing elements |
coords |
an |
data |
a vector with data values. By default it takes the
element |
borders |
If an |
trend |
specifies the mean part of the model. The options are:
|
lambda |
value of the Box-Cox transformation parameter. Two particular cases
are |
col.data |
indicates the column number for the data
to be plotted. Only valid if more than one data-set is available
i.e., if the argument |
weights.divide |
if a vector of weights with the same length as
the data is provided each data is
divided by the corresponding element in this vector.
Defaults divides the data by the element |
lowess |
logical. Indicates whether the function
|
scatter3d |
logical. If |
density |
logical. If |
rug |
logical. If |
qt.col |
colors for the quartiles in the first plot. If missing defaults to blue, green, yellow and red. |
... |
further arguments to be passed to the function
|
A plot is produced on the graphics device. No values are returned.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
points.geodata
,
scatterplot3d
, lowess
,
density
, rug
.
require(geoR) plot(s100) plot(s100, scatter3d=TRUE) plot(s100, qt.col=1) plot(ca20) # original data plot(ca20, trend=~altitude+area) # residuals from an external trend plot(ca20, trend='1st') # residuals from a polynomial trend plot(sic.100, bor=sic.borders) # original data plot(sic.100, bor=sic.borders, lambda=0) # logarithm of the data
require(geoR) plot(s100) plot(s100, scatter3d=TRUE) plot(s100, qt.col=1) plot(ca20) # original data plot(ca20, trend=~altitude+area) # residuals from an external trend plot(ca20, trend='1st') # residuals from a polynomial trend plot(sic.100, bor=sic.borders) # original data plot(sic.100, bor=sic.borders, lambda=0) # logarithm of the data
This function plots variograms for simulated geostatistical data
generated by the function grf
.
## S3 method for class 'grf' plot(x, model.line = TRUE, plot.locations = FALSE, ...)
## S3 method for class 'grf' plot(x, model.line = TRUE, plot.locations = FALSE, ...)
x |
an object of the class |
model.line |
logical. If |
plot.locations |
logical. If |
... |
further arguments to be passed to the functions
|
A plot with the empirical variogram(s) is produced on the output device. No values are returned.
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
grf
for simulation of Gaussian random fields,
plot.variogram
for plotting empirical variogram,
variog
for computation of empirical variograms and
plot
for the generic plotting function.
op <- par(no.readonly = TRUE) par(mfrow=c(2,1)) sim1 <- grf(100, cov.pars=c(10, .25)) # generates simulated data plot(sim1, plot.locations = TRUE) # # plots the locations and the sample true variogram model # par(mfrow=c(1,1)) sim2 <- grf(100, cov.pars=c(10, .25), nsim=10) # generates 10 simulated data plot(sim1) # plots sample variograms for all simulations with the true model par(op)
op <- par(no.readonly = TRUE) par(mfrow=c(2,1)) sim1 <- grf(100, cov.pars=c(10, .25)) # generates simulated data plot(sim1, plot.locations = TRUE) # # plots the locations and the sample true variogram model # par(mfrow=c(1,1)) sim2 <- grf(100, cov.pars=c(10, .25), nsim=10) # generates 10 simulated data plot(sim1) # plots sample variograms for all simulations with the true model par(op)
Produces
plots the priors and posteriors distribuitions for the paramters
phi
and tausq.rel
based on results returned by
krige.bayes
.
## S3 method for class 'krige.bayes' plot(x, phi.dist = TRUE, tausq.rel.dist = TRUE, add = FALSE, type=c("bars", "h", "l", "b", "o", "p"), thin, ...)
## S3 method for class 'krige.bayes' plot(x, phi.dist = TRUE, tausq.rel.dist = TRUE, add = FALSE, type=c("bars", "h", "l", "b", "o", "p"), thin, ...)
x |
an object of the class |
phi.dist |
logical indicating whether or not plot the distributions for this parameter. |
tausq.rel.dist |
logical indicating whether or not plot the distributions for this parameter. |
add |
logical. If |
type |
indicates the type of plot. Option |
thin |
a numerical vector defining the thining for values of the
parameters |
... |
further arguments for the plotting function. |
For plot.krige.bayes
a plot is produced or added to the current
graphics device. No values are returned.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
krige.bayes
, barplot
, matplot
.
## See documentation for krige.bayes
## See documentation for krige.bayes
This function produces plots of the profile likelihoods computed by
the function proflik
.
## S3 method for class 'proflik' plot(x, pages = c("user", "one", "two"), uni.only, bi.only, type.bi = c("contour", "persp"), conf.int = c(0.90, 0.95), yaxis.lims = c("conf.int", "as.computed"), by.col = TRUE, log.scale = FALSE, use.splines = TRUE, par.mar.persp = c(0, 0, 0, 0), ask = FALSE, ...)
## S3 method for class 'proflik' plot(x, pages = c("user", "one", "two"), uni.only, bi.only, type.bi = c("contour", "persp"), conf.int = c(0.90, 0.95), yaxis.lims = c("conf.int", "as.computed"), by.col = TRUE, log.scale = FALSE, use.splines = TRUE, par.mar.persp = c(0, 0, 0, 0), ask = FALSE, ...)
x |
an object of the class |
pages |
specify how the plots will be arranged in the
graphics device. The default option, |
uni.only |
only 1-D profiles are plotted even if the object contains results about the 2-D profiles. |
bi.only |
only 2-D profile are plotted even if the object contains results about the 1-D profiles. |
type.bi |
Type of plot for the 2-D profiles. Options are
|
conf.int |
a vector with numbers in the interval |
yaxis.lims |
defines the lower limits for the y-axis in the 1-D
plots. If |
by.col |
logical, If |
log.scale |
plots the x-axis in the logarithmic scale. Defaults to
|
use.splines |
logical. If |
par.mar.persp |
graphical parameters to be used with
|
ask |
logical. Defines whether or not the user is prompted before each plot is produced. |
... |
additional arguments to be passed to the functions
|
Produces plots with the profile likelihoods on the current graphics device. No values are returned.
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
proflik
for computation of the profile
likelihoods. For the generic plotting functions see
plot
, contour
, persp
.
See spline
for interpolation.
# see examples in the documentation for the function proflik()
# see examples in the documentation for the function proflik()
This function plot directional variograms computed by the function
variog4
. The omnidirectional variogram can be also included
in the plot.
## S3 method for class 'variog4' plot(x, omnidirectional=FALSE, same.plot=TRUE, legend = TRUE, ...)
## S3 method for class 'variog4' plot(x, omnidirectional=FALSE, same.plot=TRUE, legend = TRUE, ...)
x |
an object of the class |
omnidirectional |
logical. Indicates whether the omnidirectional variogram is included in the plot. |
same.plot |
logical. Indicates whether the directional variograms are plotted in the same or separated plots. |
legend |
logical indicating whether legends are automatically included in the plots. |
... |
further arguments to be passed to the function
|
A plot is produced on the output device. No values returned.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information about the geoR package can be found at:
http://www.leg.ufpr.br/geoR/.
variog4
for variogram calculations and
matplot
for multiple lines plotting.
s100.v4 <- variog4(s100, max.dist=1) # Plotting variograms for the four directions plot(s100.v4) # changing plot options plot(s100.v4, lwd=2) plot(s100.v4, lty=1, col=c("darkorange", "darkblue", "darkgreen","darkviolet")) plot(s100.v4, lty=1, lwd=2) # including the omnidirectional variogram plot(s100.v4, omni=TRUE) # variograms on different plots plot(s100.v4, omni=TRUE, same=FALSE)
s100.v4 <- variog4(s100, max.dist=1) # Plotting variograms for the four directions plot(s100.v4) # changing plot options plot(s100.v4, lwd=2) plot(s100.v4, lty=1, col=c("darkorange", "darkblue", "darkgreen","darkviolet")) plot(s100.v4, lty=1, lwd=2) # including the omnidirectional variogram plot(s100.v4, omni=TRUE) # variograms on different plots plot(s100.v4, omni=TRUE, same=FALSE)
Plots sample (empirical) variogram computed using the
function variog
.
## S3 method for class 'variogram' plot(x, max.dist, vario.col = "all", scaled = FALSE, var.lines = FALSE, envelope.obj = NULL, pts.range.cex, bin.cloud = FALSE, ...)
## S3 method for class 'variogram' plot(x, max.dist, vario.col = "all", scaled = FALSE, var.lines = FALSE, envelope.obj = NULL, pts.range.cex, bin.cloud = FALSE, ...)
x |
an object of the class |
max.dist |
maximum distance for the x-axis. The default is the maximum distance for which the sample variogram was computed. |
vario.col |
only used if |
scaled |
If |
var.lines |
If |
envelope.obj |
adds a variogram envelope computed by
the function |
pts.range.cex |
optional. A two elements vector with maximum and
minimum values for the caracter expansion factor |
bin.cloud |
logical. If |
... |
other arguments to be passed to the function
|
This function plots empirical variograms.
Toghether with lines.variogram
can be used to compare sample variograms of different variables
and
to compare variogram models against the
empirical variogram.
It uses the function matplot
when plotting variograms
for more them one variable.
Produces a plot with the sample variogram on the current graphics device. No values are returned.
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected]
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
variog
for variogram calculations,
lines.variogram
and lines.variomodel
for
adding lines to the current plot,
variog.model.env
and variog.mc.env
for
variogram envelops computation, matplot
for multiple
lines plot
and plot
for generic plot function.
op <- par(no.readonly = TRUE) sim <- grf(100, cov.pars=c(1, .2)) # simulates data vario <- variog(sim, max.dist=1) # computes sample variogram par(mfrow=c(2,2)) plot(vario) # the sample variogram plot(vario, scaled = TRUE) # the scaled sample variogram plot(vario, max.dist = 1) # limiting the maximum distance plot(vario, pts.range = c(1,3)) # points sizes proportional to number of pairs par(op)
op <- par(no.readonly = TRUE) sim <- grf(100, cov.pars=c(1, .2)) # simulates data vario <- variog(sim, max.dist=1) # computes sample variogram par(mfrow=c(2,2)) plot(vario) # the sample variogram plot(vario, scaled = TRUE) # the scaled sample variogram plot(vario, max.dist = 1) # limiting the maximum distance plot(vario, pts.range = c(1,3)) # points sizes proportional to number of pairs par(op)
This function produces ten plots with the results produced by the
cross-validation function xvalid
.
## S3 method for class 'xvalid' plot(x, coords, borders = NULL, ask = TRUE, error = TRUE, std.error = TRUE, data.predicted = TRUE, pp = TRUE, map = TRUE, histogram = TRUE, error.predicted = TRUE, error.data = TRUE, ...)
## S3 method for class 'xvalid' plot(x, coords, borders = NULL, ask = TRUE, error = TRUE, std.error = TRUE, data.predicted = TRUE, pp = TRUE, map = TRUE, histogram = TRUE, error.predicted = TRUE, error.data = TRUE, ...)
x |
an object of the class |
coords |
an |
borders |
optional. Takes a two column matrix or data-frame with coordinates of the borders. If provided the borders are included in the errors maps. |
ask |
logical. Defines whether or not the user is prompted before each plot is produced. |
error |
logical. Defines whether the plots for the errors
( |
std.error |
logical. Defines whether the plots for the standardised errors will be produced. |
data.predicted |
logical defining whether a plot of data versus
predicted should be displayed. Defaults to |
pp |
logical defining whether a pp plot
should be displayed. Defaults to |
map |
logical defining whether a map of the errors
should be displayed. Defaults to |
histogram |
logical defining whether a histogram of the errors
should be displayed. Defaults to |
error.predicted |
logical defining whether a plot of errors versus
predicted should be displayed. Defaults to |
error.data |
logical defining whether a plot of errors versus
data should be displayed. Defaults to |
... |
other arguments to be passed to the function
|
The number of plots to be produced will depend on the input options. If the graphics device is set to just one plot (something equivalent to par(mfcol=c(1,1))) after each graphic being displayed the user will be prompt to press <return> to see the next graphic.
Alternativaly the user can set the graphical parameter to have several plots in one page. With default options for the arguments the maximum number of plots (10) is produced and setting par(mfcol=c(5,2))) will display them in the same page.
The “errors” for the plots are defined as
and the plots uses the color blue to indicate positive errors and red to indicate negative erros.
No value returned. Plots are produced on the current graphics device.
xvalid
for the cross-validation computations.
wls <- variofit(variog(s100, max.dist = 1), ini = c(.5, .5), fix.n = TRUE) xvl <- xvalid(s100, model = wls) # op <- par(no.readonly = TRUE) par(mfcol = c(3,2)) par(mar = c(3,3,0,1)) par(mgp = c(2,1,0)) plot(xvl, error = FALSE, ask = FALSE) plot(xvl, std.err = FALSE, ask = FALSE) par(op)
wls <- variofit(variog(s100, max.dist = 1), ini = c(.5, .5), fix.n = TRUE) xvl <- xvalid(s100, model = wls) # op <- par(no.readonly = TRUE) par(mfcol = c(3,2)) par(mar = c(3,3,0,1)) par(mgp = c(2,1,0)) plot(xvl, error = FALSE, ask = FALSE) plot(xvl, std.err = FALSE, ask = FALSE) par(op)
This function produces a plot with points indicating the data locations. Arguments can control the points sizes, patterns and colors. These can be set to be proportional to data values, ranks or quantiles. Alternatively, points can be added to the current plot.
## S3 method for class 'geodata' points(x, coords=x$coords, data=x$data, data.col = 1, borders, pt.divide=c("data.proportional","rank.proportional", "quintiles", "quartiles", "deciles", "equal"), lambda = 1, trend = "cte", abs.residuals = FALSE, weights.divide = "units.m", cex.min, cex.max, cex.var, pch.seq, col.seq, add.to.plot = FALSE, x.leg, y.leg = NULL, dig.leg = 2, round.quantiles = FALSE, permute = FALSE, ...)
## S3 method for class 'geodata' points(x, coords=x$coords, data=x$data, data.col = 1, borders, pt.divide=c("data.proportional","rank.proportional", "quintiles", "quartiles", "deciles", "equal"), lambda = 1, trend = "cte", abs.residuals = FALSE, weights.divide = "units.m", cex.min, cex.max, cex.var, pch.seq, col.seq, add.to.plot = FALSE, x.leg, y.leg = NULL, dig.leg = 2, round.quantiles = FALSE, permute = FALSE, ...)
x |
a list containing elements |
coords |
an |
data |
a vector or matrix with data values.
If a matrix is provided each column is regarded as one variable or realization.
Defaults to |
data.col |
the number of the data column. Only used if
|
borders |
If an |
pt.divide |
defines the division of the points in categories.
See |
trend |
specifies the mean part of the model. The options are:
|
abs.residuals |
logical. If |
lambda |
value of the Box-Cox transformation parameter. Two particular cases
are |
weights.divide |
if a vector of weights with the same length as
the data is provided each data is
divided by the corresponding element in this vector.
Defaults divides the data by the element |
cex.min |
minimum value for the graphical parameter
|
cex.max |
maximum value for the graphical parameter
|
cex.var |
a numeric vector with the values of a variable defining the size of the points. Particularly useful for displaying 2 variables at once. |
pch.seq |
number(s) defining the graphical parameter |
col.seq |
number(s) defining the colors in the graphical parameter
|
add.to.plot |
logical. If |
x.leg , y.leg
|
|
dig.leg |
the desired number of digits after the decimal
point. Printing values in the legend uses |
round.quantiles |
logical. Defines whether or not the values
of the quantiles should be rounded. Defaults to |
permute |
logical indication whether the data values should be
randomly re-alocatted to the coordinates. See |
... |
further arguments to be passed to the function
|
The points can be devided in categories and have different sizes
and/or colours according to the argument
pt.divide
. The options are:
sizes proportional to the data values.
sizes proportional to the rank of the data.
five different sizes according to the quintiles of the data.
four different sizes according to the quartiles of the data.
ten different sizes according to the deciles of the data.
all points with the same size.
defines a number of quantiles, the number provided defines the number of different points sizes and colors.
the values in the
vector will be used by the function cut
as break
points to divide the data in classes.
For cases where points have different sizes the arguments
cex.min
and cex.max
set the minimum and the maximum
point sizes. Additionally,
pch.seq
can set different patterns for the points and
col.seq
can be used to define colors.
For example, different colors
can be used for quartiles, quintiles and deciles while a sequence of
gray tones (or a color sequence) can be used
for point sizes proportional to the data or their ranks.
For more details see the section EXAMPLES
.
The argument cex.var
allows for displaying 2 variables
at once. In this case one variable defines the backgroung colour
of the points and the other defines the points size.
The argument permute
if set to TRUE
randomly realocates the data in the coordinates.
This may be used to
contrast the spatial pattern of original data against another
situation where there is no spatial dependence (when setting
permute = TRUE
). If a trend
is provided the residuals
(and not the original data) are permuted.
A plot is created or points are added to the current graphics device.
A list with graphical parameters used to produce the plot is returned invisibily.
According to the input options, the list has some or all of the
following components:
quantiles |
the values of the quantiles used to divide the data. |
cex |
the values of the graphics expansion parameter |
col |
the values of the graphics color parameter |
pch |
the values of the graphics pattern parameter |
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
plot.geodata
for another display of the data and
points
and plot
for information on the
generic R functions. The documentation of
par
provides details on graphical parameters.
For color schemes in R see gray
and
rainbow
.
op <- par(no.readonly = TRUE) par(mfrow=c(2,2), mar=c(3,3,1,1), mgp = c(2,1,0)) points(s100, xlab="Coord X", ylab="Coord Y") points(s100, xlab="Coord X", ylab="Coord Y", pt.divide="rank.prop") points(s100, xlab="Coord X", ylab="Coord Y", cex.max=1.7, col=gray(seq(1, 0.1, l=100)), pt.divide="equal") points(s100, pt.divide="quintile", xlab="Coord X", ylab="Coord Y") par(op) points(ca20, pt.div='quartile', x.leg=4900, y.leg=5850) par(mfrow=c(1,2), mar=c(3,3,1,1), mgp = c(2,1,0)) points(s100, main="Original data") points(s100, permute=TRUE, main="Permuting locations") ## Now an example using 2 variable, 1 defining the ## gray scale and the other the points size points.geodata(coords=camg[,1:2], data=camg[,3], col="gray", cex.var=camg[,5]) points.geodata(coords=camg[,1:2], data=camg[,3], col="gray", cex.var=camg[,5], pt.div="quint")
op <- par(no.readonly = TRUE) par(mfrow=c(2,2), mar=c(3,3,1,1), mgp = c(2,1,0)) points(s100, xlab="Coord X", ylab="Coord Y") points(s100, xlab="Coord X", ylab="Coord Y", pt.divide="rank.prop") points(s100, xlab="Coord X", ylab="Coord Y", cex.max=1.7, col=gray(seq(1, 0.1, l=100)), pt.divide="equal") points(s100, pt.divide="quintile", xlab="Coord X", ylab="Coord Y") par(op) points(ca20, pt.div='quartile', x.leg=4900, y.leg=5850) par(mfrow=c(1,2), mar=c(3,3,1,1), mgp = c(2,1,0)) points(s100, main="Original data") points(s100, permute=TRUE, main="Permuting locations") ## Now an example using 2 variable, 1 defining the ## gray scale and the other the points size points.geodata(coords=camg[,1:2], data=camg[,3], col="gray", cex.var=camg[,5]) points.geodata(coords=camg[,1:2], data=camg[,3], col="gray", cex.var=camg[,5], pt.div="quint")
This function builds a rectangular grid and extracts points which are inside of an internal polygonal region.
polygrid(xgrid, ygrid, borders, vec.inout = FALSE, ...)
polygrid(xgrid, ygrid, borders, vec.inout = FALSE, ...)
xgrid |
grid values in the x-direction. |
ygrid |
grid values in the y-direction. |
borders |
a matrix with polygon coordinates defining the borders of the region. |
vec.inout |
logical. If |
... |
currently not used (kept for back compatibility). |
The function works as follows:
First it creates a grid using the R function
expand.grid
and then it uses the geoR'
internal function
.geoR_inout()
which wraps usage of SpatialPoints
and over
from the package sp to extract the points
of the grid which are inside the polygon.
Within the package geoR
this function is typically used to select points in a non-rectangular
region to perform spatial prediction
using krige.bayes
, krige.conv
or
ksline
. It is also useful to produce
image or perspective plots of the prediction results.
A list with components:
xypoly |
an |
vec.inout |
logical, a vector indicating whether each point of
the rectangular grid is inside the polygon. Only returned if |
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
pred_grid
, expand.grid
, over
,
SpatialPoints
.
poly <- matrix(c(.2, .8, .7, .1, .2, .1, .2, .7, .7, .1), ncol=2) plot(0:1, 0:1, type="n") lines(poly) poly.in <- polygrid(seq(0,1,l=11), seq(0,1,l=11), poly, vec=TRUE) points(poly.in$xy)
poly <- matrix(c(.2, .8, .7, .1, .2, .1, .2, .7, .7, .1), ncol=2) plot(0:1, 0:1, type="n") lines(poly) poly.in <- polygrid(seq(0,1,l=11), seq(0,1,l=11), poly, vec=TRUE) points(poly.in$xy)
Computes practical ranges for the correlation functions implemented in the geoR package
practicalRange(cov.model, phi, kappa = 0.5, correlation = 0.05, ...)
practicalRange(cov.model, phi, kappa = 0.5, correlation = 0.05, ...)
cov.model |
correlation model as documented in
|
phi |
correlation parameter as documented in |
kappa |
additional correlation parameter as documented in
|
correlation |
correlation threshold for asymptotic models. Defaults to 0.05. |
... |
arguments to be passed to |
A scalar with the value of the practical range.
practicalRange("exp", phi=10) practicalRange("sph", phi=10) practicalRange("gaus", phi=10) practicalRange("matern", phi=10, kappa=0.5) practicalRange("matern", phi=10, kappa=1.5) practicalRange("matern", phi=10, kappa=2.5)
practicalRange("exp", phi=10) practicalRange("sph", phi=10) practicalRange("gaus", phi=10) practicalRange("matern", phi=10, kappa=0.5) practicalRange("matern", phi=10, kappa=1.5) practicalRange("matern", phi=10, kappa=2.5)
This function facilitates the generation of a 2D prediction grid for geostatistical kriging.
pred_grid(coords, y.coords = NULL, ..., y.by = NULL, y.length.out = NULL, y.along.with = NULL)
pred_grid(coords, y.coords = NULL, ..., y.by = NULL, y.length.out = NULL, y.along.with = NULL)
coords |
a list, matrix or data-frame with xy-coordinates of prediction points or a vector with x-coordinates. |
y.coords |
a vector with y-coordinates. Needed if
argument |
... |
arguments |
y.by |
Optional. |
y.length.out |
Optional. |
y.along.with |
Optional. |
An two column data-frame which is on output of expand.grid
.
See seq
and expand.grid
which are
used internally and locations.inside
and
polygrid
to select points inside a border.
pred_grid(c(0,1), c(0,1), by=0.25) ## create a grid in a unit square loc0 <- pred_grid(ca20$borders, by=20) points(ca20) points(loc0, pch="+") points(locations.inside(loc0, ca20$border), pch="+", col=2)
pred_grid(c(0,1), c(0,1), by=0.25) ## create a grid in a unit square loc0 <- pred_grid(ca20$borders, by=20) points(ca20) points(loc0, pch="+") points(locations.inside(loc0, ca20$border), pch="+", col=2)
Performs prediction for the bivariate Gaussian common component geostatistical model
## S3 method for class 'BGCCM' predict(object, locations, borders, variable.to.predict = 1, ...)
## S3 method for class 'BGCCM' predict(object, locations, borders, variable.to.predict = 1, ...)
object |
on object of the class |
locations |
an |
borders |
optional. If missing, by default reads the element
|
variable.to.predict |
scalar with options for values or 2 indicating which variable is to be predicted. |
... |
not yet used. |
A list of the class BGCCMpred
with components:
predicted |
predicted values. |
krige.var |
prediction variances. |
This is a new function and still in draft format and pretty much untested.
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
# see http://www.leg.ufpr.br/geoR/tutorials/CCM.R
# see http://www.leg.ufpr.br/geoR/tutorials/CCM.R
Prints a short version of an object of the class BGCCM
.
## S3 method for class 'BGCCM' print(x, ...)
## S3 method for class 'BGCCM' print(x, ...)
x |
an object of the class |
... |
arguments to be passed to |
format
for options to format the output.
Computes profile likelihoods for model parameters
previously estimated using the function
likfit
.
proflik(obj.likfit, geodata, coords = geodata$coords, data = geodata$data, sill.values, range.values, nugget.values, nugget.rel.values, lambda.values, sillrange.values = TRUE, sillnugget.values = TRUE, rangenugget.values = TRUE, sillnugget.rel.values = FALSE, rangenugget.rel.values = FALSE, silllambda.values = FALSE, rangelambda.values = TRUE, nuggetlambda.values = FALSE, nugget.rellambda.values = FALSE, uni.only = TRUE, bi.only = FALSE, messages, ...)
proflik(obj.likfit, geodata, coords = geodata$coords, data = geodata$data, sill.values, range.values, nugget.values, nugget.rel.values, lambda.values, sillrange.values = TRUE, sillnugget.values = TRUE, rangenugget.values = TRUE, sillnugget.rel.values = FALSE, rangenugget.rel.values = FALSE, silllambda.values = FALSE, rangelambda.values = TRUE, nuggetlambda.values = FALSE, nugget.rellambda.values = FALSE, uni.only = TRUE, bi.only = FALSE, messages, ...)
obj.likfit |
an object of the class |
geodata |
a list containing elements |
coords |
an |
data |
a vector with data values. By default it takes the
element |
sill.values |
set of values of the partial sill parameter
|
range.values |
set of values of the range parameter
|
nugget.values |
set of values of the nugget parameter
|
nugget.rel.values |
set of values of the relative nugget parameter
|
lambda.values |
set of values of the Box-Cox transformation parameter
|
sillrange.values |
logical indicating
whether or not the 2-D profile likelihood should be computed.
Only valid if |
sillnugget.values |
as above. |
rangenugget.values |
as above. |
sillnugget.rel.values |
as above. |
rangenugget.rel.values |
as above. |
silllambda.values |
as above. |
rangelambda.values |
as above. |
nuggetlambda.values |
as above. |
nugget.rellambda.values |
as above. |
uni.only |
as above. |
bi.only |
as above. |
messages |
logical. Indicates whether status messages should be printed on the screen (i.e. current output device) while the function is running. |
... |
additional parameters to be passed to the minimization function. |
The functions .proflik.*
are auxiliary functions used to
compute the profile likelihoods. These functions are
internally called by the
minimization functions when estimating the model parameters.
An object of the class "proflik"
which is
a list. Each element contains values of a parameter (or a pair of
parameters for 2-D profiles) and the
corresponding value of the profile likelihood.
The components of the output will vary according to the
input options.
Profile likelihoods for Gaussian Random Fields are usually
uni-modal.
Unusual or jagged shapes can
be due to the lack of the convergence in the numerical minimization
for particular values of the parameter(s).
If this is the case it might be necessary to pass control
arguments
to the minimization functions using the argument ....
It's also advisable to try the different options for the
minimisation.function
argument.
See documentation of the functions optim
and/or
nlm
for further details.
2-D profiles can be computed by setting the argument
uni.only = FALSE
. However, before computing 2-D profiles be
sure they are really necessary.
Their computation can be time demanding since it
is performed on a grid determined by the
cross-product of the values defining the 1-D profiles.
There is no "default strategy" to find reasonable values for the
x-axis.
They must be found in a "try-and-error" exercise. It's recommended
to use short sequences in the initial attempts.
The EXAMPLE
section below illustrates this.
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
plot.proflik
for graphical output,
likfit
for the parameter estimation,
optim
and nlm
for further details about
the minimization functions.
op <- par(no.readonly=TRUE) ml <- likfit(s100, ini=c(.5, .5), fix.nug=TRUE) ## a first atempt to find reasonable values for the x-axis: prof <- proflik(ml, s100, sill.values=seq(0.5, 1.5, l=4), range.val=seq(0.1, .5, l=4)) par(mfrow=c(1,2)) plot(prof) ## a nicer setting ## Not run: prof <- proflik(ml, s100, sill.values=seq(0.45, 2, l=11), range.val=seq(0.1, .55, l=11)) plot(prof) ## to include 2-D profiles use: ## (commented because this is time demanding) #prof <- proflik(ml, s100, sill.values=seq(0.45, 2, l=11), # range.val=seq(0.1, .55, l=11), uni.only=FALSE) #par(mfrow=c(2,2)) #plot(prof, nlevels=16) ## End(Not run) par(op)
op <- par(no.readonly=TRUE) ml <- likfit(s100, ini=c(.5, .5), fix.nug=TRUE) ## a first atempt to find reasonable values for the x-axis: prof <- proflik(ml, s100, sill.values=seq(0.5, 1.5, l=4), range.val=seq(0.1, .5, l=4)) par(mfrow=c(1,2)) plot(prof) ## a nicer setting ## Not run: prof <- proflik(ml, s100, sill.values=seq(0.45, 2, l=11), range.val=seq(0.1, .55, l=11)) plot(prof) ## to include 2-D profiles use: ## (commented because this is time demanding) #prof <- proflik(ml, s100, sill.values=seq(0.45, 2, l=11), # range.val=seq(0.1, .55, l=11), uni.only=FALSE) #par(mfrow=c(2,2)) #plot(prof, nlevels=16) ## End(Not run) par(op)
Reads data from a ASCII file and converts it to an object of the
class
geodata
, the standard data format for the
geoR package.
read.geodata(file, header = FALSE, coords.col = 1:2, data.col = 3, data.names = NULL, covar.col = NULL, covar.names = "header", units.m.col = NULL, realisations = NULL, na.action = c("ifany", "ifdata", "ifcovar", "none"), rep.data.action, rep.covar.action, rep.units.action, ...)
read.geodata(file, header = FALSE, coords.col = 1:2, data.col = 3, data.names = NULL, covar.col = NULL, covar.names = "header", units.m.col = NULL, realisations = NULL, na.action = c("ifany", "ifdata", "ifcovar", "none"), rep.data.action, rep.covar.action, rep.units.action, ...)
file |
a string with the name of the ASCII file. |
header |
logical. Indicates whether the variables names should be read from the first line of the input file. |
coords.col |
a vector with the numbers of the columns containing the coordinates. |
data.col |
a scalar or vector with the number of the column(s) containing the data. |
data.names |
a string or vector of strings with names for the data columns. Only valid if there is more than one column of data. By default the names in the original object are used. |
covar.col |
optional. A scalar or vector with the number of the column(s) with the values of the covariate(s). |
covar.names |
optional. A vector with the names of the the covariates. By default the names in the original object are used. |
units.m.col |
optional. A scalar with the column number corresponding to the offset variable. Alternativelly can be a character vector with the name of the offset. This option is particularly relevant when using the package geoRglm. |
realisations |
optional. A vector indicating the replication
number. For more details see documentation for
|
na.action |
a string. Defines action to be taken in the presence of
|
rep.data.action |
a string or a function. Defines action to be taken when there is more than
one data at the same location. For more details see documentation for
|
rep.covar.action |
a string or a function. Defines action to be taken when there is more than
one covariate at the same location. For more details see documentation for
|
rep.units.action |
a string or a function.
Defines action to be taken on the element |
... |
further arguments to be passed to the function |
The function read.table
is used to read the data from the
ASCII file and then as.geodata
is used to convert
to an object of the class
geodata
.
An object of the class
geodata
.
See documentation for the function as.geodata
for
further details.
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
as.geodata
to convert existing R objects,
read.table
, the basic R function used to read ASCII files,
and list
for detailed information about lists.
This data-set was used by Diggle, Tawn and Moyeed (1998) to illustrate
the model-based geostatistical methodology introduced in the paper.
discussed in the paper. The radionuclide concentration data set consists
of measurements of -ray counts at
locations.
data(rongelap)
data(rongelap)
The object is a list with the following components:
coords
the coordinates of data locations.
data
the data.
units.m
-dimensional vector of observation-times for the data.
borders
a matrix with the coordinates defining the coastline on Rongelap Island.
For further details on the radionuclide concentration data, see Diggle, Harper and Simon (1997), Diggle, Tawn and Moyeed (1998) and Christensen (2004).
Christensen, O. F. (2004). Monte Carlo maximum likelihood in model-based geostatistics. Journal of computational and graphical statistics 13 702-718.
Diggle, P. J., Harper, L. and Simon, S. L. (1997). Geostatistical analysis of residual contamination from nuclea testing. In: Statistics for the environment 3: pollution assesment and control (eds. V. Barnet and K. F. Turkmann), Wiley, Chichester, 89-107.
Diggle, P. J., Tawn, J. A. and Moyeed, R. A. (1998). Model-based geostatistics (with Discussion). Applied Statistics, 47, 299–350.
These two simulated data sets are the ones used in the Technical Report which describes the package geoR (see reference below). These data-sets are used in several examples throughout the package documentation.
data(s100) data(s121)
data(s100) data(s121)
Two objects of the class
geodata
. Both are lists
with the following components:
coords
the coordinates of data locations.
data
the simulated data. Notice that for s121
this a matrix with 10 simulations.
cov.model
the correlation model.
nugget
the values of the nugget parameter.
cov.pars
the covariance parameters.
kappa
the value of the parameter kappa.
lambda
the value of the parameter lambda.
Ribeiro Jr, P.J. and Diggle, P.J. (1999) geoS: A geostatistical library for S-PLUS. Technical report ST-99-09, Dept of Maths and Stats, Lancaster University.
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
plot(s100) plot(s121, type="l")
plot(s100) plot(s121, type="l")
This is the simulated data-set used in the Technical Report which describes the implementation of the function krige.bayes (see reference below).
data(s256i)
data(s256i)
Two objects of the class
geodata
. Both are lists
with the following components:
coords
the coordinates of data locations.
data
the simulated data.
Ribeiro Jr, P.J. and Diggle, P.J. (1999) Bayesian inference in Gaussian model-based geostatistics. Technical report ST-99-08, Dept of Maths and Stats, Lancaster University.
Further information about the geoR package can be found at:
http://www.leg.ufpr.br/geoR/.
points(s256i, pt.div="quintiles", cex.min=1, cex.max=1)
points(s256i, pt.div="quintiles", cex.min=1, cex.max=1)
This functions facilitates extracting samples from geodata objects.
sample.geodata(x, size, replace = FALSE, prob = NULL, coef.logCox, external)
sample.geodata(x, size, replace = FALSE, prob = NULL, coef.logCox, external)
x |
an object of the class |
size |
non-negative integer giving the number of items to choose. |
replace |
Should sampling be with replacement? |
prob |
A vector of probability weights for obtaining the elements of the data points being sampled. |
coef.logCox |
optional. A scalar with the coeficient for the log-Cox process. See DETAILS below. |
external |
numeric values of a random field to be used in the log-Cox inhomogeneous poisson process. |
If prob=NULL
and
the argument coef.logCox
, is provided,
sampling follows a log-Cox proccess, i.e.
the probability of each point being sampled is proportional to:
with given by the value passed to the argument
coef.logCox
and taking values passed to
the argument
external
or, if this is missing,
the element data
of the geodata
object.
Therefore, the latter generates a preferential sampling.
a list which is an object of the class geodata
.
## Not run: par(mfrow=c(1,2)) S1 <- grf(2500, grid="reg", cov.pars=c(1, .23)) image(S1, col=gray(seq(0.9,0.1,l=100))) y1 <- sample.geodata(S1, 80) points(y1$coords, pch=19) ## Now a preferential sampling y2 <- sample.geodata(S1, 80, coef=1.3) ## which is equivalent topps ## y2 <- sample.geodata(S1, 80, prob=exp(1.3*S1$data)) points(y2$coords, pch=19, col=2) ## and now a clustered (but not preferential) S2 <- grf(2500, grid="reg", cov.pars=c(1, .23)) y3 <- sample.geodata(S1, 80, prob=exp(1.3*S2$data)) ## which is equivalent to ## points(y3$coords, pch=19, col=4) image(S2, col=gray(seq(0.9,0.1,l=100))) points(y3$coords, pch=19, col=4) ## End(Not run)
## Not run: par(mfrow=c(1,2)) S1 <- grf(2500, grid="reg", cov.pars=c(1, .23)) image(S1, col=gray(seq(0.9,0.1,l=100))) y1 <- sample.geodata(S1, 80) points(y1$coords, pch=19) ## Now a preferential sampling y2 <- sample.geodata(S1, 80, coef=1.3) ## which is equivalent topps ## y2 <- sample.geodata(S1, 80, prob=exp(1.3*S1$data)) points(y2$coords, pch=19, col=2) ## and now a clustered (but not preferential) S2 <- grf(2500, grid="reg", cov.pars=c(1, .23)) y3 <- sample.geodata(S1, 80, prob=exp(1.3*S2$data)) ## which is equivalent to ## points(y3$coords, pch=19, col=4) image(S2, col=gray(seq(0.9,0.1,l=100))) points(y3$coords, pch=19, col=4) ## End(Not run)
Sample quadruples from the posterior
distribution returned by
krige.bayes
.
sample.posterior(n, kb.obj)
sample.posterior(n, kb.obj)
n |
number of samples |
kb.obj |
on object with an output of |
A data-frame with samples from the posterior distribution of the model parameters.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
krige.bayes
and sample.posterior
.
Sample quadruples from the prior distribution of parameters specifying a Gaussian
random field.
Typically the prior is specified in the same manner as when calling
krige.bayes
.
sample.prior(n, kb.obj=NULL, prior=prior.control())
sample.prior(n, kb.obj=NULL, prior=prior.control())
n |
number of samples |
kb.obj |
on object with an output of |
prior |
an call to |
A data-frame with a sample of the prior
distribution of model parameters, where
is the length of
the mean parameter
.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
krige.bayes
and sample.posterior
.
sample.prior(50, prior=prior.control(beta.prior = "normal", beta = .5, beta.var.std=0.1, sigmasq.prior="sc", sigmasq=1.2, df.sigmasq= 2, phi.prior="rec", phi.discrete = seq(0,2, l=21)))
sample.prior(50, prior=prior.control(beta.prior = "normal", beta = .5, beta.var.std=0.1, sigmasq.prior="sc", sigmasq=1.2, df.sigmasq= 2, phi.prior="rec", phi.discrete = seq(0,2, l=21)))
This is an function typically called by functions in the package geoR to set limits for the axis when plotting spatial data.
set.coords.lims(coords, borders = coords, xlim, ylim, ...)
set.coords.lims(coords, borders = coords, xlim, ylim, ...)
coords |
an |
borders |
an |
xlim , ylim
|
the ranges to be encompassed by the x and y axes. |
... |
not used, included just for internal handling. |
A matrix with limits for the axis.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Data from the SIC-97 project: Spatial Interpolation Comparison.
data(SIC)
data(SIC)
Four objects of the class
"geodata"
:
sic.all
, sic.100
, sic.367
, sic.some
.
Each is a list with two components:
coords
the coordinates of the data locations. The distance are given in kilometers.
data
rainfall values. The unit is milimeters.
altitude
elevation values. The unit is milimeters.
Additionally an matrix sic.borders
with the borders of the country.
Data from the project Spatial Interpolation Comparison 97; see https://wiki.52north.org/bin/view/AI_GEOSTATS/EventsSIC97.
Christensen, O.F., Diggle, P.J. and Ribeiro Jr, P.J. (2001) Analysing positive-valued spatial data: the transformed Gaussian model. In Monestiez, P., Allard, D. and Froidevaux (eds), GeoENV III - Geostatistics for environmental applications. Quantitative Geology and Geostatistics, Kluwer Series, 11, 287–298.
points(sic.100, borders=sic.borders) points(sic.all, borders=sic.borders)
points(sic.100, borders=sic.borders) points(sic.all, borders=sic.borders)
Several soil chemistry properties measured on a regular grid with 10x25 points spaced by 5 meters.
data(soil250)
data(soil250)
A data frame with 250 observations on the following 22 variables.
x-coordinate
y-coordinate
elevation
a numeric vecto, sand portion of the sample.
a numeric vector, silt portion of the sample.
a numeric vector, sand portion of the sample.
a numeric vector, soil pH at water
a numeric vector, soil pH by KCl
a numeric vector, calcium content
a numeric vector, magnesium content
a numeric vector, potassio content
a numeric vector, aluminium content
a numeric vector, hidrogen content
a numeric vector, carbon content
a numeric vector, nitrogen content
a numeric vector, catium exchange capability
a numeric vector, enxofrar content
a numeric vector
a numeric vector
a numeric vector
a numeric vector
a numeric vector, carbon/nitrogen relation
Uniformity trial with 250 undisturbed soil samples collected at 25cm
soil depth of spacing of 5 meters, resulting on a regular grid of
points.
See also the data-set wrc with other variables colected at the same points.
Bassoi thesis
Bassoi papers
data(soil250) ctc <- as.geodata(soil250, data.col=16) plot(ctc)
data(soil250) ctc <- as.geodata(soil250, data.col=16) plot(ctc)
Data on soya bean production in a uniformity trial measured at plots of size 5x5 meters and other soil properties measured in points given by the data coordinates.
data(soja98)
data(soja98)
A data frame with 256 observations on the following 10 variables.
X
a numeric vector with X-coordinates of the plot centres.
Y
a numeric vector with X-coordinates of the plot centres.
P
a numeric vector, phosphorous content.
PH
a numeric vector, soil pH.
K
a numeric vector, potassium content. (Cmol/dm^3)
MO
a numeric vector, organic matter. (percentage)
SB
a numeric vector, basis saturation.
iCone
a numeric vector, cone index, measuring mechanic resistence of the soil. (kg/cm^2)
Rend
a numeric vector, total soya production within the plot (kg).
PROD
a numeric vector, production converted to productivity by a unit of area - hectare (ton/ha).
Souza, E.G.; Jojann, J. A.; Rocha, J. V.; Ribeiro, S. R. A.; Silva, M. S., Upazo, M. A. U.; Molin, J. P.; Oliveira, E. F.; Nóbrega, L. H. P. (1999) Variabilidade espacial dos atributos químicos do solo em um latossolo roxo distrófico da região de Cascavel-PR. Engenharia Agrícola. Jaboticabal, volume 18, nr. 3, p.80-92.
data(soja98) plot(soja98) require(geoR) prod98 <- as.geodata(soja98, coords.col=1:2, data.col=) plot(prod98, low=TRUE)
data(soja98) plot(soja98) require(geoR) prod98 <- as.geodata(soja98, coords.col=1:2, data.col=) plot(prod98, low=TRUE)
Computes summaries based on simulations of predictive distribution
returned by
krige.bayes
and krige.conv
.
statistics.predictive(simuls, mean.var = TRUE, quantile, threshold, sim.means, sim.vars)
statistics.predictive(simuls, mean.var = TRUE, quantile, threshold, sim.means, sim.vars)
simuls |
object with simulations from the predictive distribution |
mean.var |
Logical. Indicates whether or not to compute mean and variances of the simulations at each location. |
quantile |
defines quantile estimator. See
documentation for |
threshold |
defines probability estimator. See
documentation for |
sim.means |
Logical. Indicates whether or not to compute the mean of of the conditional simulations. |
sim.vars |
Logical. Indicates whether or not to compute the variances of the conditional simulations. |
A list with one ore more of the following components.
mean |
mean at each prediction location. |
variance |
variance at each prediction location. |
quantiles |
quantiles, at each prediction location. |
probabilities |
probabilities, at each prediction location, of been below the provided threshold. |
sim.means |
vector with means of each conditional simulation. |
sim.vars |
vector with variances of each conditional simulation. |
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
Selects elements of a geodata
object wich are within a
rectangular (sub)area
subarea(geodata, xlim, ylim, ...)
subarea(geodata, xlim, ylim, ...)
geodata |
an object of the class |
xlim |
optional, a vector with selected range of the x-coordinates. |
ylim |
optional, a vector with selected range of the y-coordinates. |
... |
further arguments to be passed to |
The function copies the original geodata
object and
selects values of $coords
, $data
, $borders
,
$covariate
and $units.m
which lies within the selected
sub-area.
Remaining components of the geodata objects are untouched.
If xlim
and/or ylim
are not provided the function
prompts the user to click 2 points defining an retangle defining the
subarea on a existing plot.
Returns an geodata
object, subsetting of the original one provided.
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
foo <- matrix(c(4,6,6,4,2,2,4,4), nc=2) foo1 <- zoom.coords(foo, 2) foo1 foo2 <- coords2coords(foo, c(6,10), c(6,10)) foo2 plot(1:10, 1:10, type="n") polygon(foo) polygon(foo1, lty=2) polygon(foo2, lwd=2) arrows(foo[,1], foo[,2],foo1[,1],foo1[,2], lty=2) arrows(foo[,1], foo[,2],foo2[,1],foo2[,2]) legend("topleft", c("foo", "foo1 (zoom.coords)", "foo2 (coords2coords)"), lty=c(1,2,1), lwd=c(1,1,2)) ## "zooming" part of The Gambia map gb <- gambia.borders/1000 gd <- gambia[,1:2]/1000 plot(gb, ty="l", asp=1, xlab="W-E (kilometres)", ylab="N-S (kilometres)") points(gd, pch=19, cex=0.5) r1b <- gb[gb[,1] < 420,] rc1 <- rect.coords(r1b, lty=2) r1bn <- zoom.coords(r1b, 1.8, xoff=90, yoff=-90) rc2 <- rect.coords(r1bn, xz=1.05) segments(rc1[c(1,3),1],rc1[c(1,3),2],rc2[c(1,3),1],rc2[c(1,3),2], lty=3) lines(r1bn) r1d <- gd[gd[,1] < 420,] r1dn <- zoom.coords(r1d, 1.7, xlim.o=range(r1b[,1],na.rm=TRUE), ylim.o=range(r1b[,2], na.rm=TRUE), xoff=90, yoff=-90) points(r1dn, pch=19, cex=0.5) text(450,1340, "Western Region", cex=1.5) #if(require(geoRglm)){ #data(rongelap) #points(rongelap) ## zooming the western area #rongwest <- subarea(rongelap, xlim=c(-6300, -4800)) #points(rongwest) ## now zooming in the same plot #points(rongelap) #rongwest.z <- zoom.coords(rongwest, xzoom=3, xoff=2000, yoff=3000) #points(rongwest.z, add=TRUE) #rect.coords(rongwest$sub, quiet=TRUE) #rect.coords(rongwest.z$sub, quiet=TRUE) #}
foo <- matrix(c(4,6,6,4,2,2,4,4), nc=2) foo1 <- zoom.coords(foo, 2) foo1 foo2 <- coords2coords(foo, c(6,10), c(6,10)) foo2 plot(1:10, 1:10, type="n") polygon(foo) polygon(foo1, lty=2) polygon(foo2, lwd=2) arrows(foo[,1], foo[,2],foo1[,1],foo1[,2], lty=2) arrows(foo[,1], foo[,2],foo2[,1],foo2[,2]) legend("topleft", c("foo", "foo1 (zoom.coords)", "foo2 (coords2coords)"), lty=c(1,2,1), lwd=c(1,1,2)) ## "zooming" part of The Gambia map gb <- gambia.borders/1000 gd <- gambia[,1:2]/1000 plot(gb, ty="l", asp=1, xlab="W-E (kilometres)", ylab="N-S (kilometres)") points(gd, pch=19, cex=0.5) r1b <- gb[gb[,1] < 420,] rc1 <- rect.coords(r1b, lty=2) r1bn <- zoom.coords(r1b, 1.8, xoff=90, yoff=-90) rc2 <- rect.coords(r1bn, xz=1.05) segments(rc1[c(1,3),1],rc1[c(1,3),2],rc2[c(1,3),1],rc2[c(1,3),2], lty=3) lines(r1bn) r1d <- gd[gd[,1] < 420,] r1dn <- zoom.coords(r1d, 1.7, xlim.o=range(r1b[,1],na.rm=TRUE), ylim.o=range(r1b[,2], na.rm=TRUE), xoff=90, yoff=-90) points(r1dn, pch=19, cex=0.5) text(450,1340, "Western Region", cex=1.5) #if(require(geoRglm)){ #data(rongelap) #points(rongelap) ## zooming the western area #rongwest <- subarea(rongelap, xlim=c(-6300, -4800)) #points(rongwest) ## now zooming in the same plot #points(rongelap) #rongwest.z <- zoom.coords(rongwest, xzoom=3, xoff=2000, yoff=3000) #points(rongwest.z, add=TRUE) #rect.coords(rongwest$sub, quiet=TRUE) #rect.coords(rongwest.z$sub, quiet=TRUE) #}
Subsets a object of the class geodata
by transforming it to a data-frame, using subset
and back transforming to a geodata
object.
## S3 method for class 'geodata' subset(x, ..., other = TRUE)
## S3 method for class 'geodata' subset(x, ..., other = TRUE)
x |
an object of the class |
... |
arguments to be passed to
|
other |
logical. If |
A list which is an object of the class geodata
.
subset
for the generic function and methods and
as.geodata
for more information on geodata objects.
subset(ca20, data > 70) subset(ca20, area == 1)
subset(ca20, data > 70) subset(ca20, area == 1)
Sumarises each of the main elements of an object of the class geodata
.
## S3 method for class 'geodata' summary(object, lambda =1, add.to.data = 0, by.realisations=TRUE, ...)
## S3 method for class 'geodata' summary(object, lambda =1, add.to.data = 0, by.realisations=TRUE, ...)
object |
an object of the class |
lambda |
value of the Box-Cox transformation parameter. Two particular cases
are |
add.to.data |
scalar, Constant value to be added to the data
values.
Only used if a value different from 1 is passed to the argument |
by.realisations |
logical. Indicates whether the summary must be performed separatly for each realisation, if the |
... |
further arguments to be passed to the function
|
A list with components
coords.summary |
a matrix with minimum and maximum values for the coordinates. |
distances.summary |
minimum and maximum distances between pairs of points. |
borders.summary |
a matrix with minimum and maximum values for
the coordinates. Only returned if there is an element |
data.summary |
summary statistics (min, max, quartiles and mean) for the data. |
units.m.summary |
summary statistics (min, max, quartiles and mean)
for the offset variable. Only returned if there is an element |
covariate.summary |
summary statistics (min, max, quartiles and mean)
for the covariate(s). Only returned if there is an element |
others |
names of other elements if present in the |
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
summary(s100) summary(ca20)
summary(s100) summary(ca20)
Summarizes results returned by the function likfit
.
Functions are methods for summary
and
print
for the classes likGRF
and summary.likGRF
.
## S3 method for class 'likGRF' summary(object, ...) ## S3 method for class 'likGRF' print(x, digits = max(3, getOption("digits") - 3), ...) ## S3 method for class 'summary.likGRF' print(x, digits = max(3, getOption("digits") - 3), ...)
## S3 method for class 'likGRF' summary(object, ...) ## S3 method for class 'likGRF' print(x, digits = max(3, getOption("digits") - 3), ...) ## S3 method for class 'summary.likGRF' print(x, digits = max(3, getOption("digits") - 3), ...)
object |
an object of |
x |
an object of |
digits |
the number of significant digits to use when printing. |
... |
extra arguments for |
A detailed summary of a object of the class likGRF
is produced by
by summary.likGRF
and printed by print.summary.likGRF
.
This includes model specification with values of fixed and estimated parameters.
A simplified summary of the parameter estimation is printed by
print.likGRF
.
print.likGRF
prints the parameter estimates and the value of the
maximized likelihood.summary.likGRF
returns a list with main results of a call to
likfit
.print.summary.likGRF
prints these results on the screen (or other
output device) in a "nice" format.
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
# See examples for the function likfit()
# See examples for the function likfit()
This function prints a summary of the parameter estimation results given
by variofit
.
## S3 method for class 'variofit' summary(object, ...)
## S3 method for class 'variofit' summary(object, ...)
object |
an object of the class |
... |
other arguments to be passed to the function
|
Prints a summary of the estimation results on the screen or other output device.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
The functions variofit
for
variogram based estimation. For likelihood based parameter estimation see likfit
.
s100.vario <- variog(s100, max.dist=1) wls <- variofit(s100.vario, ini=c(.5, .5), fix.nugget = TRUE) wls summary(wls)
s100.vario <- variog(s100, max.dist=1) wls <- variofit(s100.vario, ini=c(.5, .5), fix.nugget = TRUE) wls summary(wls)
Measurements at 56 locations of concentration of trichloroethylene (TCE) in groundwater on a transect in a fine-sand superficial aquifer. Extract from Kitanidis' book.
data(tce)
data(tce)
An object of the class geodata
which is a list with the elements:
coordinates of the data location (feet).
the data vector with measurements of the TCE concentration (ppb).
Kitanidis, P.K. Introduction to geostatistics - applications in hidrology (1997). Cambridge University Press.
summary(tce) summary(tce, lambda=0) plot(tce) points(tce) points(tce, lambda=0)
summary(tce) summary(tce, lambda=0) plot(tce) points(tce) points(tce, lambda=0)
Builds the trend matrix in accordance to a specification of the mean provided by the user.
trend.spatial(trend, geodata, add.to.trend)
trend.spatial(trend, geodata, add.to.trend)
trend |
specifies the mean part of the model.
See |
geodata |
optional. An object of the class |
add.to.trend |
optional. Specifies aditional terms to the mean part of the model. See details below. |
The implicity model assumes that there is an underlying process
with mean , where
denotes the coordinates
of a spatial location.
The argument
trend
defines the form of the mean and the
following options are allowed:
"cte"
the mean is assumed to be constant over the region,
in which case . This is the default
option.
"1st"
the mean is assumed to be a first order polynomial on the coordinates:
"2nd"
the mean is assumed to be a second order polynomial on the coordinates:
~ model
a model specification. See
formula
for further details on how to specify
a model in R using formulas. Notice that the model term before
the ~
is not necessary.
Typically used to include covariates
(external trend) in the model.
Denote by and
the spatial coordinates.
The following specifications are equivalent:
trend = "1st"
and trend = ~ x1 + x2
trend = "2nd"
and trend = ~ x1 + x2 + I(x1^2) + I(x2^2) + I(x1*x2)
Search path for covariates
Typically, functions in the package geoR which calls
trend.spatial
will have the arguments geodata
,
coords
and data
.
When the trend is specifed as trend = ~ model
the terms included in the model will be searched for in the following
path sequence (modified in version 1.7-6, no longer attach objects):
in the object geodata
(coerced to data-frame)
in the users/session Global environment
in the session search path
The argument add.to.trend
adds terms to what is specified in
the argument trend
. This seems redundant but allow
specifications of the type: trend="2nd", add.trend=~other.covariates
.
An object of the class trend.spatial
which is an trend
matrix, where
is the number of spatial
locations and
is the number of mean parameters in the model.
This is an auxiliary function typically called by other geoR functions.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
The section DETAILS
in the documentation for
likfit
for more about the underlying model.
# a first order polynomial trend trend.spatial("1st", sic.100)[1:5,] # a second order polynomial trend trend.spatial("2nd", sic.100)[1:5,] # a trend with a covariate trend.spatial(~altitude, sic.100)[1:5,] # a first degree trend plus a covariate trend.spatial(~coords+altitude, sic.100)[1:5,] # with produces the same as trend.spatial("1st", sic.100, add=~altitude)[1:5,] # and yet another exemple trend.spatial("2nd", sic.100, add=~altitude)[1:5,]
# a first order polynomial trend trend.spatial("1st", sic.100)[1:5,] # a second order polynomial trend trend.spatial("2nd", sic.100)[1:5,] # a trend with a covariate trend.spatial(~altitude, sic.100)[1:5,] # a first degree trend plus a covariate trend.spatial(~coords+altitude, sic.100)[1:5,] # with produces the same as trend.spatial("1st", sic.100, add=~altitude)[1:5,] # and yet another exemple trend.spatial("2nd", sic.100, add=~altitude)[1:5,]
This function builds the covariance matrix for a set of spatial locations, given the covariance parameters. According to the input options other results related to the covariance matrix (such as decompositions, determinants, inverse. etc) can also be returned.
varcov.spatial(coords = NULL, dists.lowertri = NULL, cov.model = "matern", kappa = 0.5, nugget = 0, cov.pars = stop("no cov.pars argument"), inv = FALSE, det = FALSE, func.inv = c("cholesky", "eigen", "svd", "solve"), scaled = FALSE, only.decomposition = FALSE, sqrt.inv = FALSE, try.another.decomposition = TRUE, only.inv.lower.diag = FALSE, ...)
varcov.spatial(coords = NULL, dists.lowertri = NULL, cov.model = "matern", kappa = 0.5, nugget = 0, cov.pars = stop("no cov.pars argument"), inv = FALSE, det = FALSE, func.inv = c("cholesky", "eigen", "svd", "solve"), scaled = FALSE, only.decomposition = FALSE, sqrt.inv = FALSE, try.another.decomposition = TRUE, only.inv.lower.diag = FALSE, ...)
coords |
an |
dists.lowertri |
a vector with the lower triangle of the matrix
of distances between pairs of data points. If not provided
the argument |
cov.model |
a string indicating the type of the correlation
function. More details in the
documentation for |
kappa |
values of the additional smoothness parameter, only required by
the following correlation
functions: |
nugget |
the value of the nugget parameter |
cov.pars |
a vector with 2 elements or an |
inv |
if |
det |
if |
func.inv |
algorithm used for the decomposition and inversion of the covariance
matrix. Options are |
scaled |
logical indicating whether the covariance matrix should
be scaled. If |
only.decomposition |
logical. If |
sqrt.inv |
if |
try.another.decomposition |
logical. If |
only.inv.lower.diag |
logical. If |
... |
for naw, only for internal usage. |
The elements of the covariance matrix are computed by the function
cov.spatial
. Typically this is an auxiliary function called by other
functions in the geoR package.
The result is always list. The components will vary according to the input options. The possible components are:
varcov |
the covariance matrix. |
sqrt.varcov |
a square root of the covariance matrix. |
lower.inverse |
the lower triangle of the inverse of covariance matrix. |
diag.inverse |
the diagonal of the inverse of covariance matrix. |
inverse |
the inverse of covariance matrix. |
sqrt.inverse |
a square root of the inverse of covariance matrix. |
log.det.to.half |
the logarithmic of the square root of the determinant of the covariance matrix. |
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
cov.spatial
for more information on the
correlation functions; chol
, solve
,
svd
and eigen
for matrix inversion and/or decomposition.
Covariance matrix for the bivariate Gaussian common component geostatistical model or its inverse, and optionally the determinant of the matrix.
varcovBGCCM(dists.obj, cov0.pars, cov1.pars, cov2.pars, cov0.model = "matern", cov1.model = "matern", cov2.model = "matern", kappa0 = 0.5, kappa1 = 0.5, kappa2 = 0.5, scaled = TRUE, inv = FALSE, det = FALSE)
varcovBGCCM(dists.obj, cov0.pars, cov1.pars, cov2.pars, cov0.model = "matern", cov1.model = "matern", cov2.model = "matern", kappa0 = 0.5, kappa1 = 0.5, kappa2 = 0.5, scaled = TRUE, inv = FALSE, det = FALSE)
dists.obj |
a vector with distance values |
cov0.pars |
covarianve paremeter values for the common component |
cov1.pars |
covariance parameter for the individual structure of the first variable |
cov2.pars |
covariance parameter for the individual structure of the second variable |
cov0.model |
character indicating a valid correlation model |
cov1.model |
character indicating a valid correlation model |
cov2.model |
character indicating a valid correlation model |
kappa0 |
scalar |
kappa1 |
scalar |
kappa2 |
scalar |
scaled |
logical |
inv |
logical. If |
det |
logical. Optional, if |
A matrix which is the covariance matrix for the
bivariate Gaussian
common component geostatistical model or its inverse if
inv=TRUE
.
If det=T
the logarithm of the determinant
of the matrix is also returned as an attribute
named logdetS
.
This is a new function and still in draft format and pretty much untested.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
# see http://www.leg.ufpr.br/geoR/tutorials/CCM.R
# see http://www.leg.ufpr.br/geoR/tutorials/CCM.R
Estimate covariance parameters by fitting a parametric model to a empirical variogram. Variograms models can be fitted by using weighted or ordinary least squares.
variofit(vario, ini.cov.pars, cov.model, fix.nugget = FALSE, nugget = 0, fix.kappa = TRUE, kappa = 0.5, simul.number = NULL, max.dist = vario$max.dist, weights, minimisation.function, limits = pars.limits(), messages, ...)
variofit(vario, ini.cov.pars, cov.model, fix.nugget = FALSE, nugget = 0, fix.kappa = TRUE, kappa = 0.5, simul.number = NULL, max.dist = vario$max.dist, weights, minimisation.function, limits = pars.limits(), messages, ...)
vario |
an object of the class |
ini.cov.pars |
initial values for the covariance parameters:
|
cov.model |
a string with the name of the correlation
function. For further details see documentation for
|
fix.nugget |
logical, indicating whether the parameter
|
nugget |
value for the nugget parameter. Regarded as a
fixed values if |
fix.kappa |
logical, indicating whether the parameter
|
kappa |
value of the smoothness parameter. Regarded as a
fixed values if |
simul.number |
number of simulation. To be used when the object passed to the
argument |
max.dist |
maximum distance considered when fitting the
variogram. Defaults to |
weights |
type weights used in the loss function. See
|
limits |
values defining lower and upper limits for the model
parameters used in the numerical minimisation.
Only valid if |
minimisation.function |
minimization function used to estimate
the parameters. Options are |
messages |
logical. Indicates whether or not status messages are printed on the screen (or other output device) while the function is running. |
... |
further parameters to be passed to the minimization
function. Typically arguments of the type |
Numerical minimization
The parameter values are found by numerical optimization using one of
the functions: optim
, nlm
and nls
.
In given circunstances the algorithm may not converge to correct
parameter values when called with default options and the user may
need to pass extra options for the optimizers. For instance the
function optim
takes a control
argument.
The user should try different initial values and if the parameters have
different orders of magnitude may need to use options to scale the parameters.
Some possible workarounds in case of problems include:
rescale you data values (dividing by a constant, say)
rescale your coordinates (subtracting values and/or dividing by constants)
Use the mechanism to pass control()
options for the
optimiser internally
Initial values
The algorithms for minimization functions require initial values of the parameters.
A unique initial value is used if a vector is provided in the argument
ini.cov.pars
. The elements are initial values for
and
, respectively.
This vector is concatenated with the value of the
argument
nugget
if fix.nugget = FALSE
and kappa
if fix.kappa = TRUE
.
Specification of multiple initial values is also possible.
If this is the case, the function
searches for the one which minimizes the loss function and uses this as
the initial value for the minimization algorithm.
Multiple initial values are specified by providing a matrix in the
argument
ini.cov.pars
and/or, vectors in the arguments
nugget
and kappa
(if included in the estimation).
If ini.cov.pars
is a matrix, the first column has values of
and the second has values of
.
Alternatively the argument ini.cov.pars
can take an object of
the class eyefit
or variomodel
. This allows the usage
of an output of the functions eyefit
, variofit
or
likfit
be used as initial value.
If minimisation.function = "nls"
only the values of
and
(if this is included in the
estimation) are used. Values for the remaning are not need by the algorithm.
If cov.model = "linear"
only the value of
is used. Values for the
remaning are not need by this algorithm.
If cov.model = "pure.nugget"
no initial values are needed since
no minimisation function is used.
Weights
The different options for the argument weights
are used to define the loss function to be minimised.
The available options are as follows.
"npairs"
indicates that the weights are given by the
number of pairs in each bin.
This is the default option unless variog$output.type ==
"cloud"
.
The loss function is:
"cressie"
weights as suggested by Cressie (1985).
"equal"
equal values for the weights. For this case
the estimation corresponds to the ordinary least squares variogram
fitting. This is the default option if variog$output.type ==
"cloud"
.
Where is the vector with the variogram parameters
and
for each
-bin
is the number of
pairs,
is the
value of the empirical variogram and
is the value of the theoretical variogram.
See also Cressie (1993) and Barry, Crowder and Diggle (1997) for further discussions on methods to estimate the variogram parameters.
An object of the class
"variomodel"
and "variofit"
which is list with the following components:
nugget |
value of the nugget parameter. An estimated value if
|
cov.pars |
a two elements vector with estimated values of the covariance
parameters |
cov.model |
a string with the name of the correlation function. |
kappa |
fixed value of the smoothness parameter. |
value |
minimized value of the loss function. |
max.dist |
maximum distance considered in the variogram fitting. |
minimisation.function |
minimization function used. |
weights |
a string indicating the type of weights used for the variogram fitting. |
method |
a string indicating the type of variogram fitting method (OLS or WLS). |
fix.kappa |
logical indicating whether the parameter |
fix.nugget |
logical indicating whether the nugget parameter was fixed. |
lambda |
transformation parameters inherith from the object
provided in the argument |
message |
status messages returned by the function. |
call |
the function call. |
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Barry, J.T., Crowder, M.J. and Diggle, P.J. (1997) Parametric estimation of the variogram. Tech. Report, Dept Maths & Stats, Lancaster University.
Cressie, N.A.C (1985) Mathematical Geology. 17, 563-586.
Cressie, N.A.C (1993) Statistics for Spatial Data. New York: Wiley.
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
cov.spatial
for a detailed description of the
available correlation (variogram) functions,
likfit
for maximum
and restricted maximum likelihood estimation,
lines.variomodel
for graphical output of the fitted
model. For details on the minimization functions see optim
,
nlm
and nls
.
vario100 <- variog(s100, max.dist=1) ini.vals <- expand.grid(seq(0,1,l=5), seq(0,1,l=5)) ols <- variofit(vario100, ini=ini.vals, fix.nug=TRUE, wei="equal") summary(ols) wls <- variofit(vario100, ini=ini.vals, fix.nug=TRUE) summary(wls) plot(vario100) lines(wls) lines(ols, lty=2)
vario100 <- variog(s100, max.dist=1) ini.vals <- expand.grid(seq(0,1,l=5), seq(0,1,l=5)) ols <- variofit(vario100, ini=ini.vals, fix.nug=TRUE, wei="equal") summary(ols) wls <- variofit(vario100, ini=ini.vals, fix.nug=TRUE) summary(wls) plot(vario100) lines(wls) lines(ols, lty=2)
Computes sample (empirical) variograms with options for the classical or robust
estimators. Output can be returned as a binned variogram
, a
variogram cloud
or a smoothed variogram
. Data
transformation (Box-Cox) is allowed.
“Trends” can be specified and are fitted by ordinary least
squares in which case the variograms are computed using the
residuals.
variog(geodata, coords = geodata$coords, data = geodata$data, uvec = "default", breaks = "default", trend = "cte", lambda = 1, option = c("bin", "cloud", "smooth"), estimator.type = c("classical", "modulus"), nugget.tolerance, max.dist, pairs.min = 2, bin.cloud = FALSE, direction = "omnidirectional", tolerance = pi/8, unit.angle = c("radians","degrees"), angles = FALSE, messages, ...)
variog(geodata, coords = geodata$coords, data = geodata$data, uvec = "default", breaks = "default", trend = "cte", lambda = 1, option = c("bin", "cloud", "smooth"), estimator.type = c("classical", "modulus"), nugget.tolerance, max.dist, pairs.min = 2, bin.cloud = FALSE, direction = "omnidirectional", tolerance = pi/8, unit.angle = c("radians","degrees"), angles = FALSE, messages, ...)
geodata |
a list containing element |
coords |
an |
data |
a vector or matrix with data values.
If a matrix is provided, each column is regarded as one variable or realization.
Defaults to |
uvec |
a vector with values used to define the variogram binning. Only
used when |
breaks |
a vector with values to define the variogram binning. Only
used when |
trend |
specifies the mean part of the model.
See documentation of |
lambda |
values of the Box-Cox transformation parameter.
Defaults to |
option |
defines the output type: the options |
estimator.type |
|
nugget.tolerance |
a numeric value. Points which are separated by a distance less than this value are considered co-located. Defaults to zero. |
max.dist |
a numerical value defining the maximum distance for the variogram. Pairs of locations separated for distance larger than this value are ignored for the variogram calculation. If not provided defaults takes the maximum distance among all pairs of data locations. |
pairs.min |
a integer number defining the minimum numbers of
pairs for the bins.
For |
bin.cloud |
logical. If |
direction |
a numerical value for the directional (azimuth) angle. This
used to specify directional variograms. Default defines the
omnidirectional variogram. The value must be in the interval
|
tolerance |
numerical value for the tolerance angle, when
computing directional variograms. The value must be in the interval
|
unit.angle |
defines the unit for the specification of angles in
the two previous arguments. Options are |
angles |
Logical with default to |
messages |
logical. Indicates whether status messages should be printed on the screen (or output device) while the function is running. |
... |
arguments to be passed to the function |
Variograms are widely used in geostatistical analysis for exploratory purposes, to estimate covariance parameters and/or to compare theoretical and fitted models against sample variograms.
Estimators
The two estimators currently implemented are:
classical (method of moments) estimator:
Hawkins and Cressie's modulus estimator
Defining the bins
The defaults
If arguments breaks
and uvec
are not provided, the
binning is defined as follows:
read the argument max.dist
. If not provided it is set
to the maximum distance between the pairs of points.
the center of the bins are initially defined by the sequence u = seq(0,
max.dist, l = 13)
.
the interval spanned by each bin is given by the mid-points between the centers of the bins.
If an vector is passed to the argument breaks
its elements are
taken as the limits of the bins (classes of distance) and the argument uvec
is ignored.
Variations on the default
The default definition of the bins is different for some particular
cases.
if there are coincident data locations the bins follows the default above but one more bin is added at the origin (distance zero) for the collocated points.
if the argument nugget.tolerance
is provided the
separation distance between all pairs
in the interval are set to zero.
The first bin distance is set to zero (
u[1] = 0
).
The remaining bins follows the default.
if a scalar is provided to the argument uvec
the
default number of bins is defined by this number.
if a vector is provided to the argument uvec
,
its elements are taken as central points of the bins.
An object of the class
variogram
which is a
list with the following components:
u |
a vector with distances. |
v |
a vector with estimated variogram values at distances given
in |
n |
number of pairs in each bin, if
|
sd |
standard deviation of the values in each bin. |
bins.lim |
limits defining the interval spanned by each bin. |
ind.bin |
a logical vector indicating whether the number of
pairs in each bin is greater or equal to the value in the argument
|
var.mark |
variance of the data. |
beta.ols |
parameters of the mean part of the model fitted by ordinary least squares. |
output.type |
echoes the |
max.dist |
maximum distance between pairs allowed in the variogram calculations. |
estimator.type |
echoes the type of estimator used. |
n.data |
number of data. |
lambda |
value of the transformation parameter. |
trend |
trend specification. |
nugget.tolerance |
value of the nugget tolerance argument. |
direction |
direction for which the variogram was computed. |
tolerance |
tolerance angle for directional variogram. |
uvec |
lags provided in the function call. |
call |
the function call. |
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Cressie, N.A.C (1993) Statistics for Spatial Data. New York: Wiley.
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
variog4
for more on computation of
directional variograms,
variog.model.env
and variog.mc.env
for
variogram envelopes,
variofit
for variogram based
parameter estimation and
plot.variogram
for graphical output.
# # computing variograms: # # binned variogram vario.b <- variog(s100, max.dist=1) # variogram cloud vario.c <- variog(s100, max.dist=1, op="cloud") #binned variogram and stores the cloud vario.bc <- variog(s100, max.dist=1, bin.cloud=TRUE) # smoothed variogram vario.s <- variog(s100, max.dist=1, op="sm", band=0.2) # # # plotting the variograms: par(mfrow=c(2,2)) plot(vario.b, main="binned variogram") plot(vario.c, main="variogram cloud") plot(vario.bc, bin.cloud=TRUE, main="clouds for binned variogram") plot(vario.s, main="smoothed variogram") # computing a directional variogram vario.0 <- variog(s100, max.dist=1, dir=0, tol=pi/8) plot(vario.b, type="l", lty=2) lines(vario.0) legend("topleft", legend=c("omnidirectional", expression(0 * degree)), lty=c(2,1))
# # computing variograms: # # binned variogram vario.b <- variog(s100, max.dist=1) # variogram cloud vario.c <- variog(s100, max.dist=1, op="cloud") #binned variogram and stores the cloud vario.bc <- variog(s100, max.dist=1, bin.cloud=TRUE) # smoothed variogram vario.s <- variog(s100, max.dist=1, op="sm", band=0.2) # # # plotting the variograms: par(mfrow=c(2,2)) plot(vario.b, main="binned variogram") plot(vario.c, main="variogram cloud") plot(vario.bc, bin.cloud=TRUE, main="clouds for binned variogram") plot(vario.s, main="smoothed variogram") # computing a directional variogram vario.0 <- variog(s100, max.dist=1, dir=0, tol=pi/8) plot(vario.b, type="l", lty=2) lines(vario.0) legend("topleft", legend=c("omnidirectional", expression(0 * degree)), lty=c(2,1))
Computes envelops for empirical variograms by permutation of the data values on the spatial locations.
variog.mc.env(geodata, coords = geodata$coords, data = geodata$data, obj.variog, nsim = 99, save.sim = FALSE, messages)
variog.mc.env(geodata, coords = geodata$coords, data = geodata$data, obj.variog, nsim = 99, save.sim = FALSE, messages)
geodata |
a list containing elements |
coords |
an |
data |
a vector with the data values. By default it takes the
element |
obj.variog |
an object of the class |
nsim |
number of simulations used to compute the envelope. Defaults to 99. |
save.sim |
logical. Indicates whether or not the simulated data
are included in the output. Defaults to |
messages |
logical. If |
The envelops are obtained by permutation. For each simulations data values are randomly allocated to the spatial locations. The empirical variogram is computed for each simulation using the same lags as for the variogram originally computed for the data. The envelops are computed by taking, at each lag, the maximum and minimum values of the variograms for the simulated data.
An object of the class
"variogram.envelope"
which is a
list with the following components:
u |
a vector with distances. |
v.lower |
a vector with the minimum variogram values at each
distance in |
v.upper |
a vector with the maximum variogram values at each
distance in |
simulations |
a matrix with simulated data.
Only returned if |
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
variog.model.env
for envelops computed by
from a model specification,
variog
for variogram calculations,
plot.variogram
and variog.mc.env
for
graphical output.
s100.vario <- variog(s100, max.dist=1) s100.env <- variog.mc.env(s100, obj.var = s100.vario) plot(s100.vario, envelope = s100.env)
s100.vario <- variog(s100, max.dist=1) s100.env <- variog.mc.env(s100, obj.var = s100.vario) plot(s100.vario, envelope = s100.env)
Computes envelopes for a empirical variogram by simulating data for given model parameters.
Computes bootstrap paremeter estimates
variog.model.env(geodata, coords = geodata$coords, obj.variog, model.pars, nsim = 99, save.sim = FALSE, messages) boot.variofit(geodata, coords = geodata$coords, obj.variog, model.pars, nsim = 99, trace = FALSE, messages)
variog.model.env(geodata, coords = geodata$coords, obj.variog, model.pars, nsim = 99, save.sim = FALSE, messages) boot.variofit(geodata, coords = geodata$coords, obj.variog, model.pars, nsim = 99, trace = FALSE, messages)
geodata |
a list containing element |
coords |
an |
obj.variog |
an object of the class |
model.pars |
a list with model specification and parameter
values. The input is typically an object of the class
|
nsim |
number of simulations used to compute the envelopes. Defaults to 99. |
save.sim |
logical. Indicates whether or not the simulated data
are included in the output. Defaults to |
trace |
logical. If |
messages |
logical. If |
The envelopes are computed assuming a (transformed) Gaussian random field model. Simulated values are generated at the data locations, given the model parameters. The empirical variogram is computed for each simulation using the same lags as for the original variogram of the data. The envelopes are computed by taking, at each lag, the maximum and minimum values of the variograms for the simulated data.
An object of the class
"variogram.envelope"
which is a
list with the components:
u |
a vector with distances. |
v.lower |
a vector with the minimum variogram values at each
distance in |
v.upper |
a vector with the maximum variogram values at each
distance in |
simulations |
a matrix with the simulated data.
Only returned if |
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
variog.mc.env
for envelops computed by
using data permutation,
variog
for variogram calculations,
plot.variogram
and variog.mc.env
for
graphical output. The functions
likfit
, variofit
are used to estimate the model parameters.
s100.ml <- likfit(s100, ini = c(0.5, 0.5), fix.nugget = TRUE) s100.vario <- variog(s100, max.dist = 1) s100.env <- variog.model.env(s100, obj.v = s100.vario, model.pars = s100.ml) plot(s100.vario, env = s100.env)
s100.ml <- likfit(s100, ini = c(0.5, 0.5), fix.nugget = TRUE) s100.vario <- variog(s100, max.dist = 1) s100.env <- variog.model.env(s100, obj.v = s100.vario, model.pars = s100.ml) plot(s100.vario, env = s100.env)
Computes directional variograms for 4 directions provided by the user.
variog4(geodata, coords = geodata$coords, data = geodata$data, uvec = "default", breaks = "default", trend = "cte", lambda = 1, option = c("bin", "cloud", "smooth"), estimator.type = c("classical", "modulus"), nugget.tolerance, max.dist, pairs.min = 2, bin.cloud = FALSE, direction = c(0, pi/4, pi/2, 3*pi/4), tolerance = pi/8, unit.angle = c("radians", "degrees"), messages, ...)
variog4(geodata, coords = geodata$coords, data = geodata$data, uvec = "default", breaks = "default", trend = "cte", lambda = 1, option = c("bin", "cloud", "smooth"), estimator.type = c("classical", "modulus"), nugget.tolerance, max.dist, pairs.min = 2, bin.cloud = FALSE, direction = c(0, pi/4, pi/2, 3*pi/4), tolerance = pi/8, unit.angle = c("radians", "degrees"), messages, ...)
geodata |
a list containing element |
coords |
an |
data |
a vector or matrix with data values.
If a matrix is provided, each column is regarded as one variable or realization.
Defaults to |
uvec |
a vector with values to define the variogram binning. For
further details see documentation for |
breaks |
a vector with values to define the variogram binning. For
further details see documentation for |
trend |
specifies the mean part of the model.
The options are:
|
lambda |
values of the Box-Cox transformation parameter.
Defaults to |
option |
defines the output type: the options |
estimator.type |
|
nugget.tolerance |
a numeric value. Points which are separated by a distance less than this value are considered co-located. Defaults to zero. |
max.dist |
a numerical value defining the maximum distance for the variogram. Pairs of locations separated for distance larger than this value are ignored for the variogram calculation. Defaults to the maximum distance among the pairs of data locations. |
pairs.min |
a integer number defining the minimum numbers of
pairs for the bins.
For |
bin.cloud |
logical. If |
direction |
a vector with values of 4 angles, indicating the
directions for which the variograms will be computed. Default
corresponds to |
tolerance |
numerical value for the tolerance angle, when
computing directional variograms. The value must be in the interval
|
unit.angle |
defines the unit for the specification of angles in
the two previous arguments. Options are |
messages |
logical. Indicates whether status messages should be printed on the screen (or output device) while the function is running. |
... |
arguments to be passed to the function |
The output is an object of the class variog4
,
a list with five components.
The first four elements are estimated variograms for the directions
provided and the last is the omnidirectional variogram.
Each individual component is an object of the class variogram
,
an output of the function variog
.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
variog
for variogram calculations and
plot.variog4
for plotting results
var4 <- variog4(s100, max.dist=1) plot(var4)
var4 <- variog4(s100, max.dist=1) plot(var4)
Data used in Chapter 8, page 156 of Webster and Oliver (2001) to illustrate properties of the kriging predictor.
data(wo)
data(wo)
An object of the class geodata
which is a list with the elements:
coordinates of the data location.
the data vector.
coordinate of the centrally located prediction point.
coordinate of the off-centre prediction point.
Webster, R. and Oliver, M.A. (2001). Geostatistics for Environmental Scientists. Wiley.
attach(wo) par(mfrow=c(1,2)) plot(c(-10,130), c(-10,130), ty="n", asp=1) points(rbind(coords, x1)) text(coords[,1], 5+coords[,2], format(data)) text(x1[1]+5, x1[2]+5, "?", col=2) plot(c(-10,130), c(-10,130), ty="n", asp=1) points(rbind(coords, x2)) text(coords[,1], 5+coords[,2], format(data)) text(x2[1]+5, x2[2]+5, "?", col=2)
attach(wo) par(mfrow=c(1,2)) plot(c(-10,130), c(-10,130), ty="n", asp=1) points(rbind(coords, x1)) text(coords[,1], 5+coords[,2], format(data)) text(x1[1]+5, x1[2]+5, "?", col=2) plot(c(-10,130), c(-10,130), ty="n", asp=1) points(rbind(coords, x2)) text(coords[,1], 5+coords[,2], format(data)) text(x2[1]+5, x2[2]+5, "?", col=2)
Piezometric head measurements taken at the Wolfcamp Aquifer, Texas, USA. See Cressie (1993, p.212–214) for description of the scientific problem and the data. Original data were converted to SI units: coordinates are given in kilometers and pressure heads to meters.
data(wolfcamp)
data(wolfcamp)
An object of the class
"geodata"
, which is list with two components:
coords
the coordinates of the data locations. The distance are given in kilometers.
data
values of the piezometric head. The unit is heads to meters.
Harper, W.V and Furr, J.M. (1986) Geostatistical analysis of potentiometric data in the Wolfcamp Aquifer of the Palo Duro Basin, Texas. Technical Report BMI/ONWI-587, Bettelle Memorial Institute, Columbus, OH.
Cressie, N.A.C (1993) Statistics for Spatial Data. New York: Wiley.
Papritz, A. and Moyeed, R. (2001) Parameter uncertainty in spatial prediction: checking its importance by cross-validating the Wolfcamp and Rongelap data sets. GeoENV 2000: Geostatistical for Environmental Applications. Ed. P. Monestiez, D. Allard, R. Froidevaux. Kluwer.
summary(wolfcamp) plot(wolfcamp)
summary(wolfcamp) plot(wolfcamp)
These functions are wrappers for some (but not all)
the C functions
included in the geoR package.
Typically the C code is directly called from the geoR
functions but these functions allows independent calls.
diffpairs(coords, data) loccoords(coords, locations) .diagquadraticformXAX(X, lowerA, diagA) .bilinearformXAY(X, lowerA, diagA, Y) .corr.diaglowertri(coords, cov.model, phi, kappa) .Ccor.spatial(x, phi, kappa, cov.model)
diffpairs(coords, data) loccoords(coords, locations) .diagquadraticformXAX(X, lowerA, diagA) .bilinearformXAY(X, lowerA, diagA, Y) .corr.diaglowertri(coords, cov.model, phi, kappa) .Ccor.spatial(x, phi, kappa, cov.model)
coords |
an |
data |
an vector with the data values. |
locations |
an |
lowerA |
a vector with the diagonal terms of the symmetric matrix A. |
diagA |
a vector with the diagonal terms of the symmetric matrix A. |
X |
a matrix with conforming dimensions. |
Y |
a matrix with conforming dimensions. |
cov.model |
covariance model, see |
phi |
numerical value of the correlation function parameter phi. |
kappa |
numerical value of the correlation function parameter kappa. |
x |
a vector of distances. |
The outputs for the different functions are:
diffpairs |
returns a list with elements |
loccoords |
returns a |
diagquadraticformXAX |
returns a vector with the diagonal term of the
quadratic form |
bilinearformXAY |
returns a vector or a matrix with the terms of the
quadratic form |
corr.diaglowertri |
returns the lower triangle of the correlation matrix, including the diagonal. |
Ccor.spatial |
returns a vector of values of spatial correlations. |
Paulo Justiniano Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
Soil density and measures of the water retention curve obtained at different pressures on a regular grid with 10x25 points spaced by 5 meters.
data(wrc)
data(wrc)
A data frame with 250 observations on the following 11 variables.
CoordX
a numeric vector with the X coordinates of the samples.
CoordY
a numeric vector with the Y coordinate of the samples.
Densidade
a numeric vector, soil density
Pr5
a numeric vector, water content at a pressure of 5
mca – Pa (atm)
Pr10
a numeric vector, water content at a pressure of
10 mca – Pa (atm)
Pr60
a numeric vector, water content at a pressure of 60 mca – Pa (atm)
Pr100
a numeric vector, water content at a pressure of 100 mca – Pa (atm)
Pr306
a numeric vector, water content at a pressure of 306 mca – Pa (atm)
Pr816
a numeric vector, water content at a pressure of 816 mca – Pa (atm)
Pr3060
a numeric vector, water content at a pressure of 3060 mca – Pa (atm)
Pr15300
a numeric vector, water content at a pressure of 15300 mca – Pa (atm)
Uniformity trial with 250 undisturbed soil samples collected at 25cm
soil depth of spacing of 5 meters, resulting on a regular grid of
sampling points.
For each sampling point there are measurents of the soil density and
water content obtained at eight pressures: 5, 10, 60, 100, 306, 816,
3060 and 15300 meters of column of water (mca), corresponding to
,
,
,
,
,
,
,
Pa.
The experiment aimed to use the water contents of the samples to estimate the water retention curve at the 250 data points.
See also the data-set soil250
with soil chemistry properties measured at the same points.
MORAES, S.O. (1991) Heterogeneidade hidráulica de uma terra roxa estruturada. PhD Thesis. ESALQ/USP.
MORAES, S. O. ; LIBARDI, P. L. ; REICHARDT, K. (1993) Problemas metodológicos na obtenção da curva de retenção de água pelo solo. Scientia Agricola, Piracicaba, v. 50, n. 3, p. 383-392.
MORAES, S. O. ; LIBARDI, P. L. ; REICHARDT, K. ; BACCHI, O. O. S. (1993) Heterogeneidade dos pontos experimentais de curvas de retenção da água do solo.. Scientia Agricola, Piracicaba, v. 50, n. 3, p. 393-402.
MORAES, S. O. ; LIBARDI, P. L. (1993) Variabilidade da água disponível em uma terra roxa estruturada latossólica. Scientia Agricola, Piracicaba, v. 50, n. 3, p. 393-402, 1993.
pr100 <- as.geodata(wrc, data.col=7) summary(pr100) plot(pr100)
pr100 <- as.geodata(wrc, data.col=7) summary(pr100) plot(pr100)
A function to perform model validation by comparing observed and values predicted by kriging. Options include: (i) leaving-one-out cross-validation where each data location is removed from the data set and the variable at this location is predicted using the remaining locations, for a given model. This can be computed for all or a subset of the data locations; (ii) external validation can be performed by using validation locations other than data locations.
xvalid(geodata, coords = geodata$coords, data = geodata$data, model, reestimate = FALSE, variog.obj = NULL, output.reestimate = FALSE, locations.xvalid = "all", data.xvalid = NULL, messages, ...)
xvalid(geodata, coords = geodata$coords, data = geodata$data, model, reestimate = FALSE, variog.obj = NULL, output.reestimate = FALSE, locations.xvalid = "all", data.xvalid = NULL, messages, ...)
geodata |
a list containing element |
coords |
an |
data |
a vector or matrix with data values.
If a matrix is provided, each column is regarded as one variable or realization.
Defaults to |
model |
an object containing information on a fitted
model. Typically an output of |
reestimate |
logical. Indicates whether or not the model parameters should be re-estimated for each point removed from the data-set. |
variog.obj |
on object with the empirical variogram, typically an
output of the function |
output.reestimate |
logical. Only valid if |
locations.xvalid |
there are three possible specifications for
this argument: |
data.xvalid |
data values at the validation locations. Only used if the validation locations are other than the data locations. |
messages |
logical. Indicates whether status messages should be printed on the screen (or output device) while the function is running. |
... |
further arguments to the minimization functions used by
|
The cross-validation uses internally the function krige.conv
to predict at each location.
For models fitted by variofit
the
parameters ,
,
and
are always regarded as fixed when
reestimating the model.
See documentation of the function likfit
for further
details on the model specification and parameters.
An object of the class
"xvalid"
which is a list with the following components:
data |
the original data. |
predicted |
the values predicted by cross-validation. |
krige.var |
the cross-validation prediction variance. |
error |
the differences |
std.error |
the errors divided by the square root of the prediction variances. |
prob |
the cumulative probability at original value under a normal distribution with parameters given by the cross-validation results. |
A method for summary
returns summary statistics for the errors
and standard errors.
If reestimate = TRUE
and output = TRUE
additional
columns are added to the resulting data-frame with the
values of the re-estimated parameters.
Paulo J. Ribeiro Jr. [email protected],
Peter J. Diggle [email protected].
Further information on the package geoR can be found at:
http://www.leg.ufpr.br/geoR/.
plot.xvalid
for plotting of the results, likfit
,
variofit
for parameter estimation and
krige.conv
for the kriging method used for predictions.
# # Maximum likelihood estimation # s100.ml <- likfit(s100, ini = c(.5, .5), fix.nug = TRUE) # # Weighted least squares estimation # s100.var <- variog(s100, max.dist = 1) s100.wls <- variofit(s100.var, ini = c(.5, .5), fix.nug = TRUE) # # Now, performing cross-validation without reestimating the model # s100.xv.ml <- xvalid(s100, model = s100.ml) s100.xv.wls <- xvalid(s100, model = s100.wls) ## ## Plotting results ## par.ori <- par(no.readonly = TRUE) ## par(mfcol=c(5,2), mar=c(2.3,2.3,.5,.5), mgp=c(1.3, .6, 0)) plot(s100.xv.ml) par(mfcol=c(5,2)) plot(s100.xv.wls) ## par(par.ori) #
# # Maximum likelihood estimation # s100.ml <- likfit(s100, ini = c(.5, .5), fix.nug = TRUE) # # Weighted least squares estimation # s100.var <- variog(s100, max.dist = 1) s100.wls <- variofit(s100.var, ini = c(.5, .5), fix.nug = TRUE) # # Now, performing cross-validation without reestimating the model # s100.xv.ml <- xvalid(s100, model = s100.ml) s100.xv.wls <- xvalid(s100, model = s100.wls) ## ## Plotting results ## par.ori <- par(no.readonly = TRUE) ## par(mfcol=c(5,2), mar=c(2.3,2.3,.5,.5), mgp=c(1.3, .6, 0)) plot(s100.xv.ml) par(mfcol=c(5,2)) plot(s100.xv.wls) ## par(par.ori) #