This function combines some input arguments with defaults for other to create a list describing the LatticeKrig spatial model. A key to specifying the LatticeKrig spatial model is specifying the geometry, e.g. LKRectangle for a 2-d rectangular domain. Each geometry has some parameters that control the basic model setup and these are included through the ... arguments of this function. See the help for this argument below for some examples.
LKrigSetup(x = NULL, nlevel = NULL, alpha = NA, alphaObject =
NULL, nu = NULL, a.wght = NA, a.wghtObject = NULL, NC
= NULL, NC.buffer = NULL,delta = delta, normalize = TRUE,
normalizeMethod =
"exact", lambda = NA, tau = NA, sigma2 = NA, sigma2.object = NULL,
latticeInfo = NULL, basisInfo = NULL, LKGeometry =
"LKRectangle", distance.type = "Euclidean",
BasisFunction = "WendlandFunction", overlap = 2.5, V =
NULL, BasisType = "Radial", fixedFunction =
"LKrigDefaultFixedFunction", fixedFunctionArgs =
list(m = 2), collapseFixedEffect = FALSE, max.points =
NULL, mean.neighbor = 50, choleskyMemory = NULL,
verbose = FALSE, noCheck = FALSE, returnCall = FALSE,
dense = FALSE, ...)
LatticeKrigEasyDefaults(argList, nlevel, x)LKinfoUpdate(LKinfo, ... )
An object with class "LKinfo" and also the additional class given by LKGeometry. The required components are:
Number of levels
alpha parameters as a list that has nlevel components and possibly some attributes.
a.wght parameters as a list that has nlevel components and possibly some attributes.
nu parameter
A logical indicating whether to normalize.
A string that determines the method for normalization.
Value of lambda.
Value of tau.
Value for sigma2.
Value for sigma2.object.
A list with specific multi-resolution lattice information
All arguments passed in the call and any in in ...
A list with basis information.
The actual call used to create this object.
Argument supplied to the top level LatticeKrig function.
A vector of length nlevel
with the relative
variances for the different multi-resolution levels.
For non-stationary models an object to be used with the predict function to give the alpha values at the process locations.Typically this is a list of "predict" objects. See nonstationaryModels for examples how to use this option.
This parameter controls the correlation range in the SAR
model. In most cases, a scalar value and for the 2-d model by default
greater than 4.
If a vector this can specify an anisotropic set of weights. To
specify a.wght parameters that are different for each level they
should be in the form of a list
of length nlevel
. E.g. a.wght = list( 4.5, 5, 10)
will specify different a.wghts for 3 different levels. The setup
function will
check that the values are in a valid range for a geometry and the
length of the list agrees with the number of levels.
The details of how this is connected to the covariance function
varies
based on the geometry. However, qualitatively this is related to a
range parameter. For the LKRectangle geometry and a stationary
model, at level k the center point has
weight 1 with the 4 nearest neighbors given weight
-1/a.wght[k]. In this case a.wght must be greater than 4 for the
fields to be
stationary and following Lindgren and Rue the range parameter is
approximately 1/sqrt(a.wght-4)
.
For non-stationary models an object to be used with the predict function to give the a.wght values at the lattice locations. See nonstationaryModels for examples how to used option.
A list with extra components the object used to describe the multi-resolution basis. Usually this will not be needed for standard models.
A character string indicating the type of basis function. Currently
this is either "Radial"
or "Tensor"
.
A list that will be used in the spam call to
do the Cholesky decomposition. See the memory
argument in
chol.spam
.
If FALSE the fixed part of the model is found separately for each replicated data set. If TRUE the estimate is polled across replicates.This is largely a modeling decision whether variation among the replicate fields is due to the spatial component or also include variation in the fixed effects across replicates -- guess they are not really fixed then!
A vector that will be used for the basis center spacings. This
is an alternative choice to NC
. Note that all the spacings need
to be specified as a vector with length nlevel
.
If FALSE sparse linear algebra is used for the computations . If TRUE the matrices are made "dense" (zeroes are filled in) and the ordinary Lapack functions are used for the linear algebra. This option is primarily for testing and timing sparse verses standard algorithms.
A text string indicate type distance to use between spatial locations when evaluating the basis functions. Default is "Euclidean". Other choices when locations are in degrees longitude and latitude are "Chordal" and "GreatCircle" with the default units being miles. See Details below how to change the radius that is used.
A text string that is the name of the function
used to find the fixed part of the spatial model based on the
locations. The default is a linear (m=2) polynomial in the
spatial coordinates. See LKrigDefaultFixedFunction
for more details.
Set this to NULL if you do not want to
include a fixed effect in the spatial model.
A list containing arguments to supply when evaluating the fixed function.
The "noise to signal ratio" or also known as the
smoothing parameter it is the parameter lambda =
tau^2/sigma2
. If specified then tau and sigma2 typically are
estimated in LKrig by maximum likelihood. If lambda is not
specified then it is set as lambda = tau^2/ sigma2
. Note
that to evaluate the spatial process model, e.g. using the
function LKrig.cov
, a value of lambda is not needed and
this argument can default to NA.
Part
or all of the object used to describe the Markov random field
lattice. In the standard cases this list is created in the
setup function and need not be specified. See
LKrigSetupLattice
for details. Note that the contents
of this list is concatenated to any additional components
supplied by LKrigSetupLattice
.
A text string that gives the names of the model geometry. The default is "LKrectangle" assuming the spatial domain is a rectangle. Other common choices are "LKInterval" (1 d problem ) and "LKBox" (for a 3d problem). See LKGeometry for more detials.
A list that has class "LKinfo".
The average number of nonzero points when each basis function is evaluated at a set of points points in the spatial domain.
This is a parameter for the nearest neighbor distance function that sets the maximum array size for the nonzero distances among points. e.g. with 100 points each with 20 nonzero neighbors max.points needs to be 2000 = 100*20. Specifically if the total number of nonzero values when each basis function is evaluated at all the spatial locations. The easier way to specify space is by using the mean.neighbor argument.
For regular grids of lattice points the maximum number of
lattice grid points for a spatial coordinate and at the coarsest level
of resolution. For a example, for a square region,
(and LKGeometry = "LKRectangle"
)
NC=5
results in a 5X5 = 25 lattice points at the first level.
Note that the default is that lattice points are also taken to have
the same spacing in every dimension. See the delta
argument as an
alternative way to specify the basis centers.
Number of extra lattice points added outside the
spatial domain
for regular grids of lattice points. This helps to reduce boundary
effects from the
SAR model. NC.buffer=5
and NC=5
for a square region
will result in
(5+ 2*5) X (5+ 2*5) = 225 lattice locations at the coarsest level
of resolution.
Note that this number by default is fixed for finer resolutions and
so does not
contribute as much to the total number of lattice points.
This option works for either NC
or delta
.
Number of levels in multi-resolution. Note that each subsequent level increases the number of basis functions within the spatial domain size by a factor of roughly 4. But not exactly 4!
If FALSE do not make any checks on the consistency of the different parts of the final LKinfo object. e.q. values of a.wght within the range of a stationary Markov random field.
If TRUE the basis functions will be normalized to
give a marginal variance of one for each level of
multi-resolution. (Normalizing by levels makes it easier to
interpret the alpha
weights.)
Options are "exact"
, "exactKronecker"
,
"fftInterpolation"
, and "both"
. The "exact"
" option
calculates the exact marginal variance but slowly, while
"exactKronecker"
can offer a speedup in scenarios with a constant
a.wght and rectangular geometry. "fftInterpolation"
offers
an ever faster but approximate calculation, and can only be used in
situations where the number of locations significantly exceeds th
e number of basis functions. The "both"
method
automatically uses the FFT approximation for lower levels, and switches
to the Kronecker method
when the number of basis functions grows to be too large for the
approximate method. See
LKrigNormalizeBasis
for more detail.
A
smoothness parameter that controls relative sizes of
alpha
. Currently this parameter only makes sense for
the 2D rectangular domain (LKRectangle)
Controls the overlap among the radial basis functions and
should be in units of the lattice spacing. For the rectangular
case the default of 2.5 means that the support of the Wendland
basis function will overlap 2.5 lattice units in each
direction. See LKrig.basis
for how overlap adjusts
scaling in the basis function formula.
A scalar, the sill or marginal variance of the process.
Text string giving the 1-d form for basis function.
A prediction object to specify part of the
marginal variance for the process. Specifically the form is
VAR(g(x1))= sigma2*h(x1) Calling predict(sigma2.object,x1)
should return a vector with the values of h at the (arbitrary)
spatial locations in x1. If omitted assumed to be the
constant one -- the usual case.
If TRUE the call to LKrigSetup is also included as part of the LKinfo object.
The measurement error standard deviation. Also called the nugget variance in geostatistics.
See entry in LKrig
.
If TRUE print out intermediate information.
Spatial locations that define the spatial domain for prediction. This is only used to determine ranges of the grid for the basis functions so, for example, for a rectangular domain only two points are required that bound the rest of the data locations. E.g. x= rbind( c( 0,0), c(1,1)) will set the domain to be the unit square.
Specific arguments that will be included in the
setupArgs
list and also passed to
LKrigSetupLattice
. For LKinfoUpdate these specify the components
of LKinfo to update. For example for a rectangular domain (the default)
the argument NC
is needed to specify the initial lattice size
NC.buffer
sets the number of extra points included in the
lattice and defaults to 5. NC
for the LKSphere geometry
is the initial level of the
icosahedral grid.
Doug Nychka
Many of the functions within LKrigSetup are overloaded to
adapt to the LKGeometry
class. This makes it easy to add new
geometries or other models to the LatticeKrig framework. The
required components of this object (see below) outline how
the latticeKrig model is structured and what should be common
features independent of the geometry. The key components are:
basisInfo
used to specify the form of the basis functions (see LKrig.basis)
latticeInfo
that contains the information used to generate the
spatial autoregressive matrix on the lattice.
See (LKrigSetupLattice for the top level function that sets up the lattice.
a.wght
A component that specifies the weights in the SAR model. (See LKrigSetupAwght)
alpha
A component that gives the relative weights of the different
layers for a multiresolution model. (See
LKrigSetupAlpha.)
Also part of this flexibility is to use different distance functions
(metrics). See help on LKDistance
for the S4 method to
find the distance
and
LKDist for the lower level functions that actually do the work.
To change the radius used for the spherical distances one can add a Radius
attribute to the text string.
For example to use kilometers for great circle distance ( R approximately 6371)
dtype <- "GreatCircle"
attr( dtype, which="Radius") <- 6371
Now use distance.type = dtype
for the distance type argument.
The function LKrigEasyDefaults is used in the top level function LattticeKrig to make the logic of different default choices more readable and reduces the clutter in this function. Its main purpose is to find a reasonable choice for NC when this is not specified.
As example of how the computation is structured with the complete
LKinfo
object
LKrigSAR can be called to generate the sparse SAR matrix of the basis function coefficients at a given level of resolution:
B1<- LKrigSAR(LKinfo, Level=1)
The basis function matrix can be evaluated at a matrix of locations $x1
as
Phi<- LKrig.basis( x1,LKinfo)
The function LKinfoUpdate is more of a utility used for clarity that allows one to update the LKinfo object with particular components without having to recreate the entire object. This function is used in the MLE search when just values of alpha or a.wght are being varied.
data(ozone2)
# find the ranges of the data, this is the same as passing
# the entire set of observation locations and is more compact
sDomain<-apply( ozone2$lon.lat, 2,"range")
LKinfo0<- LKrigSetup( sDomain, NC=10, nlevel=2, alpha=c(1,.5),
a.wght = 5)
print( LKinfo0)
#Gigantic buffer added note extra basis functions.
LKinfo<- LKrigSetup( sDomain, NC=10, NC.buffer= 15, nlevel=2,
alpha=c(1,.5),a.wght = 5)
print( LKinfo)
LKinfo2<- LKinfoUpdate( LKinfo, a.wght=4.1, NC=12)
LKinfo3<- LKrigSetup( sDomain, NC=12, nlevel=2, alpha=c(1,.5),
a.wght=4.1)
# LKinfo2 and LKinfo3 should be the same.
Run the code above in your browser using DataLab