| Title: | Procedures for Gaussian and Non Gaussian Geostatistical (Large) Data Analysis |
|---|---|
| Description: | Functions for Gaussian and Non Gaussian (bivariate) spatial and spatio-temporal data analysis are provided for a) (fast) simulation of random fields, b) inference for random fields using standard likelihood and a likelihood approximation method called weighted composite likelihood based on pairs and b) prediction using (local) best linear unbiased prediction. Weighted composite likelihood can be very efficient for estimating massive datasets. Both regression and spatial (temporal) dependence analysis can be jointly performed. Flexible covariance models for spatial and spatial-temporal data on Euclidean domains and spheres are provided. There are also many useful functions for plotting and performing diagnostic analysis. Different non Gaussian random fields can be considered in the analysis. Among them, random fields with marginal distributions such as Skew-Gaussian, Student-t, Tukey-h, Sin-Arcsin, Two-piece, Weibull, Gamma, Log-Gaussian, Binomial, Negative Binomial and Poisson. See the URL for the papers associated with this package, as for instance, Bevilacqua and Gaetan (2015) <doi:10.1007/s11222-014-9460-6>, Bevilacqua et al. (2016) <doi:10.1007/s13253-016-0256-3>, Vallejos et al. (2020) <doi:10.1007/978-3-030-56681-4>, Bevilacqua et. al (2020) <doi:10.1002/env.2632>, Bevilacqua et. al (2021) <doi:10.1111/sjos.12447>, Bevilacqua et al. (2022) <doi:10.1016/j.jmva.2022.104949>, Morales-Navarrete et al. (2023) <doi:10.1080/01621459.2022.2140053>, and a large class of examples and tutorials. |
| Authors: | Moreno Bevilacqua [aut, cre, cph], Víctor Morales-Oñate [ctb], Francisco Cuevas-Pacheco [ctb], Christian Caamaño-Carrillo [ctb] |
| Maintainer: | Moreno Bevilacqua <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 2.2.4 |
| Built: | 2026-06-15 15:50:34 UTC |
| Source: | https://github.com/cran/GeoModels |
A numerical matrix of dimension containing longitude, latitude, and yearly total precipitation anomalies registered at 7,352 location sites in the USA.
data(anomalies)data(anomalies)
A numeric matrix with 7,252 rows and 3 columns:
Longitude
Latitude
Annual precipitation anomaly
Kaufman, C.G., Schervish, M.J., Nychka, D.W. (2008). Covariance tapering for likelihood-based estimation in large spatial data sets. Journal of the American Statistical Association, Theory & Methods, 103, 1545–1555.
Checks whether the correlation model is bivariate.
CheckBiv(numbermodel)CheckBiv(numbermodel)
numbermodel |
A numeric value; the number associated with a given correlation model. |
This function checks whether the correlation model is bivariate.
A logical value: TRUE if the correlation model is bivariate, and FALSE otherwise.
Moreno Bevilacqua [email protected]
https://sites.google.com/view/moreno-bevilacqua/home
Víctor Morales Oñate [email protected]
https://sites.google.com/site/moralesonatevictor/
Christian Caamaño-Carrillo [email protected]
https://www.researchgate.net/profile/Christian-Caamano
library(GeoModels) CheckBiv(CkCorrModel("Bi_matern_sep"))library(GeoModels) CheckBiv(CkCorrModel("Bi_matern_sep"))
Checks the validity and type of the specified distance.
CheckDistance(distance)CheckDistance(distance)
distance |
A character string indicating the type of distance.
Available options are: |
This function checks whether the specified distance type is valid.
An integer:
0 for Euclidean distance
1 for Geodesic distance
2 for Chordal distance
If the input is not recognized, the function returns NULL.
Moreno Bevilacqua [email protected]
https://sites.google.com/view/moreno-bevilacqua/home
Víctor Morales Oñate [email protected]
https://sites.google.com/site/moralesonatevictor/
Christian Caamaño-Carrillo [email protected]
https://www.researchgate.net/profile/Christian-Caamano
Subroutine called by InitParam. The procedure controls if a covariance model is valid only on the sphere.
CheckSph(numbermodel)CheckSph(numbermodel)
numbermodel |
Numeric; the code number for the covariance model. |
The function checks if a covariance is valid only on the sphere
Returns TRUE or FALSE
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
The procedure control if the correlation model is spacetime.
CheckST(numbermodel)CheckST(numbermodel)
numbermodel |
numeric; the number associated to a given correlation model. |
The function check if the correlation model is spacetime.
Returns TRUE or FALSE depending if the correlation model is spacetime or not.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
library(GeoModels) CheckST(CkCorrModel("gneiting"))library(GeoModels) CheckST(CkCorrModel("gneiting"))
The procedure controls if the correlation model inserted is correct.
CkCorrModel(corrmodel)CkCorrModel(corrmodel)
corrmodel |
String; the name of a correlation model, for the
description see |
The procedure controls if the correlation model is correct
Return a number associated to a given correlation model if the model is considered in the package. Otherwise return NULL.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
Subroutine called by the fitting procedures. The procedure controls the the validity of the input inserted by the users.
CkInput(coordx, coordy, coordz,coordt, coordx_dyn,corrmodel, data, distance, fcall, fixed, grid,likelihood, maxdist, maxtime, model, n, optimizer, param, radius, start, taper, tapsep, type, varest, weighted,copula,X)CkInput(coordx, coordy, coordz,coordt, coordx_dyn,corrmodel, data, distance, fcall, fixed, grid,likelihood, maxdist, maxtime, model, n, optimizer, param, radius, start, taper, tapsep, type, varest, weighted,copula,X)
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordz |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordt |
A numeric vector assigning 1-dimension of temporal coordinates. |
corrmodel |
String; the name of a correlation model, for the
description see |
coordx_dyn |
A list of |
data |
A numeric vector or a ( |
distance |
String; the name of the spatial distance. The default is |
fcall |
String; |
fixed |
A named list giving the values of the parameters that
will be considered as known values. The listed parameters for a
given correlation function will be not estimated, i.e. if
|
grid |
Logical; if |
likelihood |
String; the configuration of the composite
likelihood. |
maxdist |
Numeric; an optional positive value indicating the maximum spatial distance considered in the composite-likelihood computation. |
maxtime |
Numeric; an optional positive value indicating the maximum temporal lag separation in the composite-likelihood. |
radius |
Numeric; the radius of the sphere in the case of lon-lat coordinates. The default is 6371, the radius of the earth. |
model |
String; the density associated to the likelihood
objects. |
n |
Numeric; the number of trials in a binomial random fields.
Default is |
optimizer |
String; the optimization algorithm
(see |
param |
A numeric vector of parameters, needed only in
simulation. See |
start |
A named list with the initial values of the
parameters that are used by the numerical routines in maximization
procedure. |
taper |
String; the name of the tapered correlation function. |
tapsep |
Numeric; an optional value indicating the separabe parameter in the space time quasi taper (see Details). |
type |
String; the type of the likelihood objects. If |
varest |
Logical; if |
weighted |
Logical; if |
copula |
String; the type of copula. It can be "Clayton" or "Gaussian" |
X |
Numeric; Matrix of space-time covariates in the linear mean specification. |
Subroutine called by the fitting procedures. The procedure controls the the validity of the input inserted by the users.
A list with the type of error associated with the input parameters.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
Subroutine called by InitParam. The procedure controls the type of the composite-likelihood inserted by the users.
CkLikelihood(likelihood)CkLikelihood(likelihood)
likelihood |
String; the configuration of the composite
likelihood. |
The function controls the type of the composite-likelihood inserted by the users.
The function returns a numeric positive integer, or NULL if the likelihood is invalid.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
Subroutine called by InitParam.\
The procedure controls the type of random field inserted by the users.
CkModel(model)CkModel(model)
model |
String; the density associated with the likelihood
objects. |
The function controls the type of random field inserted by the users.
The function returns a numeric positive integer, or NULL if the model is invalid.
Moreno Bevilacqua [email protected] https://sites.google.com/view/moreno-bevilacqua/home \ Víctor Morales Oñate [email protected] https://sites.google.com/site/moralesonatevictor/ \ Christian Caamaño-Carrillo [email protected] https://www.researchgate.net/profile/Christian-Caamano
Subroutine called by InitParam. \
The procedure controls the type of likelihood objects inserted by the users.
CkType(type)CkType(type)
type |
String; the type of the likelihood objects. If |
The procedure checks the likelihood object.
The function returns a numeric positive integer, or NULL if the type of likelihood is invalid.
Moreno Bevilacqua [email protected] https://sites.google.com/view/moreno-bevilacqua/home \ Víctor Morales Oñate [email protected] https://sites.google.com/site/moralesonatevictor/ \ Christian Caamaño-Carrillo [email protected] https://www.researchgate.net/profile/Christian-Caamano
Subroutine called by GeoFit. The procedure estimates the model parameters by maximisation of the indipendence composite log-likelihood.
CompIndLik2(bivariate, coordx, coordy ,coordz,coordt, coordx_dyn, data, flagcorr, flagnuis, fixed,grid, lower, model, n, namescorr, namesnuis, namesparam, numparam, optimizer, onlyvar, param, spacetime, type, upper, namesupper, varest, ns, X, sensitivity,copula,MM,score)CompIndLik2(bivariate, coordx, coordy ,coordz,coordt, coordx_dyn, data, flagcorr, flagnuis, fixed,grid, lower, model, n, namescorr, namesnuis, namesparam, numparam, optimizer, onlyvar, param, spacetime, type, upper, namesupper, varest, ns, X, sensitivity,copula,MM,score)
bivariate |
Logical; if |
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordz |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordt |
A numeric vector assigning 1-dimension of
temporal coordinates. Optional argument, the default is |
coordx_dyn |
A list of |
data |
A numeric vector or a ( |
flagcorr |
A numeric vector of binary values denoting which paramerters of the correlation function will be estimated. |
flagnuis |
A numeric vector of binary values denoting which nuisance paramerters will be estimated. |
fixed |
A numeric vector of parameters that will be considered as known values. |
grid |
Logical; if |
lower |
An optional named list giving the values for the lower bound of the space parameter
when the optimizer is |
model |
Numeric; the id value of the density associated to the likelihood objects. |
n |
Numeric; number of trials in a binomial random fields. |
namescorr |
String; the names of the correlation parameters. |
namesnuis |
String; the names of the nuisance parameters. |
namesparam |
String; the names of the parameters to be maximised. |
numparam |
Numeric; the number of parameters to be maximised. |
optimizer |
String; the optimization algorithm
(see |
onlyvar |
Logical; if |
param |
A numeric vector of parameters values. |
spacetime |
Logical; if |
type |
String; the type of the likelihood objects. If |
upper |
An optional named list giving the values for the upper bound
of the space parameter when the optimizer is or |
namesupper |
String; the names of the upper limit of the parameters. |
varest |
Logical; if |
ns |
Numeric; Number of (dynamical) temporal instants. |
X |
Numeric; Matrix of space-time covariates in the linear mean specification. |
sensitivity |
Logical; if |
copula |
String; the type of copula. It can be "Clayton" or "Gaussian" |
MM |
Numeric;a non constant fixed mean |
score |
Logical; should score function be computed? |
Return a list from an optim call.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
Subroutine called by GeoFit.
The procedure estimates the model parameters by maximization of the
composite log-likelihood.
CompLik(copula, bivariate, coordx, coordy, coordz, coordt, coordx_dyn, corrmodel, data, distance, flagcorr, flagnuis, fixed, grid, likelihood, lower, model, n, namescorr, namesnuis, namesparam, numparam, numparamcorr, optimizer, onlyvar, param, spacetime, type, upper, varest, weigthed, ns, X, sensitivity, MM, aniso,score)CompLik(copula, bivariate, coordx, coordy, coordz, coordt, coordx_dyn, corrmodel, data, distance, flagcorr, flagnuis, fixed, grid, likelihood, lower, model, n, namescorr, namesnuis, namesparam, numparam, numparamcorr, optimizer, onlyvar, param, spacetime, type, upper, varest, weigthed, ns, X, sensitivity, MM, aniso,score)
copula |
String; the type of copula. It can be "Clayton" or "Gaussian". |
bivariate |
Logical; if |
coordx |
A numeric |
coordy |
A numeric vector giving one dimension of
spatial coordinates; optional, default is |
coordz |
A numeric vector giving one dimension of
spatial coordinates; optional, default is |
coordt |
A numeric vector giving one dimension of temporal coordinates;
optional, default is |
coordx_dyn |
A list of |
corrmodel |
Numeric; the ID of the correlation model. |
data |
A numeric vector, or a |
distance |
String; the name of the spatial distance.
Default is |
flagcorr |
Numeric vector of binary values indicating which parameters of the correlation function will be estimated. |
flagnuis |
Numeric vector of binary values indicating which nuisance parameters will be estimated. |
fixed |
Numeric vector of parameters considered as known values. |
grid |
Logical; if |
likelihood |
String; configuration of the composite likelihood (see |
lower |
Named list; optional lower bounds for parameters when using
optimizers |
model |
Numeric; ID of the density associated with the likelihood objects. |
n |
Numeric; number of trials in binomial random fields. |
namescorr |
Character vector; names of the correlation parameters. |
namesnuis |
Character vector; names of the nuisance parameters. |
namesparam |
Character vector; names of the parameters to be maximized. |
numparam |
Numeric; number of parameters to be maximized. |
numparamcorr |
Numeric; number of correlation parameters. |
optimizer |
String; optimization algorithm (see |
onlyvar |
Logical; if |
param |
Numeric vector of parameter values. |
spacetime |
Logical; if |
type |
String; type of likelihood object.
Default is |
upper |
Named list; optional upper bounds for parameters when using
optimizers |
varest |
Logical; if |
weigthed |
Logical; if |
ns |
Numeric; number of (dynamic) temporal instants. |
X |
Numeric; matrix of space-time covariates in the linear mean specification. |
sensitivity |
Logical; if |
MM |
Numeric; a non-constant fixed mean. |
aniso |
Logical; whether anisotropy should be considered. |
score |
Logical; should score function be computed? |
Subroutine called by GeoFit.
The procedure estimates model parameters by maximization of the composite log-likelihood.
Returns a list from an optim call.
Moreno Bevilacqua, [email protected], https://sites.google.com/view/moreno-bevilacqua/home,
Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/,
Christian Caamaño-Carrillo, [email protected], https://www.researchgate.net/profile/Christian-Caamano
Subroutine called by GeoFit. The procedure estimates the model parameters by maximisation of the composite log-likelihood.
CompLik2(copula,bivariate, coordx, coordy ,coordz,coordt, coordx_dyn,corrmodel, data, distance, flagcorr, flagnuis, fixed,grid,likelihood, lower, model, n, namescorr, namesnuis, namesparam, numparam, numparamcorr, optimizer, onlyvar, param, spacetime, type, upper, varest, weigthed, ns, X,sensitivity, colidx,rowidx,neighb,MM,aniso,score)CompLik2(copula,bivariate, coordx, coordy ,coordz,coordt, coordx_dyn,corrmodel, data, distance, flagcorr, flagnuis, fixed,grid,likelihood, lower, model, n, namescorr, namesnuis, namesparam, numparam, numparamcorr, optimizer, onlyvar, param, spacetime, type, upper, varest, weigthed, ns, X,sensitivity, colidx,rowidx,neighb,MM,aniso,score)
copula |
String; the type of copula. It can be "Clayton" or "Gaussian" |
bivariate |
Logical; if |
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordz |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordt |
A numeric vector assigning 1-dimension of
temporal coordinates. Optional argument, the default is |
coordx_dyn |
A list of |
corrmodel |
Numeric; the id of the correlation model. |
data |
A numeric vector or a ( |
distance |
String; the name of the spatial distance. The default is |
flagcorr |
A numeric vector of binary values denoting which paramerters of the correlation function will be estimated. |
flagnuis |
A numeric vector of binary values denoting which nuisance paramerters will be estimated. |
fixed |
A numeric vector of parameters that will be considered as known values. |
grid |
Logical; if |
likelihood |
String; the configuration of the
compositelikelihood, see |
lower |
An optional named list giving the values for the lower bound of the space parameter
when the optimizer is |
model |
Numeric; the id value of the density associated to the likelihood objects. |
n |
Numeric; number of trials in a binomial random fields. |
namescorr |
String; the names of the correlation parameters. |
namesnuis |
String; the names of the nuisance parameters. |
namesparam |
String; the names of the parameters to be maximised. |
numparam |
Numeric; the number of parameters to be maximised. |
numparamcorr |
Numeric; the number of correlation parameters. |
optimizer |
String; the optimization algorithm
(see |
onlyvar |
Logical; if |
param |
A numeric vector of parameters' values. |
spacetime |
Logical; if |
type |
String; the type of the likelihood objects. If |
upper |
An optional named list giving the values for the upper bound
of the space parameter when the optimizer is or |
varest |
Logical; if |
weigthed |
Logical; if |
ns |
Numeric; Number of (dynamical) temporal instants. |
X |
Numeric; Matrix of space-time covariates in the linear mean specification. |
sensitivity |
Logical; if |
colidx |
Numeric; Vector of indexes for spatial distances. |
rowidx |
Numeric; Vector of indexes for spatial distances. |
neighb |
Numeric; an optional positive integer indicating the order of neighborhood location. |
MM |
Numeric;a non constant fixed mean |
aniso |
Logical; should anisotropy be considered? |
score |
Logical; should score function be computed? |
Return a list from an optim call.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
Subroutine called by InitParam and other procedures. The procedure returns a list with the parameters of a given correlation model.
CorrelationPar(corrmodel)CorrelationPar(corrmodel)
corrmodel |
Integer; an integer associated to a given correlation model. |
The function return a list with the Parameters of a Correlation Model
Return a vector string of correlation parameters.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
The procedure returns a list with the names of the parameters of a given correlation model.
CorrParam(corrmodel)CorrParam(corrmodel)
corrmodel |
String: the name associated to a given correlation model. |
The function return a list with the Parameters of a Correlation Model
Return a vector string of correlation parameters.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
require(GeoModels) ################################################################ ### ### Example 1. Parameters of the Matern model ### ############################################################### CorrParam("Matern") ################################################################ ### ### Example 2. Parameters of the Generalized Wendland model ### ############################################################### CorrParam("GenWend") ################################################################ ### ### Example 3. Parameters of the Generalized Cauchy model ### ############################################################### CorrParam("GenCauchy") ################################################################ ### ### Example 4. Parameters of the space time Gneiting model ### ############################################################### CorrParam("Gneiting") ################################################################ ### ### Example 5. Parameters of the bi-Matern separable model. ### Note that in the bivariate case variance paramters are ### included ############################################################### CorrParam("Bi_Matern_sep")require(GeoModels) ################################################################ ### ### Example 1. Parameters of the Matern model ### ############################################################### CorrParam("Matern") ################################################################ ### ### Example 2. Parameters of the Generalized Wendland model ### ############################################################### CorrParam("GenWend") ################################################################ ### ### Example 3. Parameters of the Generalized Cauchy model ### ############################################################### CorrParam("GenCauchy") ################################################################ ### ### Example 4. Parameters of the space time Gneiting model ### ############################################################### CorrParam("Gneiting") ################################################################ ### ### Example 5. Parameters of the bi-Matern separable model. ### Note that in the bivariate case variance paramters are ### included ############################################################### CorrParam("Bi_Matern_sep")
Computes the correlations f for a random field transformed via the sinh-arcsinh (SAS) distribution. This transformation introduces flexible skewness and tail behavior to an underlying Gaussian field. The resulting correlation is derived via an infinite Hermite expansion, as described in Equation (16) of Blasi et al. (2022).
corrsas(corr, skew, tail, max_coeff = NULL)corrsas(corr, skew, tail, max_coeff = NULL)
corr |
A numeric vector of correlation values of the underlying standard Gaussian random field. |
skew |
A numeric value representing the skewness parameter |
tail |
A positive numeric value representing the tailweight parameter |
max_coeff |
Optional integer. The maximum number of Hermite coefficients used in the infinite series expansion. If |
The correlation of the sinh-arcsinh transformed field is computed as:
where is the correlation function of the underlying Gaussian field and are Hermite coefficients depending on the skewness and tail parameters. This series is truncated at max_coeff terms for computational feasibility.
See Equation (16) in Blasi et al. (2022) for the full derivation.
A numeric vector of adjusted correlation values corresponding to the SAS-transformed process.
Blasi, F., Caamaño-Carrillo, C., Bevilacqua, M., Furrer, R. (2022). A selective view of climatological data and likelihood estimation. Spatial Statistics, 50, 100596. doi:10.1016/j.spasta.2022.100596
# Example usage: rho <- seq(0, 1, length.out = 50) rho_sas <- corrsas(rho, skew = 0.5, tail = 0.8, max_coeff = 20) plot(rho, rho_sas, type = "l", main = "SAS Correlation", xlab = "Original Correlation", ylab = "Transformed Correlation")# Example usage: rho <- seq(0, 1, length.out = 50) rho_sas <- corrsas(rho, skew = 0.5, tail = 0.8, max_coeff = 20) plot(rho, rho_sas, type = "l", main = "SAS Correlation", xlab = "Original Correlation", ylab = "Transformed Correlation")
Transforms or back-transforms a set of coordinates according to the geometric anisotropy parameters.
GeoAniso(coords, anisopars=c(0,1), inverse = FALSE)GeoAniso(coords, anisopars=c(0,1), inverse = FALSE)
coords |
An n x 2 matrix with the coordinates to be transformed. |
anisopars |
A bivariate vector with the the anisotropy angle and the anisotropy ratio, respectively. The angle must be given in radians in [0,pi] and the anisotropy ratio must be greater or equal than 1. |
inverse |
Logical: Default to FALSE. If TRUE the reverse transformation is performed. |
Geometric anisotropy is defined by a linear tranformation from the anisotropic space to the isotropic space that is
where X is a matrix with original coordinates (anisotropic space), and Y is a matrix with transformed coordinates (isotropic space).
Here R is a rotation matrix with associated anisotropy angle parameter (in ) and a is a shrinking matrix with associated anisotropy ratio
parameter (greeater or equal than one).
The two parameters are specified in the anisopars argument as a bivariate numeric vector. The case corresponds to the isotropic case.
Returns a matrix of transformed coordinates
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
The function computes the correlations of a spatial (or spatio-temporal or bivariate spatial) Gaussian or non Gaussian randomm field for a given correlation model and a set of spatial (temporal) distances.
GeoCorrFct(x,t=NULL,corrmodel, model="Gaussian", distance="Eucl", param, radius=6371,n=1, covariance=FALSE,variogram=FALSE)GeoCorrFct(x,t=NULL,corrmodel, model="Gaussian", distance="Eucl", param, radius=6371,n=1, covariance=FALSE,variogram=FALSE)
x |
A set of spatial distances. |
t |
A set of (optional) temporal distances. |
corrmodel |
String; the name of a correlation model, for the
description see |
model |
String; the type of RF. See |
distance |
String; the name of the spatial distance. The default
is |
param |
A list of parameter values required for the covariance model. |
radius |
Numeric; a value indicating the radius of the sphere when using covariance models valid using the great circle distance. Default value is the radius of the earth in Km (i.e. 6371) |
n |
Numeric; the number of trials in a (negative) binomial random fields.
Default is |
covariance |
Logic; if TRUE then the covariance is returned. Default is FALSE |
variogram |
Logic; if FALSE then the covariance/correlation is returned. Otherwise the associated semivariogram is returned |
Returns correlations or covariances values associated to a given parametric spatial and temporal correlation models.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian, Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
library(GeoModels) ################################################################ ### ### Example 1. Covariance of a Gaussian random field with underlying ### Matern correlation model with nugget ### ############################################################### # Define the spatial distances x = seq(0,1,0.002) # Correlation Parameters for Matern model CorrParam("Matern") NuisParam("Gaussian") # Matern Parameters param=list(sill=2,smooth=0.5,scale=0.2/3,nugget=0.2,mean=0) cc= GeoCorrFct(x=x, corrmodel="Matern", covariance=TRUE, param=param,model="Gaussian") plot(cc,ylab="Corr",lwd=2,main="Matern correlation",type="l") ################################################################ ### ### Example 2. Covariance of a Gaussian random field with underlying ### Generalized Wendland-Matern correlation model ### ############################################################### CorrParam("GenWend_Matern") NuisParam("Gaussian") # GenWend Matern Parameters param=list(sill=2,smooth=1,scale=0.1,nugget=0,power2=1/4,mean=0) cc= GeoCorrFct(x=x, corrmodel="GenWend_Matern", param=param,model="Gaussian",covariance=FALSE) plot(cc,ylab="Cov",lwd=2,,main="GenWend covariance",type="l") ################################################################ ### ### Example 3. Semivariogram of a Tukeyh random field with underlying ### Generalized Wendland correlation model ### ############################################################### CorrParam("GenWend") NuisParam("Tukeyh") x = seq(0,1,0.005) param=list(sill=1,smooth=1,scale=0.5,nugget=0,power2=5,tail=0.1,mean=0) cc= GeoCorrFct(x=x, corrmodel="GenWend", param=param,model="Tukeyh",variogram=TRUE) plot(cc,ylab="Corr",lwd=2,main="Tukey semivariogram",type="l") ################################################################ ### ### Example 4. Semi-Variogram of a LoggGaussian random field with underlying ### Kummer correlation model ### ############################################################### CorrParam("Kummer") NuisParam("LogGaussian") # GenWend Matern Parameters param=list(smooth=1,sill=0.5,scale=0.1,nugget=0,power2=1,mean=0) cc= GeoCorrFct(x=x, corrmodel="Kummer", param=param,model="LogGaussian", ,covariance=TRUE,variogram=TRUE) plot(cc,ylab="Semivario",lwd=2, main="LogGaussian semivariogram",type="l") ################################################################ ### ### Example 5. Covariance of Poisson random field with underlying ### Matern correlation model ### ############################################################### CorrParam("Matern") NuisParam("Poisson") x = seq(0,1,0.005) param=list(scale=0.6/3,nugget=0,smooth=0.5,mean=2) cc= GeoCorrFct(x=x, corrmodel="Matern", param=param,model="Poisson",covariance=TRUE) plot(cc,ylab="Cov",lwd=2, main="Poisson covariance",type="l") ################################################################ ### ### Example 6. Space time semivariogram of a Gaussian random field ### with separable Matern correlation model ### ############################################################### ## spatial and temporal distances h<-seq(0,3,by=0.04) times<-seq(0,3,by=0.04) # Correlation Parameters for the space time separable Matern model CorrParam("Matern") NuisParam("Gaussian") # Matern Parameters param=list(sill=1,scale_s=0.6/3,scale_t=0.5,nugget=0,mean=0,smooth_s=1.5,smooth_t=0.5) cc= GeoCorrFct(x=h,t=times,corrmodel="Matern_Matern", param=param, model="Gaussian",variogram=TRUE) plot(cc,lwd=2,type="l") ################################################################ ### ### Example 7. Correlation of a bivariate Gaussian random field ### with underlying separable bivariate Matern correlation model ### ############################################################### # Define the spatial distances x = seq(0,1,0.005) #Correlation Parameters for the bivariate sep Matern model CorrParam("Bi_Matern") #Matern Parameters param=list(sill_1=1,sill_2=1,smooth_1=0.5,smooth_2=1,smooth_12=0.75, scale_1=0.2/3, scale_2=0.2/3, scale_12=0.2/3, mean_1=0,mean_2=0,nugget_1=0,nugget_2=0,pcol=-0.2) cc= GeoCorrFct(x=x, corrmodel="Bi_Matern", param=param,model="Gaussian") plot(cc,ylab="corr",lwd=2,type="l")library(GeoModels) ################################################################ ### ### Example 1. Covariance of a Gaussian random field with underlying ### Matern correlation model with nugget ### ############################################################### # Define the spatial distances x = seq(0,1,0.002) # Correlation Parameters for Matern model CorrParam("Matern") NuisParam("Gaussian") # Matern Parameters param=list(sill=2,smooth=0.5,scale=0.2/3,nugget=0.2,mean=0) cc= GeoCorrFct(x=x, corrmodel="Matern", covariance=TRUE, param=param,model="Gaussian") plot(cc,ylab="Corr",lwd=2,main="Matern correlation",type="l") ################################################################ ### ### Example 2. Covariance of a Gaussian random field with underlying ### Generalized Wendland-Matern correlation model ### ############################################################### CorrParam("GenWend_Matern") NuisParam("Gaussian") # GenWend Matern Parameters param=list(sill=2,smooth=1,scale=0.1,nugget=0,power2=1/4,mean=0) cc= GeoCorrFct(x=x, corrmodel="GenWend_Matern", param=param,model="Gaussian",covariance=FALSE) plot(cc,ylab="Cov",lwd=2,,main="GenWend covariance",type="l") ################################################################ ### ### Example 3. Semivariogram of a Tukeyh random field with underlying ### Generalized Wendland correlation model ### ############################################################### CorrParam("GenWend") NuisParam("Tukeyh") x = seq(0,1,0.005) param=list(sill=1,smooth=1,scale=0.5,nugget=0,power2=5,tail=0.1,mean=0) cc= GeoCorrFct(x=x, corrmodel="GenWend", param=param,model="Tukeyh",variogram=TRUE) plot(cc,ylab="Corr",lwd=2,main="Tukey semivariogram",type="l") ################################################################ ### ### Example 4. Semi-Variogram of a LoggGaussian random field with underlying ### Kummer correlation model ### ############################################################### CorrParam("Kummer") NuisParam("LogGaussian") # GenWend Matern Parameters param=list(smooth=1,sill=0.5,scale=0.1,nugget=0,power2=1,mean=0) cc= GeoCorrFct(x=x, corrmodel="Kummer", param=param,model="LogGaussian", ,covariance=TRUE,variogram=TRUE) plot(cc,ylab="Semivario",lwd=2, main="LogGaussian semivariogram",type="l") ################################################################ ### ### Example 5. Covariance of Poisson random field with underlying ### Matern correlation model ### ############################################################### CorrParam("Matern") NuisParam("Poisson") x = seq(0,1,0.005) param=list(scale=0.6/3,nugget=0,smooth=0.5,mean=2) cc= GeoCorrFct(x=x, corrmodel="Matern", param=param,model="Poisson",covariance=TRUE) plot(cc,ylab="Cov",lwd=2, main="Poisson covariance",type="l") ################################################################ ### ### Example 6. Space time semivariogram of a Gaussian random field ### with separable Matern correlation model ### ############################################################### ## spatial and temporal distances h<-seq(0,3,by=0.04) times<-seq(0,3,by=0.04) # Correlation Parameters for the space time separable Matern model CorrParam("Matern") NuisParam("Gaussian") # Matern Parameters param=list(sill=1,scale_s=0.6/3,scale_t=0.5,nugget=0,mean=0,smooth_s=1.5,smooth_t=0.5) cc= GeoCorrFct(x=h,t=times,corrmodel="Matern_Matern", param=param, model="Gaussian",variogram=TRUE) plot(cc,lwd=2,type="l") ################################################################ ### ### Example 7. Correlation of a bivariate Gaussian random field ### with underlying separable bivariate Matern correlation model ### ############################################################### # Define the spatial distances x = seq(0,1,0.005) #Correlation Parameters for the bivariate sep Matern model CorrParam("Bi_Matern") #Matern Parameters param=list(sill_1=1,sill_2=1,smooth_1=0.5,smooth_2=1,smooth_12=0.75, scale_1=0.2/3, scale_2=0.2/3, scale_12=0.2/3, mean_1=0,mean_2=0,nugget_1=0,nugget_2=0,pcol=-0.2) cc= GeoCorrFct(x=x, corrmodel="Bi_Matern", param=param,model="Gaussian") plot(cc,ylab="corr",lwd=2,type="l")
The function computes the correlations of a spatial or spatio-temporal or a bivariate spatial Gaussian or non Gaussian copula randomm field with a given covariance model and a set of spatial (temporal) distances.
GeoCorrFct_Cop(x,t=NULL,corrmodel, model="Gaussian",copula="Gaussian", distance="Eucl", param, radius=6371, n=1,covariance=FALSE,variogram=FALSE)GeoCorrFct_Cop(x,t=NULL,corrmodel, model="Gaussian",copula="Gaussian", distance="Eucl", param, radius=6371, n=1,covariance=FALSE,variogram=FALSE)
x |
A set of spatial distances. |
t |
A set of (optional) temporal distances. |
corrmodel |
String; the name of a correlation model, for the description see the Section Details. |
model |
String; the type of RF. See |
copula |
String; the type of copula. The two options are Gaussian and Clayton. |
distance |
String; the name of the spatial distance. The default
is |
param |
A list of parameter values required for the covariance model. |
radius |
Numeric; a value indicating the radius of the sphere when using covariance models valid using the great circle distance. Default value is the radius of the earth in Km (i.e. 6371) |
n |
Numeric; the number of trials in a (negative) binomial random fields.
Default is |
covariance |
Logic; if TRUE then the covariance is returned. Default is FALSE |
variogram |
Logic; if FALSE then the covariance/coorelation is returned. Otherwise the associated semivariogram is returned |
Returns a vector of correlations or covariances values associated to a given parametric spatial and temporal correlation models.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
library(GeoModels) ################################################################ ### ### Example 1. Correlation of a (mean reparametrized) beta random field with underlying ### Matern correlation model using Gaussian and Clayton copulas ### ############################################################### # Define the spatial distances x = seq(0,0.4,0.01) # Correlation Parameters for Matern model CorrParam("Matern") NuisParam("Beta2") # corr Gaussian copula param=list(smooth=0.5,sill=1,scale=0.2/3,nugget=0,mean=0,min=0,max=1,shape=0.5) corr1= GeoCorrFct_Cop(x=x, corrmodel="Matern", param=param,copula="Gaussian",model="Beta2") plot(corr1,ylab="corr",main="Gauss copula correlation",lwd=2) # corr Clayton copula param=list(smooth=0.5,sill=1,scale=0.2/3,nugget=0,mean=0,min=0,max=1,shape=0.5,nu=2) corr2= GeoCorrFct_Cop(x=x, corrmodel="Matern", param=param,copula="Clayton",model="Beta2") lines(x,corr2$corr,ylim=c(0,1),lty=2) plot(corr1,ylab="corr",main="Clayton copula correlation",lwd=2)library(GeoModels) ################################################################ ### ### Example 1. Correlation of a (mean reparametrized) beta random field with underlying ### Matern correlation model using Gaussian and Clayton copulas ### ############################################################### # Define the spatial distances x = seq(0,0.4,0.01) # Correlation Parameters for Matern model CorrParam("Matern") NuisParam("Beta2") # corr Gaussian copula param=list(smooth=0.5,sill=1,scale=0.2/3,nugget=0,mean=0,min=0,max=1,shape=0.5) corr1= GeoCorrFct_Cop(x=x, corrmodel="Matern", param=param,copula="Gaussian",model="Beta2") plot(corr1,ylab="corr",main="Gauss copula correlation",lwd=2) # corr Clayton copula param=list(smooth=0.5,sill=1,scale=0.2/3,nugget=0,mean=0,min=0,max=1,shape=0.5,nu=2) corr2= GeoCorrFct_Cop(x=x, corrmodel="Matern", param=param,copula="Clayton",model="Beta2") lines(x,corr2$corr,ylim=c(0,1),lty=2) plot(corr1,ylab="corr",main="Clayton copula correlation",lwd=2)
The procedure computes and plots estimated covariance or semivariogram models of a Gaussian or a non Gaussian spatial (temporal or bivariate spatial) random field. It allows to add the empirical estimates in order to compare them with the fitted model.
GeoCovariogram(fitted, distance="Eucl",answer.cov=FALSE, answer.vario=FALSE, answer.range=FALSE, fix.lags=NULL, fix.lagt=NULL, show.cov=FALSE, show.vario=TRUE, show.range=FALSE, add.cov=FALSE, add.vario=FALSE, pract.range=95, vario, invisible=FALSE, ...)GeoCovariogram(fitted, distance="Eucl",answer.cov=FALSE, answer.vario=FALSE, answer.range=FALSE, fix.lags=NULL, fix.lagt=NULL, show.cov=FALSE, show.vario=TRUE, show.range=FALSE, add.cov=FALSE, add.vario=FALSE, pract.range=95, vario, invisible=FALSE, ...)
fitted |
A fitted object obtained from the
|
distance |
String; the name of the spatial distance. The default
is |
answer.cov |
Logical; if |
answer.vario |
Logical; if |
answer.range |
Logical; if |
fix.lags |
Integer; a positive value denoting the spatial lag to consider for the plot of the temporal profile. |
fix.lagt |
Integer; a positive value denoting the temporal lag to consider for the plot of the spatial profile. |
show.cov |
Logical; if |
show.vario |
Logical; if |
show.range |
Logical; if |
add.cov |
Logical; if |
add.vario |
Logical; if |
pract.range |
Numeric; the percent of the sill to be reached. |
vario |
A |
invisible |
Logical;If TRUE then a statistic the (sum of the squared diffeence between the empirical semivariogram and the estimated semivariogram) is computed. |
... |
other optional parameters which are passed to plot functions. |
The function computes the fitted variogram model
Produces a plot. No values are returned.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
Cressie, N. A. C. (1993) Statistics for Spatial Data. New York: Wiley.
Gaetan, C. and Guyon, X. (2010) Spatial Statistics and Modelling. Spring Verlang, New York.
library(GeoModels) library(scatterplot3d) ################################################################ ### ### Example 1. Plot of fitted covariance and fitted ### and empirical semivariogram from a Gaussian RF ### with Matern correlation. ### ############################################################### set.seed(21) # Set the coordinates of the points: x = runif(300, 0, 1) y = runif(300, 0, 1) coords=cbind(x,y) # Set the model's parameters: corrmodel = "Matern" model = "Gaussian" mean = 0 sill = 1 nugget = 0 scale = 0.2/3 smooth=0.5 param=list(mean=mean,sill=sill, nugget=nugget, scale=scale, smooth=smooth) # Simulation of the Gaussian random field: data = GeoSim(coordx=coords, corrmodel=corrmodel, model=model,param=param)$data I=Inf start=list(mean=0,scale=scale,sill=sill) lower=list(mean=-I,scale=0,sill=0) upper=list(mean= I,scale=I,sill=I) fixed=list(nugget=nugget,smooth=smooth) # Maximum composite-likelihood fitting of the Gaussian random field: fit = GeoFit(data=data,coordx=coords, corrmodel=corrmodel,model=model, likelihood="Marginal",type='Pairwise',start=start, lower=lower,upper=upper, optimizer="nlminb", fixed=fixed,neighb=3) # Empirical estimation of the variogram: vario = GeoVariogram(data=data,coordx=coords,maxdist=0.5) # Plot of covariance and variogram functions: GeoCovariogram(fit,show.vario=TRUE, vario=vario,pch=20) ################################################################ ### ### Example 2. Plot of fitted covariance and fitted ### and empirical semivariogram from a Bernoulli ### RF with Genwend correlation. ### ############################################################### set.seed(2111) model="Binomial";n=1 # Set the coordinates of the points: x = runif(500, 0, 1) y = runif(500, 0, 1) coords=cbind(x,y) # Set the model's parameters: corrmodel = "GenWend" mean = 0 nugget = 0 scale = 0.2 smooth=0 power=4 param=list(mean=mean, nugget=nugget, scale=scale,smooth=0,power2=4) # Simulation of the Gaussian RF: data = GeoSim(coordx=coords, corrmodel=corrmodel, model=model,param=param,n=n)$data start=list(mean=0,scale=scale) fixed=list(nugget=nugget,power2=4,smooth=0) # Maximum composite-likelihood fitting of the Binomial random field: fit = GeoFit(data,coordx=coords, corrmodel=corrmodel,model=model, likelihood="Marginal",type='Pairwise',start=start,n=n, optimizer="BFGS", fixed=fixed,neighb=4) # Empirical estimation of the variogram: vario = GeoVariogram(data,coordx=coords,maxdist=0.5) # Plot of covariance and variogram functions: GeoCovariogram(fit, show.vario=TRUE, vario=vario,pch=20,ylim=c(0,0.3)) ################################################################ ### ### Example 3. Plot of fitted covariance and fitted ### and empirical semivariogram from a Weibull RF ### with Wend0 correlation. ### ############################################################### set.seed(111) model="Weibull";shape=4 # Set the coordinates of the points: x = runif(700, 0, 1) y = runif(700, 0, 1) coords=cbind(x,y) # Set the model's parameters: corrmodel = "Wend0" mean = 0 nugget = 0 scale = 0.4 power2=4 param=list(mean=mean, nugget=nugget, scale=scale,shape=shape,power2=power2) # Simulation of the Gaussian RF: data = GeoSim(coordx=coords, corrmodel=corrmodel, model=model,param=param)$data start=list(mean=0,scale=scale,shape=shape) I=Inf lower=list(mean=-I,scale=0,shape=0) upper=list(mean= I,scale=I,shape=I) fixed=list(nugget=nugget,power2=power2) fit = GeoFit(data,coordx=coords, corrmodel=corrmodel,model=model, likelihood="Marginal",type='Pairwise',start=start, lower=lower,upper=upper, optimizer="nlminb", fixed=fixed,neighb=3) # Empirical estimation of the variogram: vario = GeoVariogram(data,coordx=coords,maxdist=0.5) # Plot of covariance and variogram functions: GeoCovariogram(fit, show.vario=TRUE, vario=vario,pch=20) ################################################################ ### ### Example 4. Plot of fitted and empirical semivariogram ### from a space time Gaussian random fields ### with double Matern correlation. ### ############################################################### set.seed(92) # Define the spatial-coordinates of the points: x = runif(50, 0, 1) y = runif(50, 0, 1) coords=cbind(x,y) # Define the temporal sequence: time = seq(0, 10, 1) param=list(mean=mean,nugget=nugget, smooth_s=0.5,smooth_t=0.5,scale_s=0.5/3,scale_t=2/2,sill=sill) # Simulation of the spatio-temporal Gaussian random field: data = GeoSim(coordx=coords, coordt=time, corrmodel="Matern_Matern",param=param)$data fixed=list(nugget=0, mean=0, smooth_s=0.5,smooth_t=0.5) start=list(scale_s=0.2, scale_t=0.5, sill=1) # Maximum composite-likelihood fitting of the space-time Gaussian random field: fit = GeoFit(data, coordx=coords, coordt=time, corrmodel="Matern_Matern", maxtime=1, neighb=3, likelihood="Marginal", type="Pairwise",fixed=fixed, start=start) # Empirical estimation of spatio-temporal covariance: vario = GeoVariogram(data,coordx=coords, coordt=time, maxtime=5,maxdist=0.5) # Plot of the fitted space-time variogram GeoCovariogram(fit,vario=vario,show.vario=TRUE) # Plot of covariance, variogram and spatio and temporal profiles: GeoCovariogram(fit,vario=vario,fix.lagt=1,fix.lags=1,show.vario=TRUE,pch=20) ################################################################ ### ### Example 5. Plot of fitted and empirical semivariogram ### from a bivariate Gaussian random fields ### with Matern correlation. ### ############################################################### set.seed(92) # Define the spatial-coordinates of the points: x <- runif(600, 0, 2) y <- runif(600, 0, 2) coords <- cbind(x,y) # Simulation of a bivariate spatial Gaussian RF: # with a Bivariate Matern set.seed(12) param=list(mean_1=4,mean_2=2,smooth_1=0.5,smooth_2=0.5,smooth_12=0.5, scale_1=0.12,scale_2=0.1,scale_12=0.15, sill_1=1,sill_2=1,nugget_1=0,nugget_2=0,pcol=-0.5) data <- GeoSim(coordx=coords,corrmodel="Bi_matern", param=param)$data # selecting fixed and estimated parameters fixed=list(mean_1=4,mean_2=2,nugget_1=0,nugget_2=0, smooth_1=0.5,smooth_2=0.5,smooth_12=0.5) start=list(sill_1=var(data[1,]),sill_2=var(data[2,]), scale_1=0.1,scale_2=0.1,scale_12=0.1, pcol=cor(data[1,],data[2,])) # Maximum marginal pairwise likelihood fitcl<- GeoFit(data=data, coordx=coords, corrmodel="Bi_Matern", likelihood="Marginal",type="Pairwise", optimizer="BFGS" , start=start,fixed=fixed, neighb=4) print(fitcl) # Empirical estimation of spatio-temporal covariance: vario = GeoVariogram(data,coordx=coords,maxdist=0.4,bivariate=TRUE) GeoCovariogram(fitcl,vario=vario,show.vario=TRUE,pch=20)library(GeoModels) library(scatterplot3d) ################################################################ ### ### Example 1. Plot of fitted covariance and fitted ### and empirical semivariogram from a Gaussian RF ### with Matern correlation. ### ############################################################### set.seed(21) # Set the coordinates of the points: x = runif(300, 0, 1) y = runif(300, 0, 1) coords=cbind(x,y) # Set the model's parameters: corrmodel = "Matern" model = "Gaussian" mean = 0 sill = 1 nugget = 0 scale = 0.2/3 smooth=0.5 param=list(mean=mean,sill=sill, nugget=nugget, scale=scale, smooth=smooth) # Simulation of the Gaussian random field: data = GeoSim(coordx=coords, corrmodel=corrmodel, model=model,param=param)$data I=Inf start=list(mean=0,scale=scale,sill=sill) lower=list(mean=-I,scale=0,sill=0) upper=list(mean= I,scale=I,sill=I) fixed=list(nugget=nugget,smooth=smooth) # Maximum composite-likelihood fitting of the Gaussian random field: fit = GeoFit(data=data,coordx=coords, corrmodel=corrmodel,model=model, likelihood="Marginal",type='Pairwise',start=start, lower=lower,upper=upper, optimizer="nlminb", fixed=fixed,neighb=3) # Empirical estimation of the variogram: vario = GeoVariogram(data=data,coordx=coords,maxdist=0.5) # Plot of covariance and variogram functions: GeoCovariogram(fit,show.vario=TRUE, vario=vario,pch=20) ################################################################ ### ### Example 2. Plot of fitted covariance and fitted ### and empirical semivariogram from a Bernoulli ### RF with Genwend correlation. ### ############################################################### set.seed(2111) model="Binomial";n=1 # Set the coordinates of the points: x = runif(500, 0, 1) y = runif(500, 0, 1) coords=cbind(x,y) # Set the model's parameters: corrmodel = "GenWend" mean = 0 nugget = 0 scale = 0.2 smooth=0 power=4 param=list(mean=mean, nugget=nugget, scale=scale,smooth=0,power2=4) # Simulation of the Gaussian RF: data = GeoSim(coordx=coords, corrmodel=corrmodel, model=model,param=param,n=n)$data start=list(mean=0,scale=scale) fixed=list(nugget=nugget,power2=4,smooth=0) # Maximum composite-likelihood fitting of the Binomial random field: fit = GeoFit(data,coordx=coords, corrmodel=corrmodel,model=model, likelihood="Marginal",type='Pairwise',start=start,n=n, optimizer="BFGS", fixed=fixed,neighb=4) # Empirical estimation of the variogram: vario = GeoVariogram(data,coordx=coords,maxdist=0.5) # Plot of covariance and variogram functions: GeoCovariogram(fit, show.vario=TRUE, vario=vario,pch=20,ylim=c(0,0.3)) ################################################################ ### ### Example 3. Plot of fitted covariance and fitted ### and empirical semivariogram from a Weibull RF ### with Wend0 correlation. ### ############################################################### set.seed(111) model="Weibull";shape=4 # Set the coordinates of the points: x = runif(700, 0, 1) y = runif(700, 0, 1) coords=cbind(x,y) # Set the model's parameters: corrmodel = "Wend0" mean = 0 nugget = 0 scale = 0.4 power2=4 param=list(mean=mean, nugget=nugget, scale=scale,shape=shape,power2=power2) # Simulation of the Gaussian RF: data = GeoSim(coordx=coords, corrmodel=corrmodel, model=model,param=param)$data start=list(mean=0,scale=scale,shape=shape) I=Inf lower=list(mean=-I,scale=0,shape=0) upper=list(mean= I,scale=I,shape=I) fixed=list(nugget=nugget,power2=power2) fit = GeoFit(data,coordx=coords, corrmodel=corrmodel,model=model, likelihood="Marginal",type='Pairwise',start=start, lower=lower,upper=upper, optimizer="nlminb", fixed=fixed,neighb=3) # Empirical estimation of the variogram: vario = GeoVariogram(data,coordx=coords,maxdist=0.5) # Plot of covariance and variogram functions: GeoCovariogram(fit, show.vario=TRUE, vario=vario,pch=20) ################################################################ ### ### Example 4. Plot of fitted and empirical semivariogram ### from a space time Gaussian random fields ### with double Matern correlation. ### ############################################################### set.seed(92) # Define the spatial-coordinates of the points: x = runif(50, 0, 1) y = runif(50, 0, 1) coords=cbind(x,y) # Define the temporal sequence: time = seq(0, 10, 1) param=list(mean=mean,nugget=nugget, smooth_s=0.5,smooth_t=0.5,scale_s=0.5/3,scale_t=2/2,sill=sill) # Simulation of the spatio-temporal Gaussian random field: data = GeoSim(coordx=coords, coordt=time, corrmodel="Matern_Matern",param=param)$data fixed=list(nugget=0, mean=0, smooth_s=0.5,smooth_t=0.5) start=list(scale_s=0.2, scale_t=0.5, sill=1) # Maximum composite-likelihood fitting of the space-time Gaussian random field: fit = GeoFit(data, coordx=coords, coordt=time, corrmodel="Matern_Matern", maxtime=1, neighb=3, likelihood="Marginal", type="Pairwise",fixed=fixed, start=start) # Empirical estimation of spatio-temporal covariance: vario = GeoVariogram(data,coordx=coords, coordt=time, maxtime=5,maxdist=0.5) # Plot of the fitted space-time variogram GeoCovariogram(fit,vario=vario,show.vario=TRUE) # Plot of covariance, variogram and spatio and temporal profiles: GeoCovariogram(fit,vario=vario,fix.lagt=1,fix.lags=1,show.vario=TRUE,pch=20) ################################################################ ### ### Example 5. Plot of fitted and empirical semivariogram ### from a bivariate Gaussian random fields ### with Matern correlation. ### ############################################################### set.seed(92) # Define the spatial-coordinates of the points: x <- runif(600, 0, 2) y <- runif(600, 0, 2) coords <- cbind(x,y) # Simulation of a bivariate spatial Gaussian RF: # with a Bivariate Matern set.seed(12) param=list(mean_1=4,mean_2=2,smooth_1=0.5,smooth_2=0.5,smooth_12=0.5, scale_1=0.12,scale_2=0.1,scale_12=0.15, sill_1=1,sill_2=1,nugget_1=0,nugget_2=0,pcol=-0.5) data <- GeoSim(coordx=coords,corrmodel="Bi_matern", param=param)$data # selecting fixed and estimated parameters fixed=list(mean_1=4,mean_2=2,nugget_1=0,nugget_2=0, smooth_1=0.5,smooth_2=0.5,smooth_12=0.5) start=list(sill_1=var(data[1,]),sill_2=var(data[2,]), scale_1=0.1,scale_2=0.1,scale_12=0.1, pcol=cor(data[1,],data[2,])) # Maximum marginal pairwise likelihood fitcl<- GeoFit(data=data, coordx=coords, corrmodel="Bi_Matern", likelihood="Marginal",type="Pairwise", optimizer="BFGS" , start=start,fixed=fixed, neighb=4) print(fitcl) # Empirical estimation of spatio-temporal covariance: vario = GeoVariogram(data,coordx=coords,maxdist=0.4,bivariate=TRUE) GeoCovariogram(fitcl,vario=vario,show.vario=TRUE,pch=20)
Image plot displaying the pattern of the sparsness of a covariance matrix.
GeoCovDisplay(covmatrix,limits=FALSE,pch=2)GeoCovDisplay(covmatrix,limits=FALSE,pch=2)
covmatrix |
An object of class GeoCovmatrix. See the Section Details. |
limits |
Logical; If TRUE and the covariance matrix is spatiotemporal or spatial bivariate then vertical and horizontal lines are added to the image plot. |
pch |
Type of symbols to use in the image plot. |
For a given covariance matrix object (GeoCovmatrix)
the function diplays the pattern of the sparsness of a covariance matrix
where the white color represents 0 entries and black color represents non zero entries
Produces a plot. No values are returned.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
library(GeoModels) # Define the spatial-coordinates of the points: x <- runif(100, 0, 2) y <- runif(100, 0, 2) coords=cbind(x,y) matrix1 <- GeoCovmatrix(coordx=coords, corrmodel="GenWend", param=list(smooth=0, power2=4,sill=1,scale=0.2,nugget=0)) GeoCovDisplay(matrix1)library(GeoModels) # Define the spatial-coordinates of the points: x <- runif(100, 0, 2) y <- runif(100, 0, 2) coords=cbind(x,y) matrix1 <- GeoCovmatrix(coordx=coords, corrmodel="GenWend", param=list(smooth=0, power2=4,sill=1,scale=0.2,nugget=0)) GeoCovDisplay(matrix1)
The function computes the covariance matrix associated to a spatial or spatio-temporal or a bivariate spatial Gaussian or non-Gaussian random field with given underlying covariance model and a set of spatial location sites (and temporal instants).
GeoCovmatrix(estobj = NULL, coordx, coordy = NULL, coordz = NULL, coordt = NULL, coordx_dyn = NULL, corrmodel, distance = "Eucl", grid = FALSE, model = "Gaussian", n = 1, param, anisopars = NULL, radius = 1, sparse = FALSE, copula = NULL, X = NULL, spobj = NULL)GeoCovmatrix(estobj = NULL, coordx, coordy = NULL, coordz = NULL, coordt = NULL, coordx_dyn = NULL, corrmodel, distance = "Eucl", grid = FALSE, model = "Gaussian", n = 1, param, anisopars = NULL, radius = 1, sparse = FALSE, copula = NULL, X = NULL, spobj = NULL)
estobj |
An object of class |
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of spatial coordinates; optional argument, the default is |
coordz |
A numeric vector giving 1-dimension of spatial coordinates; optional argument, the default is |
coordt |
A numeric vector giving 1-dimension of temporal coordinates.
At the moment implemented only for the Gaussian case. Optional argument, the default is |
coordx_dyn |
A list of |
corrmodel |
String; the name of a correlation model, for the description see the Section Details. |
distance |
String; the name of the spatial distance. The default is |
grid |
Logical; if |
n |
Numeric; the number of trials in a binomial random field. Default is |
model |
String; the type of RF. See |
param |
A list of parameter values required for the covariance model. |
anisopars |
A list of two elements |
radius |
Numeric; a value indicating the radius of the sphere
when using covariance models valid for the great circle distance. Default value is |
sparse |
Logical; if |
copula |
String; the type of copula. It can be |
X |
Numeric; matrix of space-time covariates. |
spobj |
An object of class |
In the spatial case, the covariance matrix of the random vector
with a specific spatial covariance model is computed. Here is the number of spatial location sites.
In the space-time case, the covariance matrix of the random vector
with a specific space-time covariance model is computed. Here is the number of temporal instants.
In the bivariate case, the covariance matrix of the random vector
with a specific spatial bivariate covariance model is computed.
The location site can be a point in the -dimensional Euclidean space with or
or a point (given in lon/lat degree format) on a sphere of arbitrary radius.
A list with all implemented spatial, space-time and bivariate
correlation models is given below.
The argument param is a list including all the parameters of a given
correlation model specified by the argument corrmodel.
For each correlation model one can check the associated parameters' names using CorrParam.
In what follows
, , and .
The associated parameters in the argument param are
smooth, power2, power, power_s, power_t and sep respectively.
Moreover let when is true and otherwise.
Spatial correlation models:
GenCauchy (generalised Cauchy in Gneiting and Schlather 2004) defined as:
If is the geodesic distance then .
Matern defined as:
If is the geodesic distance then .
Kummer (Kummer hypergeometric in Ma and Bhadra 2022) defined as:
where is the Kummer hypergeometric function.
If is the geodesic distance then .
Kummer_Matern It is a rescaled version of the Kummer model,
i.e. must be divided by . When goes to infinity it is the Matern model.
Wave defined as:
This model is valid only for dimensions less than or equal to 3.
GenWend (Generalized Wendland in Bevilacqua et al. 2019) defined as:
where
and and
is the Gaussian hypergeometric function.
The cases correspond to the Wend0, Wend1 and Wend2 models respectively.
GenWend_Matern (Generalized Wendland Matern in Bevilacqua et al. 2022).
It is defined as a rescaled version of the Generalized Wendland, i.e.
must be divided by .
When goes to infinity it is the Matern model.
GenWend_Matern2 (Generalized Wendland Matern second parametrisation).
It is defined as a rescaled version of the Generalized Wendland, i.e.
must be multiplied by and the smoothness parameter is .
When goes to infinity it is the Matern model.
Hypergeometric (Hypergeometric model in Bevilacqua et al. 2025).
Hypergeometric_Matern (Hypergeometric model first parametrisation).
Hypergeometric_Matern2 (Hypergeometric model second parametrisation).
Multiquadric defined as:
This model is valid on the unit sphere and is the geodesic distance.
Sinpower defined as:
This model is valid on the unit sphere and is the geodesic distance.
F_Sphere (F family in Alegria et al. 2021) defined as:
where .
This model is valid on the unit sphere and is the geodesic distance.
Spatio-temporal correlation models:
Non-separable models:
Gneiting defined as:
Gneiting_GC defined as:
where can be either Euclidean or geodesic distance.
Iacocesare defined as:
Porcu defined as:
Porcu1 defined as:
Stein defined as:
where .
Gneiting_mat_S defined as:
where , , .
Gneiting_mat_T defined by interchanging with in Gneiting_mat_S.
Gneiting_wen_S defined as:
where , , .
Gneiting_wen_T defined by interchanging with in Gneiting_wen_S.
Matern_Matern_nosep defined as:
with and .
GenWend_GenWend_nosep defined as:
with , for , and .
Multiquadric_st defined as:
where .
This model is valid on the unit sphere and is the geodesic distance.
Sinpower_st defined as:
where and , .
This model is valid on the unit sphere and is the geodesic distance.
Separable models:
Space-time separable correlation models are easily obtained as the product of a spatial and a temporal correlation model, that is
Several combinations are possible:
Exp_Exp defined as:
Matern_Matern defined as:
GenWend_GenWend defined as:
Stable_Stable defined as:
Note that some models are nested (e.g. Exp_Exp within Matern_Matern).
Spatial bivariate correlation models:
Bi_Matern (Bivariate full Matern model)
Bi_Matern_contr (Bivariate Matern model with constraints)
Bi_Matern_sep (Bivariate separable Matern model)
Bi_LMC (Bivariate linear model of coregionalization)
Bi_LMC_contr (Bivariate LMC with constraints)
Bi_Wendx (Bivariate full Wendland model)
Bi_Wendx_contr (Bivariate Wendland model with constraints)
Bi_Wendx_sep (Bivariate separable Wendland model)
Bi_F_Sphere (Bivariate full F model on the unit sphere)
Remarks:
In what follows we assume
positive.
The associated names of the parameters in param are
sill, sill_1, sill_2,
nugget, nugget_1, nugget_2,
scale, scale_s, scale_t, scale_1, scale_2, scale_12,
smooth_1, smooth_2, smooth_12, a_1, a_12, a_21, a_2
respectively.
Let be a spatial correlation model given in standard notation.
Then the covariance model applied with arbitrary variance, nugget and scale equals to if and
with nugget parameter between 0 and 1.
Similarly, if is a spatio-temporal correlation model given in standard notation,
then the covariance model is if and and
Here ‘...’ stands for additional parameters.
The bivariate models implemented are the following:
Bi_Matern defined as:
where is the colocated correlation parameter and .
The model Bi_Matern_sep (separable Matern) is a special case when
and .
The model Bi_Matern_contr (constrained Matern)
is a special case when and .
Bi_GenWend defined as:
where is the colocated correlation parameter and .
The model Bi_GenWend_sep (separable GenWendland) is a special case when
and .
The model Bi_GenWend_contr (constrained GenWendland)
is a special case when and .
Bi_LMC defined as:
where is a correlation model.
The model Bi_LMC_contr
is a special case when .
Bivariate LMC models, in the current version of the package, are obtained with equal to the exponential correlation model.
Returns an object of class GeoCovmatrix.
An object of class GeoCovmatrix is a list containing
at most the following components:
bivariate |
Logical: |
coordx |
A |
coordy |
A |
coordt |
A |
coordx_dyn |
A list of |
covmatrix |
The covariance matrix if |
corrmodel |
String: the correlation model. |
distance |
String: the type of spatial distance. |
grid |
Logical: |
nozero |
In the case of tapered matrix the percentage of non-zero values in the
covariance matrix; otherwise |
n |
The number of trials for binomial RFs. |
namescorr |
String: the names of the correlation parameters. |
numcoord |
Numeric: the number of spatial coordinates. |
numtime |
Numeric: the number of temporal coordinates. |
model |
The type of RF, see |
param |
Numeric: the covariance parameters. |
spacetime |
|
sparse |
Logical: is the returned object of class |
Moreno Bevilacqua, [email protected], https://sites.google.com/view/moreno-bevilacqua/home
Víctor Morales-Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/
Christian Caamaño-Carrillo, [email protected], https://www.researchgate.net/profile/Christian-Caamano
Alegria, A., Cuevas-Pacheco, F., Diggle, P. and Porcu, E. (2021). The F-family of covariance functions: A Matérn analogue for modeling random fields on spheres. Spatial Statistics 43, 100512.
Bevilacqua, M., Faouzi, T., Furrer, R. and Porcu, E. (2019). Estimation and prediction using generalized Wendland functions under fixed domain asymptotics. Annals of Statistics 47(2), 828–856.
Bevilacqua, M., Caamaño-Carrillo, C. and Porcu, E. (2022). Unifying compactly supported and Matérn covariance functions in spatial statistics. Journal of Multivariate Analysis 189, 104949.
Daley, D. J., Porcu, E. and Bevilacqua, M. (2015). Classes of compactly supported covariance functions for multivariate random fields. Stochastic Environmental Research and Risk Assessment 29(4), 1249–1263.
Emery, X. and Alegria, A. (2022). The Gauss hypergeometric covariance kernel for modeling second-order stationary random fields in Euclidean spaces: its compact support, properties and spectral representation. Stochastic Environmental Research and Risk Assessment 36, 2819–2834.
Gneiting, T. (2002). Nonseparable, stationary covariance functions for space-time data. Journal of the American Statistical Association 97, 590–600.
Gneiting, T., Kleiber, W. and Schlather, M. (2010). Matérn cross-covariance functions for multivariate random fields. Journal of the American Statistical Association 105, 1167–1177.
Ma, P. and Bhadra, A. (2022). Beyond Matérn: on a class of interpretable confluent hypergeometric covariance functions. Journal of the American Statistical Association, 1–14.
Porcu, E., Bevilacqua, M. and Genton, M. (2015). Spatio-temporal covariance and cross-covariance functions of the great circle distance on a sphere. Journal of the American Statistical Association. DOI: 10.1080/01621459.2015.1072541.
Gneiting, T. and Schlather, M. (2004). Stochastic models that separate fractal dimension and the Hurst effect. SIAM Review 46, 269–282.
library(GeoModels) ################################################################ ### ### Example 1. Estimated spatial covariance matrix associated to ### a WCL estimates using the Matern correlation model ### ############################################################### set.seed(3) N <- 300 # number of location sites x <- runif(N, 0, 1) y <- runif(N, 0, 1) coords <- cbind(x, y) # Set the covariance model's parameters: corrmodel <- "Matern" mean <- 0.5 sill <- 1 nugget <- 0 scale <- 0.2/3 smooth <- 0.5 param <- list(mean = mean, sill = sill, nugget = nugget, scale = scale, smooth = smooth) data <- GeoSim(coordx = coords, corrmodel = corrmodel, param = param)$data fixed <- list(nugget = nugget, smooth = smooth) start <- list(mean = mean, scale = scale, sill = sill) fit0 <- GeoFit(data = data, coordx = coords, corrmodel = corrmodel, neighb = 3, likelihood = "Conditional", optimizer = "BFGS", type = "Pairwise", start = start, fixed = fixed) print(fit0) # estimated covariance matrix using Geofit object mm <- GeoCovmatrix(fit0)$covmatrix # estimated covariance matrix mm1 <- GeoCovmatrix(coordx = coords, corrmodel = corrmodel, param = c(fit0$param, fit0$fixed))$covmatrix sum(mm - mm1) ################################################################ ### ### Example 2. Spatial covariance matrix associated to ### the Generalized Wendland-Matern correlation model ### ############################################################### # Correlation Parameters for Gen Wendland model CorrParam("GenWend_Matern") # Gen Wendland Parameters param <- list(sill = 1, scale = 0.04, nugget = 0, smooth = 0, power2 = 1/1.5) matrix2 <- GeoCovmatrix(coordx = coords, corrmodel = "GenWend_Matern", param = param, sparse = TRUE) # Percentage of non-zero values matrix2$nozero ################################################################ ### ### Example 3. Spatial covariance matrix associated to ### the Kummer correlation model ### ############################################################### # Correlation Parameters for Kummer model CorrParam("Kummer") param <- list(sill = 1, scale = 0.2, nugget = 0, smooth = 0.5, power2 = 1) matrix3 <- GeoCovmatrix(coordx = coords, corrmodel = "Kummer", param = param) matrix3$covmatrix[1:4, 1:4] ################################################################ ### ### Example 4. Covariance matrix associated to ### the space-time double Matern correlation model ### ############################################################### # Define the temporal coordinates: times <- seq(1, 4, 1) # Correlation Parameters for double Matern model CorrParam("Matern_Matern") # Define covariance parameters param <- list(scale_s = 0.3, scale_t = 0.5, sill = 1, smooth_s = 0.5, smooth_t = 0.5) # Simulation of a spatial Gaussian random field: matrix4 <- GeoCovmatrix(coordx = coords, coordt = times, corrmodel = "Matern_Matern", param = param) dim(matrix4$covmatrix) ################################################################ ### ### Example 5. Spatial covariance matrix associated to ### a skew Gaussian RF with Matern correlation model ### ############################################################### param <- list(sill = 1, scale = 0.3/3, nugget = 0, skew = 4, smooth = 0.5) # Simulation of a spatial Gaussian random field: matrix5 <- GeoCovmatrix(coordx = coords, corrmodel = "Matern", param = param, model = "SkewGaussian") # covariance matrix matrix5$covmatrix[1:4, 1:4] ################################################################ ### ### Example 6. Spatial covariance matrix associated to ### a Weibull RF with GenWend correlation model ### ############################################################### param <- list(scale = 0.3, nugget = 0, shape = 4, mean = 0, smooth = 1, power2 = 5) # Simulation of a spatial Gaussian random field: matrix6 <- GeoCovmatrix(coordx = coords, corrmodel = "GenWend", param = param, sparse = TRUE, model = "Weibull") # Percentage of non-zero values matrix6$nozero ################################################################ ### ### Example 7. Spatial covariance matrix associated to ### a binomial Gaussian RF with Generalized Wendland correlation model ### ############################################################### param <- list(mean = 0.2, scale = 0.2, nugget = 0, power2 = 4, smooth = 0) # Simulation of a spatial Gaussian random field: matrix7 <- GeoCovmatrix(coordx = coords, corrmodel = "GenWend", param = param, n = 5, sparse = TRUE, model = "Binomial") as.matrix(matrix7$covmatrix)[1:4, 1:4] ################################################################ ### ### Example 8. Covariance matrix associated to ### a bivariate Matern exponential correlation model ### ############################################################### set.seed(8) # Define the spatial coordinates of the points: x <- runif(4, 0, 1) y <- runif(4, 0, 1) coords <- cbind(x, y) # Parameters param <- list(mean_1 = 0, mean_2 = 0, sill_1 = 1, sill_2 = 2, scale_1 = 0.1, scale_2 = 0.1, scale_12 = 0.1, smooth_1 = 0.5, smooth_2 = 0.5, smooth_12 = 0.5, nugget_1 = 0, nugget_2 = 0, pcol = -0.25) # Covariance matrix matrix8 <- GeoCovmatrix(coordx = coords, corrmodel = "Bi_matern", param = param)$covmatrix matrix8library(GeoModels) ################################################################ ### ### Example 1. Estimated spatial covariance matrix associated to ### a WCL estimates using the Matern correlation model ### ############################################################### set.seed(3) N <- 300 # number of location sites x <- runif(N, 0, 1) y <- runif(N, 0, 1) coords <- cbind(x, y) # Set the covariance model's parameters: corrmodel <- "Matern" mean <- 0.5 sill <- 1 nugget <- 0 scale <- 0.2/3 smooth <- 0.5 param <- list(mean = mean, sill = sill, nugget = nugget, scale = scale, smooth = smooth) data <- GeoSim(coordx = coords, corrmodel = corrmodel, param = param)$data fixed <- list(nugget = nugget, smooth = smooth) start <- list(mean = mean, scale = scale, sill = sill) fit0 <- GeoFit(data = data, coordx = coords, corrmodel = corrmodel, neighb = 3, likelihood = "Conditional", optimizer = "BFGS", type = "Pairwise", start = start, fixed = fixed) print(fit0) # estimated covariance matrix using Geofit object mm <- GeoCovmatrix(fit0)$covmatrix # estimated covariance matrix mm1 <- GeoCovmatrix(coordx = coords, corrmodel = corrmodel, param = c(fit0$param, fit0$fixed))$covmatrix sum(mm - mm1) ################################################################ ### ### Example 2. Spatial covariance matrix associated to ### the Generalized Wendland-Matern correlation model ### ############################################################### # Correlation Parameters for Gen Wendland model CorrParam("GenWend_Matern") # Gen Wendland Parameters param <- list(sill = 1, scale = 0.04, nugget = 0, smooth = 0, power2 = 1/1.5) matrix2 <- GeoCovmatrix(coordx = coords, corrmodel = "GenWend_Matern", param = param, sparse = TRUE) # Percentage of non-zero values matrix2$nozero ################################################################ ### ### Example 3. Spatial covariance matrix associated to ### the Kummer correlation model ### ############################################################### # Correlation Parameters for Kummer model CorrParam("Kummer") param <- list(sill = 1, scale = 0.2, nugget = 0, smooth = 0.5, power2 = 1) matrix3 <- GeoCovmatrix(coordx = coords, corrmodel = "Kummer", param = param) matrix3$covmatrix[1:4, 1:4] ################################################################ ### ### Example 4. Covariance matrix associated to ### the space-time double Matern correlation model ### ############################################################### # Define the temporal coordinates: times <- seq(1, 4, 1) # Correlation Parameters for double Matern model CorrParam("Matern_Matern") # Define covariance parameters param <- list(scale_s = 0.3, scale_t = 0.5, sill = 1, smooth_s = 0.5, smooth_t = 0.5) # Simulation of a spatial Gaussian random field: matrix4 <- GeoCovmatrix(coordx = coords, coordt = times, corrmodel = "Matern_Matern", param = param) dim(matrix4$covmatrix) ################################################################ ### ### Example 5. Spatial covariance matrix associated to ### a skew Gaussian RF with Matern correlation model ### ############################################################### param <- list(sill = 1, scale = 0.3/3, nugget = 0, skew = 4, smooth = 0.5) # Simulation of a spatial Gaussian random field: matrix5 <- GeoCovmatrix(coordx = coords, corrmodel = "Matern", param = param, model = "SkewGaussian") # covariance matrix matrix5$covmatrix[1:4, 1:4] ################################################################ ### ### Example 6. Spatial covariance matrix associated to ### a Weibull RF with GenWend correlation model ### ############################################################### param <- list(scale = 0.3, nugget = 0, shape = 4, mean = 0, smooth = 1, power2 = 5) # Simulation of a spatial Gaussian random field: matrix6 <- GeoCovmatrix(coordx = coords, corrmodel = "GenWend", param = param, sparse = TRUE, model = "Weibull") # Percentage of non-zero values matrix6$nozero ################################################################ ### ### Example 7. Spatial covariance matrix associated to ### a binomial Gaussian RF with Generalized Wendland correlation model ### ############################################################### param <- list(mean = 0.2, scale = 0.2, nugget = 0, power2 = 4, smooth = 0) # Simulation of a spatial Gaussian random field: matrix7 <- GeoCovmatrix(coordx = coords, corrmodel = "GenWend", param = param, n = 5, sparse = TRUE, model = "Binomial") as.matrix(matrix7$covmatrix)[1:4, 1:4] ################################################################ ### ### Example 8. Covariance matrix associated to ### a bivariate Matern exponential correlation model ### ############################################################### set.seed(8) # Define the spatial coordinates of the points: x <- runif(4, 0, 1) y <- runif(4, 0, 1) coords <- cbind(x, y) # Parameters param <- list(mean_1 = 0, mean_2 = 0, sill_1 = 1, sill_2 = 2, scale_1 = 0.1, scale_2 = 0.1, scale_12 = 0.1, smooth_1 = 0.5, smooth_2 = 0.5, smooth_12 = 0.5, nugget_1 = 0, nugget_2 = 0, pcol = -0.25) # Covariance matrix matrix8 <- GeoCovmatrix(coordx = coords, corrmodel = "Bi_matern", param = param)$covmatrix matrix8
The procedure use the GeoKrig or GeoKrigloc function to compute n-fold kriging cross-validation using informations from a GeoFit object. The function returns some prediction scores.
GeoCV(fit, K=100, estimation=TRUE, optimizer=NULL, lower=NULL, upper=NULL, n.fold=0.05,local=FALSE, neighb=NULL, maxdist=NULL,maxtime=NULL,sparse=FALSE, type_krig="Simple", which=1, parallel=TRUE, ncores=NULL,progress=TRUE)GeoCV(fit, K=100, estimation=TRUE, optimizer=NULL, lower=NULL, upper=NULL, n.fold=0.05,local=FALSE, neighb=NULL, maxdist=NULL,maxtime=NULL,sparse=FALSE, type_krig="Simple", which=1, parallel=TRUE, ncores=NULL,progress=TRUE)
fit |
An object of class
|
K |
The number of iterations in cross-validation. |
estimation |
Logical; if |
optimizer |
The type of optimization algorithm if estimation is |
lower |
An optional named list giving the values for the lower bound of the space parameter
when the optimizer is |
upper |
An optional named list giving the values for the upper bound of the space parameter
when the optimizer is |
n.fold |
Numeric; the percentage of data to be deleted (and predicted) in the cross-validation procedure. |
local |
Logical; If local is TRUE, then local kriging is performed. The default is FALSE. |
neighb |
Numeric; an optional positive integer indicating the order of neighborhood if local kriging is performed. |
maxdist |
Numeric; an optional positive value indicating the distance in the spatial neighborhood if local kriging is performed. |
maxtime |
Numeric; an optional positive value indicating the distance in the temporal neighborhood if local kriging is performed. |
sparse |
Logical; if |
type_krig |
String; the type of kriging. If |
which |
Numeric; In the case of bivariate cokriging it indicates which variable to predict. It can be 1 or 2 |
parallel |
Logical; if |
ncores |
Numeric; number of cores involved in parallelization. |
progress |
Logic; If TRUE then a progress bar is shown. |
Returns an object containing the following informations:
predicted |
A list of the predicted values in the CV procedure; |
data_to_pred |
A list of the data to predict in the CV procedure; |
mae |
The vector of mean absolute error in the CV procedure; |
mad |
The vector of median absolute error in the CV procedure; |
brie |
The vector of brie score in the CV procedure; |
rmse |
The vector of root mean squared error in the CV procedure; |
lscore |
The vector of log-score in the CV procedure; |
crps |
The vector of continuous ranked probability score in the CV procedure; |
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
library(GeoModels) ################################################################ ########### Examples of spatial kriging ############ ################################################################ model="Gaussian" set.seed(79) x = runif(400, 0, 1) y = runif(400, 0, 1) coords=cbind(x,y) # Set the exponential cov parameters: corrmodel = "GenWend" mean=0; sill=5; nugget=0 scale=0.2;smooth=0;power2=4 param=list(mean=mean,sill=sill,nugget=nugget,scale=scale,smooth=smooth,power2=power2) # Simulation of the spatial Gaussian random field: data = GeoSim(coordx=coords, corrmodel=corrmodel, param=param)$data ## estimation with pairwise likelihood fixed=list(nugget=nugget,smooth=0,power2=power2) start=list(mean=0,scale=scale,sill=1) I=Inf lower=list(mean=-I,scale=0,sill=0) upper=list(mean= I,scale=I,sill=I) # Maximum pairwise likelihood fitting : fit = GeoFit(data, coordx=coords, corrmodel=corrmodel,model=model, likelihood='Marginal', type='Pairwise',neighb=3, optimizer="nlminb", lower=lower,upper=upper, start=start,fixed=fixed) #a=GeoCV(fit,K=100,estimation=TRUE,parallel=TRUE) #mean(a$rmse)library(GeoModels) ################################################################ ########### Examples of spatial kriging ############ ################################################################ model="Gaussian" set.seed(79) x = runif(400, 0, 1) y = runif(400, 0, 1) coords=cbind(x,y) # Set the exponential cov parameters: corrmodel = "GenWend" mean=0; sill=5; nugget=0 scale=0.2;smooth=0;power2=4 param=list(mean=mean,sill=sill,nugget=nugget,scale=scale,smooth=smooth,power2=power2) # Simulation of the spatial Gaussian random field: data = GeoSim(coordx=coords, corrmodel=corrmodel, param=param)$data ## estimation with pairwise likelihood fixed=list(nugget=nugget,smooth=0,power2=power2) start=list(mean=0,scale=scale,sill=1) I=Inf lower=list(mean=-I,scale=0,sill=0) upper=list(mean= I,scale=I,sill=I) # Maximum pairwise likelihood fitting : fit = GeoFit(data, coordx=coords, corrmodel=corrmodel,model=model, likelihood='Marginal', type='Pairwise',neighb=3, optimizer="nlminb", lower=lower,upper=upper, start=start,fixed=fixed) #a=GeoCV(fit,K=100,estimation=TRUE,parallel=TRUE) #mean(a$rmse)
Compute a full distance matrix between coordinates in 2D or 3D, using Euclidean,
Chordal, or Geodesic distance. The computation is done in C for efficiency,
with parameters passed from R via dotCall64.
GeoDistances(coordx = NULL, coordy = NULL, coordz = NULL, distance = c("Eucl", "Chor", "Geod"), radius = 1)GeoDistances(coordx = NULL, coordy = NULL, coordz = NULL, distance = c("Eucl", "Chor", "Geod"), radius = 1)
coordx |
A numeric matrix of coordinates. Must have 2 or 3 columns
(for 2D or 3D) (if coordy and coordz are not provided). Otherwise
coordinates can be given via
|
coordy |
Optional numeric vector of coordinates. |
coordz |
Optional numeric vector of coordinates (for 3D Euclidean). |
distance |
Type of distance to compute:
|
radius |
Radius of the sphere for geodesic or chordal distances. Defaults to 1. Use Earth radius (e.g., 6371 Km) for geographic distances. |
Euclidean distance: straight-line distance in 2D or 3D space.
Chordal distance: Euclidean distance between points projected on the unit sphere, scaled by the given radius.
Geodesic distance: shortest path along the surface of a sphere of
radius radius.
A symmetric numeric matrix of size n x n, where n is the number
of points. Each entry contains the distance between the corresponding pair
of coordinates.
# Example with Euclidean distance coords <- cbind(c(0, 10), c(0, 10)) GeoDistances(coords, distance = "Eucl") # Example with geodesic distance (approx distance between Rome and New York) rome <- c(12.4964, 41.9028) # ny <- c(-74.0060, 40.7128) coords <- rbind(rome, ny) GeoDistances(coords, distance = "Geod", radius = 6371)# Example with Euclidean distance coords <- cbind(c(0, 10), c(0, 10)) GeoDistances(coords, distance = "Eucl") # Example with geodesic distance (approx distance between Rome and New York) rome <- c(12.4964, 41.9028) # ny <- c(-74.0060, 40.7128) coords <- rbind(rome, ny) GeoDistances(coords, distance = "Geod", radius = 6371)
The function computes RMSE, MAE, LSCORE, CRPS predictive scores based on drop-one prediction for a spatial, spatiotemporal and bivariate Gaussian RFs
GeoDoScores(data, method="cholesky", matrix)GeoDoScores(data, method="cholesky", matrix)
data |
A |
method |
String; the type of matrix decomposition used in the computation of the predictive scores. Default is |
matrix |
An object of class GeoCovmatrix. See the Section Details. |
For a given covariance matrix object (GeoCovmatrix)
and a given spatial, spatiotemporal or bivariare realization
from a Gaussian random field,
the function computes four predictive scores based on drop-one prediction.
Returns a list containing the following informations:
RMSE |
Root-mean-square error predictive score |
MAE |
Mean absolute error predictive score |
LSCORE |
Logarithmic predictive score |
CRPS |
Continuous ranked probability predictive score |
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
Zhang H. and Wang Y. (2010). Kriging and cross-validation for massive spatial data. Environmetrics, 21, 290–304. Gneiting T. and Raftery A. Strictly Proper Scoring Rules, Prediction, and Estimation. Journal of the American Statistical Association, 102
library(GeoModels) ################################################################ ######### Examples of predictive score computation ############ ################################################################ set.seed(8) # Define the spatial-coordinates of the points: x <- runif(500, 0, 2) y <- runif(500, 0, 2) coords=cbind(x,y) matrix1 <- GeoCovmatrix(coordx=coords, corrmodel="Matern", param=list(smooth=0.5, sill=1,scale=0.2,nugget=0)) data <- GeoSim(coordx=coords, corrmodel="Matern", param=list(mean=0,smooth=0.5, sill=1,scale=0.2,nugget=0))$data Pr_scores <- GeoDoScores(data,matrix=matrix1) Pr_scoreslibrary(GeoModels) ################################################################ ######### Examples of predictive score computation ############ ################################################################ set.seed(8) # Define the spatial-coordinates of the points: x <- runif(500, 0, 2) y <- runif(500, 0, 2) coords=cbind(x,y) matrix1 <- GeoCovmatrix(coordx=coords, corrmodel="Matern", param=list(smooth=0.5, sill=1,scale=0.2,nugget=0)) data <- GeoSim(coordx=coords, corrmodel="Matern", param=list(mean=0,smooth=0.5, sill=1,scale=0.2,nugget=0))$data Pr_scores <- GeoDoScores(data,matrix=matrix1) Pr_scores
Maximum weighted composite-likelihood fitting for Gaussian and some Non-Gaussian univariate spatial, spatio-temporal and bivariate spatial random fields. The function allows fixing any of the parameters and setting upper/lower bounds in the optimization. Different optimization methods can be used.
GeoFit(data, coordx, coordy=NULL, coordz=NULL, coordt=NULL, coordx_dyn=NULL, copula=NULL, corrmodel=NULL, distance="Eucl", fixed=NULL, anisopars=NULL, est.aniso=c(FALSE,FALSE), grid=FALSE, likelihood="Marginal", lower=NULL, maxdist=Inf, neighb=NULL, p_neighb=1, maxtime=Inf, memdist=TRUE, method="cholesky", model="Gaussian", n=1, onlyvar=FALSE, optimizer="Nelder-Mead", radius=1, score=FALSE, sensitivity=FALSE, sparse=FALSE, start=NULL, thin_method="bernoulli",type="Pairwise", upper=NULL, varest=FALSE, weighted=FALSE, X=NULL, spobj=NULL, spdata=NULL)GeoFit(data, coordx, coordy=NULL, coordz=NULL, coordt=NULL, coordx_dyn=NULL, copula=NULL, corrmodel=NULL, distance="Eucl", fixed=NULL, anisopars=NULL, est.aniso=c(FALSE,FALSE), grid=FALSE, likelihood="Marginal", lower=NULL, maxdist=Inf, neighb=NULL, p_neighb=1, maxtime=Inf, memdist=TRUE, method="cholesky", model="Gaussian", n=1, onlyvar=FALSE, optimizer="Nelder-Mead", radius=1, score=FALSE, sensitivity=FALSE, sparse=FALSE, start=NULL, thin_method="bernoulli",type="Pairwise", upper=NULL, varest=FALSE, weighted=FALSE, X=NULL, spobj=NULL, spdata=NULL)
data |
A |
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of spatial coordinates; optional argument, default is |
coordz |
A numeric vector giving 1-dimension of spatial coordinates; optional argument, default is |
coordt |
A numeric vector assigning 1-dimension of temporal coordinates. Optional argument, default is |
coordx_dyn |
A list of |
copula |
String; the type of copula. It can be |
corrmodel |
String; the name of a correlation model, for the description see the Section Details. |
distance |
String; the name of the spatial distance. Default is |
fixed |
An optional named list giving the values of the parameters that will be considered as known values. The listed parameters for a given model/correlation function will not be estimated. |
anisopars |
A list of two elements: |
est.aniso |
A bivariate logical vector providing which anisotropy parameters must be estimated. |
grid |
Logical; if |
likelihood |
String; the configuration of the composite likelihood. |
lower |
An optional named list giving lower bounds for parameters when the optimizer is |
maxdist |
Numeric; an optional positive value indicating the maximum spatial distance considered in the composite computation. See the Section Details for more information. |
neighb |
Numeric; an optional positive integer indicating the order of neighborhood in the composite likelihood computation. See the Section Details for more information. |
p_neighb |
Numeric; a value in |
maxtime |
Numeric; an optional positive integer indicating the order of temporal neighborhood in the composite likelihood computation. |
memdist |
Logical; if |
method |
String; the type of matrix decomposition/linear algebra backend used in likelihood computations.
Default is |
model |
String; the type of random field (and associated density) used in the likelihood objects. Default is |
n |
Numeric; number of trials in a binomial random field; number of successes in a negative binomial random field. |
onlyvar |
Logical; if |
optimizer |
String; the optimization algorithm (see |
radius |
Numeric; the radius of the sphere in the case of lon-lat coordinates. Default is |
score |
Logical; if |
sensitivity |
Logical; if |
sparse |
Logical; if |
start |
An optional named list with initial values for parameters to be estimated. Default is |
thin_method |
String; thinning scheme used when |
.
type |
String; the type of likelihood objects. If |
upper |
An optional named list giving upper bounds for parameters when the optimizer is |
varest |
Logical; if |
weighted |
Logical; if |
X |
Numeric; matrix of spatio(temporal) covariates in the linear mean specification. |
spobj |
An object of class |
spdata |
Character; the name of the data component in the |
GeoFit provides weighted composite likelihood estimation based on pairs and independence composite likelihood estimation
for Gaussian and non-Gaussian random fields. Specifically, marginal and conditional pairwise likelihoods are available
for each type of random field.
The optimization method is specified using optimizer. The default method is Nelder-Mead; other available methods are
nlm, BFGS, SANN, L-BFGS-B, bobyqa, and nlminb. In the last three cases,
bounds can be specified using lower and upper.
Depending on the dimension of data and on the name of the correlation model,
the observations are assumed to be a realization of a spatial, spatio-temporal or bivariate random field.
Specifically, with data, coordx, coordy, coordt:
If data is a numeric -dimensional vector and coordx, coordy are two numeric -dimensional vectors
(or coordx is a ()-matrix and coordy=NULL), then the data are interpreted as a single spatial realisation observed on spatial sites;
If data is a numeric ()-matrix and coordt is a numeric -dimensional vector, then the data are interpreted as a single spatio-temporal realisation observed on d sites and t times;
If data is a numeric ()-matrix, then the data are interpreted as a single bivariate spatial realisation observed on d spatial sites;
If data is a list, coordx_dyn is a list and coordt is a numeric -dimensional vector, then the data are interpreted as a spatio-temporal realisation observed on dynamical spatial sites (different locations for each time) and for t times.
It is also possible to specify a matrix of covariates using X. Specifically:
In the spatial case, X must be a () matrix associated to data (a -vector);
In the spatio-temporal case, X must be a () matrix associated to data (a -matrix), where ;
In the bivariate case, X must be a () matrix associated to data (a -matrix), where .
The distance parameter allows different kinds of spatial distances:
Eucl, euclidean distance (default);
Chor, chordal distance;
Geod, geodesic distance.
The likelihood parameter represents the composite-likelihood configuration:
Conditional, composite likelihood formed by conditionals;
Marginal, composite likelihood formed by marginals (default);
Full, standard likelihood.
It must be coupled with type:
Pairwise, composite likelihood based on pairs;
Independence, composite likelihood based on independence;
Standard, standard likelihood.
Stochastic thinning of nearest-neighbor pairs can be enabled via p_neighb<1. The argument thin_method
controls the thinning scheme (default "bernoulli").
Returns an object of class GeoFit.
An object of class GeoFit is a list containing at most the following components:
bivariate |
Logical: |
clic |
The composite information criterion; if the full likelihood is considered then it coincides with AIC. |
coordx |
A |
coordy |
A |
coordt |
A |
coordx_dyn |
A list of dynamical (in time) spatial coordinates. |
conf.int |
Confidence intervals for standard maximum likelihood estimation. |
convergence |
A string that denotes if convergence is reached. |
copula |
The type of copula. |
corrmodel |
The correlation model. |
data |
The vector/matrix/array (or list) of data. |
distance |
The type of spatial distance. |
fixed |
A list of fixed parameters. |
iterations |
The number of iterations used by the numerical routine. |
likelihood |
The configuration of the composite likelihood. |
logCompLik |
The value of the log composite-likelihood at the maximum. |
maxdist |
The maximum spatial distance used in the weighted composite likelihood (or |
maxtime |
The order of temporal neighborhood in the composite likelihood computation. |
message |
Extra message passed from the numerical routines. |
model |
The density associated to the likelihood objects. |
missp |
|
n |
The number of trials/successes for (negative) binomial models. |
neighb |
The order of spatial neighborhood in the composite likelihood computation. |
ns |
The number of (different) location sites in the bivariate case. |
numcoord |
The number of spatial coordinates. |
numtime |
The number of temporal realisations. |
param |
A list of parameter estimates. |
radius |
The radius of the sphere in the case of great-circle distance. |
stderr |
Standard errors for standard maximum likelihood estimation. |
sensmat |
The sensitivity matrix. |
varcov |
The variance-covariance matrix of the estimates. |
type |
The type of likelihood objects. |
X |
The matrix of covariates. |
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
General Composite-likelihood:
Varin, C., Reid, N. and Firth, D. (2011). An Overview of Composite Likelihood Methods. Statistica Sinica, 21, 5–42.
Varin, C. and Vidoni, P. (2005) A Note on Composite Likelihood Inference and Model Selection. Biometrika, 92, 519–528.
Non Gaussian random fields:
Alegrıa A., Caro S., Bevilacqua M., Porcu E., Clarke J. (2017) Estimating covariance functions of multivariate skew-Gaussian random fields on the sphere. Spatial Statistics 22 388-402
Alegria A., Bevilacqua, M., Porcu, E. (2016) Likelihood-based inference for multivariate space-time wrapped-Gaussian fields. Journal of Statistical Computation and Simulation. 86(13), 2583–2597.
Bevilacqua M., Caamano C., Gaetan C. (2020) On modeling positive continuous data with spatio-temporal dependence. Environmetrics 31(7)
Bevilacqua M., Caamaño C., Arellano Valle R.B., Morales-Oñate V. (2020) Non-Gaussian Geostatistical Modeling using (skew) t Processes. Scandinavian Journal of Statistics.
Blasi F., Caamaño C., Bevilacqua M., Furrer R. (2022) A selective view of climatological data and likelihood estimation Spatial Statistics 10.1016/j.spasta.2022.100596
Bevilacqua M., Caamaño C., Arellano-Valle R. B., Camilo Gomez C. (2022) A class of random fields with two-piece marginal distributions for modeling point-referenced data with spatial outliers. Test 10.1007/s11749-021-00797-5
Morales-Navarrete D., Bevilacqua M., Caamaño C., Castro L.M. (2022) Modelling Point Referenced Spatial Count Data: A Poisson Process Approach TJournal of the American Statistical Association To appear
Caamaño C., Bevilacqua M., López C., Morales-Oñate V. (2023) Nearest neighbours weighted composite likelihood based on pairs for (non-)Gaussian massive spatial data with an application to Tukey-hh random fields estimation Computational Statistics and Data Analysis To appear
Bevilacqua M., Alvarado E., Caamaño C., (2023) A flexible Clayton-like spatial copula with application to bounded support data Journal of Multivariate Analysis To appear
Weighted Composite-likelihood for (non-)Gaussian random fields:
Bevilacqua, M. Gaetan, C., Mateu, J. and Porcu, E. (2012) Estimating space and space-time covariance functions for large data sets: a weighted composite likelihood approach. Journal of the American Statistical Association, Theory & Methods, 107, 268–280.
Bevilacqua, M., Gaetan, C. (2015) Comparing composite likelihood methods based on pairs for spatial Gaussian random fields. Statistics and Computing, 25(5), 877-892.
Caamaño C., Bevilacqua M., López C., Morales-Oñate V. (2023) Nearest neighbours weighted composite likelihood based on pairs for (non-)Gaussian massive spatial data with an application to Tukey-hh random fields estimation Computational Statistics and Data Analysis To appear
library(GeoModels) ############################################################### ############ Examples of spatial Gaussian random fieldss ################ ############################################################### # Define the spatial-coordinates of the points: set.seed(3) N=300 # number of location sites x <- runif(N, 0, 1) y <- runif(N, 0, 1) coords <- cbind(x,y) # Define spatial matrix covariates and regression parameters X=cbind(rep(1,N),runif(N)) mean <- 0.2 mean1 <- -0.5 # Set the covariance model's parameters: corrmodel <- "Matern" sill <- 1 nugget <- 0 scale <- 0.2/3 smooth=0.5 param<-list(mean=mean,mean1=mean1,sill=sill,nugget=nugget,scale=scale,smooth=smooth) # Simulation of the spatial Gaussian random fields: data <- GeoSim(coordx=coords,corrmodel=corrmodel, param=param,X=X)$data ################################################################ ### ### Example 0. Maximum independence composite likelihood fitting of ### a Gaussian random fields (no dependence parameters) ### ############################################################### # setting starting parameters to be estimated start<-list(mean=mean,mean1=mean1,sill=sill) fit1 <- GeoFit(data=data,coordx=coords,likelihood="Marginal", type="Independence", start=start,X=X) print(fit1) ################################################################ ### ### Example 1. Maximum conditional pairwise likelihood fitting of ### a Gaussian random fields using Nelder-Mead ### ############################################################### # setting fixed and starting parameters to be estimated fixed<-list(nugget=nugget,smooth=smooth) start<-list(mean=mean,mean1=mean1,scale=scale,sill=sill) fit1 <- GeoFit(data=data,coordx=coords,corrmodel=corrmodel, neighb=3,likelihood="Conditional",optimizer="Nelder-Mead", type="Pairwise", start=start,fixed=fixed,X=X) print(fit1) ################################################################ ### ### Example 2. Standard Maximum likelihood fitting of ### a Gaussian random fields using nlminb ### ############################################################### # Define the spatial-coordinates of the points: set.seed(3) N=250 # number of location sites x <- runif(N, 0, 1) y <- runif(N, 0, 1) coords <- cbind(x,y) param<-list(mean=mean,sill=sill,nugget=nugget,scale=scale,smooth=smooth) data <- GeoSim(coordx=coords,corrmodel=corrmodel, param=param)$data # setting fixed and parameters to be estimated fixed<-list(nugget=nugget,smooth=smooth) start<-list(mean=mean,scale=scale,sill=sill) I=Inf lower<-list(mean=-I,scale=0,sill=0) upper<-list(mean=I,scale=I,sill=I) fit2 <- GeoFit(data=data,coordx=coords,corrmodel=corrmodel, optimizer="nlminb",upper=upper,lower=lower, likelihood="Full",type="Standard", start=start,fixed=fixed) print(fit2) ############################################################### ############ Examples of spatial non-Gaussian random fieldss ############# ############################################################### ################################################################ ### ### Example 3. Maximum pairwise likelihood fitting of a Weibull random fields ### with Generalized Wendland correlation with Nelder-Mead ### ############################################################### set.seed(524) # Define the spatial-coordinates of the points: N=300 x <- runif(N, 0, 1) y <- runif(N, 0, 1) coords <- cbind(x,y) X=cbind(rep(1,N),runif(N)) mean=1; mean1=2 # regression parameters nugget=0 shape=2 scale=0.2 smooth=0 model="Weibull" corrmodel="GenWend" param=list(mean=mean,mean1=mean1,scale=scale, shape=shape,nugget=nugget,power2=4,smooth=smooth) # Simulation of a non stationary weibull random fields: data <- GeoSim(coordx=coords, corrmodel=corrmodel,model=model,X=X, param=param)$data fixed<-list(nugget=nugget,power2=4,smooth=smooth) start<-list(mean=mean,mean1=mean1,scale=scale,shape=shape) # Maximum independence likelihood: fit <- GeoFit(data=data, coordx=coords, X=X, likelihood="Marginal",type="Independence", corrmodel=corrmodel, ,model=model, start=start, fixed=fixed) print(unlist(fit$param)) ## estimating dependence parameter fixing vector mean parameter Xb=as.numeric(X %*% c(mean,mean1)) fixed<-list(nugget=nugget,power2=4,smooth=smooth,mean=Xb) start<-list(scale=scale,shape=shape) # Maximum conditional composite-likelihood fitting of the random fields: fit1 <- GeoFit(data=data,coordx=coords,corrmodel=corrmodel, model=model, neighb=3,likelihood="Conditional",type="Pairwise", optimizer="Nelder-Mead", start=start,fixed=fixed) print(unlist(fit1$param)) ### joint estimation of the dependence parameter and mean parameters fixed<-list(nugget=nugget,power2=4,smooth=smooth) start<-list(mean=mean,mean1=mean1,scale=scale,shape=shape) fit2 <- GeoFit(data=data,coordx=coords,corrmodel=corrmodel, model=model, neighb=3,likelihood="Conditional",type="Pairwise",X=X, optimizer="Nelder-Mead", start=start,fixed=fixed) print(unlist(fit2$param)) ################################################################ ### ### Example 4. Maximum pairwise likelihood fitting of ### a Skew-Gaussian spatial random fields with Wendland correlation ### ############################################################### set.seed(261) model="SkewGaussian" # Define the spatial-coordinates of the points: x <- runif(500, 0, 1) y <- runif(500, 0, 1) coords <- cbind(x,y) corrmodel="Wend0" mean=0;nugget=0 sill=1 skew=-4.5 power2=4 c_supp=0.2 # model parameters param=list(power2=power2,skew=skew, mean=mean,sill=sill,scale=c_supp,nugget=nugget) data <- GeoSim(coordx=coords, corrmodel=corrmodel,model=model, param=param)$data plot(density(data)) fixed=list(power2=power2,nugget=nugget) start=list(scale=c_supp,skew=skew,mean=mean,sill=sill) lower=list(scale=0,skew=-I,mean=-I,sill=0) upper=list(scale=I,skew=I,mean=I,sill=I) # Maximum marginal pairwise likelihood: fit1 <- GeoFit(data=data,coordx=coords,corrmodel=corrmodel, model=model, neighb=3,likelihood="Marginal",type="Pairwise", optimizer="bobyqa",lower=lower,upper=upper, start=start,fixed=fixed) print(unlist(fit1$param)) ################################################################ ### ### Example 5. Maximum pairwise likelihood fitting of ### a Bernoulli random fields with exponential correlation ### ############################################################### set.seed(422) N=250 x <- runif(N, 0, 1) y <- runif(N, 0, 1) coords <- cbind(x,y) mean=0.1; mean1=0.8; mean2=-0.5 # regression parameters X=cbind(rep(1,N),runif(N),runif(N)) # marix covariates corrmodel <- "Wend0" param=list(mean=mean,mean1=mean1,mean2=mean2,nugget=0,scale=0.2,power2=4) # Simulation of the spatial Binomial-Gaussian random fields: data <- GeoSim(coordx=coords, corrmodel=corrmodel, model="Binomial", n=1,X=X, param=param)$data ## estimating the marginal parameters using independence cl fixed <- list(power2=4,scale=0.2,nugget=0) start <- list(mean=mean,mean1=mean1,mean2=mean2) # Maximum independence likelihood: fit <- GeoFit(data=data, coordx=coords,n=1, X=X, likelihood="Marginal",type="Independence",corrmodel=corrmodel, ,model="Binomial", start=start, fixed=fixed) print(fit) ## estimating dependence parameter fixing vector mean parameter Xb=as.numeric(X %*% c(mean,mean1,mean2)) fixed <- list(nugget=0,power2=4,mean=Xb) start <- list(scale=0.2) # Maximum conditional pairwise likelihood: fit1 <- GeoFit(data=data, coordx=coords, corrmodel=corrmodel,n=1, likelihood="Conditional",type="Pairwise", neighb=3 ,model="Binomial", start=start, fixed=fixed) print(fit1) ## estimating jointly marginal and dependnce parameters fixed <- list(nugget=0,power2=4) start <- list(mean=mean,mean1=mean1,mean2=mean2,scale=0.2) # Maximum conditional pairwise likelihood: fit2 <- GeoFit(data=data, coordx=coords, corrmodel=corrmodel,n=1, X=X, likelihood="Conditional",type="Pairwise", neighb=3 ,model="Binomial", start=start, fixed=fixed) print(fit2) ############################################################### ######### Examples of Gaussian spatio-temporal random fieldss ########### ############################################################### set.seed(52) # Define the temporal sequence: time <- seq(1, 9, 1) # Define the spatial-coordinates of the points: x <- runif(20, 0, 1) y <- runif(20, 0, 1) coords=cbind(x,y) # Set the covariance model's parameters: scale_s=0.2/3;scale_t=1 smooth_s=0.5;smooth_t=0.5 sill=1 nugget=0 mean=0 param<-list(mean=0,scale_s=scale_s,scale_t=scale_t, smooth_t=smooth_t, smooth_s=smooth_s ,sill=sill,nugget=nugget) # Simulation of the spatial-temporal Gaussian random fields: data <- GeoSim(coordx=coords,coordt=time,corrmodel="Matern_Matern", param=param)$data ################################################################ ### ### Example 6. Maximum pairwise likelihood fitting of a ### space time Gaussian random fields with double-exponential correlation ### ############################################################### # Fixed parameters fixed<-list(nugget=nugget,smooth_s=smooth_s,smooth_t=smooth_t) # Starting value for the estimated parameters start<-list(mean=mean,scale_s=scale_s,scale_t=scale_t,sill=sill) # Maximum composite-likelihood fitting of the random fields: fit <- GeoFit(data=data,coordx=coords,coordt=time, corrmodel="Matern_Matern",maxtime=1,neighb=3, likelihood="Marginal",type="Pairwise", start=start,fixed=fixed) print(fit) ############################################################### ######### Examples of a bivariate Gaussian random fields ########### ############################################################### ################################################################ ### Example 7. Maximum pairwise likelihood fitting of a ### bivariate Gaussian random fields with separable Bivariate matern ### (cross) correlation model ############################################################### # Define the spatial-coordinates of the points: set.seed(89) x <- runif(300, 0, 1) y <- runif(300, 0, 1) coords=cbind(x,y) # parameters param=list(mean_1=0,mean_2=0,scale=0.1,smooth=0.5,sill_1=1,sill_2=1, nugget_1=0,nugget_2=0,pcol=0.2) # Simulation of a spatial bivariate Gaussian random fields: data <- GeoSim(coordx=coords, corrmodel="Bi_Matern_sep", param=param)$data # selecting fixed and estimated parameters fixed=list(mean_1=0,mean_2=0,nugget_1=0,nugget_2=0,smooth=0.5) start=list(sill_1=var(data[1,]),sill_2=var(data[2,]), scale=0.1,pcol=cor(data[1,],data[2,])) # Maximum marginal pairwise likelihood fitcl<- GeoFit(data=data, coordx=coords, corrmodel="Bi_Matern_sep", likelihood="Marginal",type="Pairwise", start=start,fixed=fixed, neighb=3) print(fitcl)library(GeoModels) ############################################################### ############ Examples of spatial Gaussian random fieldss ################ ############################################################### # Define the spatial-coordinates of the points: set.seed(3) N=300 # number of location sites x <- runif(N, 0, 1) y <- runif(N, 0, 1) coords <- cbind(x,y) # Define spatial matrix covariates and regression parameters X=cbind(rep(1,N),runif(N)) mean <- 0.2 mean1 <- -0.5 # Set the covariance model's parameters: corrmodel <- "Matern" sill <- 1 nugget <- 0 scale <- 0.2/3 smooth=0.5 param<-list(mean=mean,mean1=mean1,sill=sill,nugget=nugget,scale=scale,smooth=smooth) # Simulation of the spatial Gaussian random fields: data <- GeoSim(coordx=coords,corrmodel=corrmodel, param=param,X=X)$data ################################################################ ### ### Example 0. Maximum independence composite likelihood fitting of ### a Gaussian random fields (no dependence parameters) ### ############################################################### # setting starting parameters to be estimated start<-list(mean=mean,mean1=mean1,sill=sill) fit1 <- GeoFit(data=data,coordx=coords,likelihood="Marginal", type="Independence", start=start,X=X) print(fit1) ################################################################ ### ### Example 1. Maximum conditional pairwise likelihood fitting of ### a Gaussian random fields using Nelder-Mead ### ############################################################### # setting fixed and starting parameters to be estimated fixed<-list(nugget=nugget,smooth=smooth) start<-list(mean=mean,mean1=mean1,scale=scale,sill=sill) fit1 <- GeoFit(data=data,coordx=coords,corrmodel=corrmodel, neighb=3,likelihood="Conditional",optimizer="Nelder-Mead", type="Pairwise", start=start,fixed=fixed,X=X) print(fit1) ################################################################ ### ### Example 2. Standard Maximum likelihood fitting of ### a Gaussian random fields using nlminb ### ############################################################### # Define the spatial-coordinates of the points: set.seed(3) N=250 # number of location sites x <- runif(N, 0, 1) y <- runif(N, 0, 1) coords <- cbind(x,y) param<-list(mean=mean,sill=sill,nugget=nugget,scale=scale,smooth=smooth) data <- GeoSim(coordx=coords,corrmodel=corrmodel, param=param)$data # setting fixed and parameters to be estimated fixed<-list(nugget=nugget,smooth=smooth) start<-list(mean=mean,scale=scale,sill=sill) I=Inf lower<-list(mean=-I,scale=0,sill=0) upper<-list(mean=I,scale=I,sill=I) fit2 <- GeoFit(data=data,coordx=coords,corrmodel=corrmodel, optimizer="nlminb",upper=upper,lower=lower, likelihood="Full",type="Standard", start=start,fixed=fixed) print(fit2) ############################################################### ############ Examples of spatial non-Gaussian random fieldss ############# ############################################################### ################################################################ ### ### Example 3. Maximum pairwise likelihood fitting of a Weibull random fields ### with Generalized Wendland correlation with Nelder-Mead ### ############################################################### set.seed(524) # Define the spatial-coordinates of the points: N=300 x <- runif(N, 0, 1) y <- runif(N, 0, 1) coords <- cbind(x,y) X=cbind(rep(1,N),runif(N)) mean=1; mean1=2 # regression parameters nugget=0 shape=2 scale=0.2 smooth=0 model="Weibull" corrmodel="GenWend" param=list(mean=mean,mean1=mean1,scale=scale, shape=shape,nugget=nugget,power2=4,smooth=smooth) # Simulation of a non stationary weibull random fields: data <- GeoSim(coordx=coords, corrmodel=corrmodel,model=model,X=X, param=param)$data fixed<-list(nugget=nugget,power2=4,smooth=smooth) start<-list(mean=mean,mean1=mean1,scale=scale,shape=shape) # Maximum independence likelihood: fit <- GeoFit(data=data, coordx=coords, X=X, likelihood="Marginal",type="Independence", corrmodel=corrmodel, ,model=model, start=start, fixed=fixed) print(unlist(fit$param)) ## estimating dependence parameter fixing vector mean parameter Xb=as.numeric(X %*% c(mean,mean1)) fixed<-list(nugget=nugget,power2=4,smooth=smooth,mean=Xb) start<-list(scale=scale,shape=shape) # Maximum conditional composite-likelihood fitting of the random fields: fit1 <- GeoFit(data=data,coordx=coords,corrmodel=corrmodel, model=model, neighb=3,likelihood="Conditional",type="Pairwise", optimizer="Nelder-Mead", start=start,fixed=fixed) print(unlist(fit1$param)) ### joint estimation of the dependence parameter and mean parameters fixed<-list(nugget=nugget,power2=4,smooth=smooth) start<-list(mean=mean,mean1=mean1,scale=scale,shape=shape) fit2 <- GeoFit(data=data,coordx=coords,corrmodel=corrmodel, model=model, neighb=3,likelihood="Conditional",type="Pairwise",X=X, optimizer="Nelder-Mead", start=start,fixed=fixed) print(unlist(fit2$param)) ################################################################ ### ### Example 4. Maximum pairwise likelihood fitting of ### a Skew-Gaussian spatial random fields with Wendland correlation ### ############################################################### set.seed(261) model="SkewGaussian" # Define the spatial-coordinates of the points: x <- runif(500, 0, 1) y <- runif(500, 0, 1) coords <- cbind(x,y) corrmodel="Wend0" mean=0;nugget=0 sill=1 skew=-4.5 power2=4 c_supp=0.2 # model parameters param=list(power2=power2,skew=skew, mean=mean,sill=sill,scale=c_supp,nugget=nugget) data <- GeoSim(coordx=coords, corrmodel=corrmodel,model=model, param=param)$data plot(density(data)) fixed=list(power2=power2,nugget=nugget) start=list(scale=c_supp,skew=skew,mean=mean,sill=sill) lower=list(scale=0,skew=-I,mean=-I,sill=0) upper=list(scale=I,skew=I,mean=I,sill=I) # Maximum marginal pairwise likelihood: fit1 <- GeoFit(data=data,coordx=coords,corrmodel=corrmodel, model=model, neighb=3,likelihood="Marginal",type="Pairwise", optimizer="bobyqa",lower=lower,upper=upper, start=start,fixed=fixed) print(unlist(fit1$param)) ################################################################ ### ### Example 5. Maximum pairwise likelihood fitting of ### a Bernoulli random fields with exponential correlation ### ############################################################### set.seed(422) N=250 x <- runif(N, 0, 1) y <- runif(N, 0, 1) coords <- cbind(x,y) mean=0.1; mean1=0.8; mean2=-0.5 # regression parameters X=cbind(rep(1,N),runif(N),runif(N)) # marix covariates corrmodel <- "Wend0" param=list(mean=mean,mean1=mean1,mean2=mean2,nugget=0,scale=0.2,power2=4) # Simulation of the spatial Binomial-Gaussian random fields: data <- GeoSim(coordx=coords, corrmodel=corrmodel, model="Binomial", n=1,X=X, param=param)$data ## estimating the marginal parameters using independence cl fixed <- list(power2=4,scale=0.2,nugget=0) start <- list(mean=mean,mean1=mean1,mean2=mean2) # Maximum independence likelihood: fit <- GeoFit(data=data, coordx=coords,n=1, X=X, likelihood="Marginal",type="Independence",corrmodel=corrmodel, ,model="Binomial", start=start, fixed=fixed) print(fit) ## estimating dependence parameter fixing vector mean parameter Xb=as.numeric(X %*% c(mean,mean1,mean2)) fixed <- list(nugget=0,power2=4,mean=Xb) start <- list(scale=0.2) # Maximum conditional pairwise likelihood: fit1 <- GeoFit(data=data, coordx=coords, corrmodel=corrmodel,n=1, likelihood="Conditional",type="Pairwise", neighb=3 ,model="Binomial", start=start, fixed=fixed) print(fit1) ## estimating jointly marginal and dependnce parameters fixed <- list(nugget=0,power2=4) start <- list(mean=mean,mean1=mean1,mean2=mean2,scale=0.2) # Maximum conditional pairwise likelihood: fit2 <- GeoFit(data=data, coordx=coords, corrmodel=corrmodel,n=1, X=X, likelihood="Conditional",type="Pairwise", neighb=3 ,model="Binomial", start=start, fixed=fixed) print(fit2) ############################################################### ######### Examples of Gaussian spatio-temporal random fieldss ########### ############################################################### set.seed(52) # Define the temporal sequence: time <- seq(1, 9, 1) # Define the spatial-coordinates of the points: x <- runif(20, 0, 1) y <- runif(20, 0, 1) coords=cbind(x,y) # Set the covariance model's parameters: scale_s=0.2/3;scale_t=1 smooth_s=0.5;smooth_t=0.5 sill=1 nugget=0 mean=0 param<-list(mean=0,scale_s=scale_s,scale_t=scale_t, smooth_t=smooth_t, smooth_s=smooth_s ,sill=sill,nugget=nugget) # Simulation of the spatial-temporal Gaussian random fields: data <- GeoSim(coordx=coords,coordt=time,corrmodel="Matern_Matern", param=param)$data ################################################################ ### ### Example 6. Maximum pairwise likelihood fitting of a ### space time Gaussian random fields with double-exponential correlation ### ############################################################### # Fixed parameters fixed<-list(nugget=nugget,smooth_s=smooth_s,smooth_t=smooth_t) # Starting value for the estimated parameters start<-list(mean=mean,scale_s=scale_s,scale_t=scale_t,sill=sill) # Maximum composite-likelihood fitting of the random fields: fit <- GeoFit(data=data,coordx=coords,coordt=time, corrmodel="Matern_Matern",maxtime=1,neighb=3, likelihood="Marginal",type="Pairwise", start=start,fixed=fixed) print(fit) ############################################################### ######### Examples of a bivariate Gaussian random fields ########### ############################################################### ################################################################ ### Example 7. Maximum pairwise likelihood fitting of a ### bivariate Gaussian random fields with separable Bivariate matern ### (cross) correlation model ############################################################### # Define the spatial-coordinates of the points: set.seed(89) x <- runif(300, 0, 1) y <- runif(300, 0, 1) coords=cbind(x,y) # parameters param=list(mean_1=0,mean_2=0,scale=0.1,smooth=0.5,sill_1=1,sill_2=1, nugget_1=0,nugget_2=0,pcol=0.2) # Simulation of a spatial bivariate Gaussian random fields: data <- GeoSim(coordx=coords, corrmodel="Bi_Matern_sep", param=param)$data # selecting fixed and estimated parameters fixed=list(mean_1=0,mean_2=0,nugget_1=0,nugget_2=0,smooth=0.5) start=list(sill_1=var(data[1,]),sill_2=var(data[2,]), scale=0.1,pcol=cor(data[1,],data[2,])) # Maximum marginal pairwise likelihood fitcl<- GeoFit(data=data, coordx=coords, corrmodel="Bi_Matern_sep", likelihood="Marginal",type="Pairwise", start=start,fixed=fixed, neighb=3) print(fitcl)
Maximum weighted composite-likelihood fitting for Gaussian and some Non-Gaussian univariate spatial, spatio-temporal and bivariate spatial RFs. A first preliminary estimation is performed using independence composite-likelihood for the marginal parameters of the model. The estimates are then used as starting values in the second final estimation step. The function allows fixing any of the parameters and setting upper/lower bounds in the optimization.
GeoFit2(data, coordx, coordy=NULL, coordz=NULL, coordt=NULL, coordx_dyn=NULL, copula=NULL, corrmodel, distance="Eucl", fixed=NULL, anisopars=NULL, est.aniso=c(FALSE,FALSE), grid=FALSE, likelihood="Marginal", lower=NULL, maxdist=Inf, neighb=NULL, p_neighb=1, maxtime=Inf, memdist=TRUE, method="cholesky", model="Gaussian", n=1, onlyvar=FALSE, optimizer="Nelder-Mead", radius=1, score=FALSE, sensitivity=FALSE, sparse=FALSE, start=NULL, thin_method="bernoulli", type="Pairwise", upper=NULL, varest=FALSE, weighted=FALSE, X=NULL, spobj=NULL, spdata=NULL)GeoFit2(data, coordx, coordy=NULL, coordz=NULL, coordt=NULL, coordx_dyn=NULL, copula=NULL, corrmodel, distance="Eucl", fixed=NULL, anisopars=NULL, est.aniso=c(FALSE,FALSE), grid=FALSE, likelihood="Marginal", lower=NULL, maxdist=Inf, neighb=NULL, p_neighb=1, maxtime=Inf, memdist=TRUE, method="cholesky", model="Gaussian", n=1, onlyvar=FALSE, optimizer="Nelder-Mead", radius=1, score=FALSE, sensitivity=FALSE, sparse=FALSE, start=NULL, thin_method="bernoulli", type="Pairwise", upper=NULL, varest=FALSE, weighted=FALSE, X=NULL, spobj=NULL, spdata=NULL)
data |
A |
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of spatial coordinates; optional argument, default is |
coordz |
A numeric vector giving 1-dimension of spatial coordinates; optional argument, default is |
coordt |
A numeric vector assigning 1-dimension of temporal coordinates. Optional argument, default is |
coordx_dyn |
A list of |
copula |
String; the type of copula. It can be |
corrmodel |
String; the name of a correlation model, for the description see the Section Details. |
distance |
String; the name of the spatial distance. Default is |
fixed |
An optional named list giving the values of the parameters that will be considered as known values. The listed parameters for a given correlation function will not be estimated. |
anisopars |
A list of two elements: |
est.aniso |
A bivariate logical vector providing which anisotropic parameters must be estimated. |
grid |
Logical; if |
likelihood |
String; the configuration of the composite likelihood. |
lower |
An optional named list giving lower bounds for parameters when the optimizer is |
maxdist |
Numeric; an optional positive value indicating the maximum spatial distance considered in the composite likelihood computation. See the Section Details for more information. |
neighb |
Numeric; an optional positive integer indicating the order of neighborhood in the composite likelihood computation. See the Section Details for more information. |
p_neighb |
Numeric; a value in |
maxtime |
Numeric; an optional positive integer indicating the order of temporal neighborhood in the composite likelihood computation. |
memdist |
Logical; if |
method |
String; the type of matrix decomposition used in the likelihood computation. Default is |
model |
String; the type of RF and therefore the densities associated to the likelihood objects.
|
n |
Numeric; number of trials in a binomial RF; number of successes in a negative binomial RF. |
onlyvar |
Logical; if |
optimizer |
String; the optimization algorithm (see |
radius |
Numeric; the radius of the sphere in the case of lon-lat coordinates. Default value is |
score |
Logical; should score function be computed? Default is |
sensitivity |
Logical; if |
sparse |
Logical; if |
start |
An optional named list with initial values for parameters used by the numerical routines in the maximization procedure.
Default is |
thin_method |
String; thinning scheme used when |
.
type |
String; the type of the likelihood objects. If |
upper |
An optional named list giving upper bounds for parameters when the optimizer is |
varest |
Logical; if |
weighted |
Logical; if |
X |
Numeric; matrix of spatio(temporal) covariates in the linear mean specification. |
spobj |
An object of class |
spdata |
Character; the name of data in the |
The function GeoFit2 is similar to GeoFit.
However, GeoFit2 performs a preliminary estimation using maximum independence composite likelihood
for the marginal parameters of the model and then uses the obtained estimates as starting values in the final
weighted composite likelihood estimation (that includes both marginal and dependence parameters).
This provides robust starting values for the marginal parameters in the optimization algorithm.
Stochastic thinning of nearest-neighbor pairs can be enabled via p_neighb<1. The argument thin_method
controls the thinning scheme (default "bernoulli").
Returns an object of class GeoFit.
An object of class GeoFit is a list containing at most the following components:
bivariate |
Logical: |
clic |
The composite information criterion; if the full likelihood is considered then it coincides with AIC. |
coordx |
A |
coordy |
A |
coordt |
A |
coordx_dyn |
A list of dynamical (in time) spatial coordinates. |
conf.int |
Confidence intervals for standard maximum likelihood estimation. |
convergence |
A string that denotes if convergence is reached. |
copula |
The type of copula. |
corrmodel |
The correlation model. |
data |
The vector or matrix or array (or list) of data. |
distance |
The type of spatial distance. |
fixed |
A list of fixed parameters. |
iterations |
The number of iterations used by the numerical routine. |
likelihood |
The configuration of the composite likelihood. |
logCompLik |
The value of the log composite-likelihood at the maximum. |
maxdist |
The maximum spatial distance used in the weighted composite likelihood (or |
maxtime |
The order of temporal neighborhood in the composite likelihood computation. |
message |
Extra message passed from the numerical routines. |
model |
The density associated to the likelihood objects. |
missp |
|
n |
The number of trials in a binomial RF; the number of successes in a negative binomial RF. |
neighb |
The order of spatial neighborhood in the composite likelihood computation. |
ns |
The number of (different) location sites in the bivariate case. |
numcoord |
The number of spatial coordinates. |
numtime |
The number of temporal realisations of the RF. |
param |
A list of parameter estimates. |
radius |
The radius of the sphere in the case of great-circle distance. |
stderr |
Standard errors for standard maximum likelihood estimation. |
sensmat |
The sensitivity matrix. |
varcov |
The variance-covariance matrix of the estimates. |
type |
The type of the likelihood objects. |
X |
The matrix of covariates. |
Moreno Bevilacqua, [email protected], https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian Caamaño-Carrillo, [email protected], https://www.researchgate.net/profile/Christian-Caamano
library(GeoModels) ############################################################### ############ Examples of spatial Gaussian RFs ################ ############################################################### ################################################################ ### ### Example 1 : Maximum pairwise conditional likelihood fitting ### of a Gaussian RF with Matern correlation ### ############################################################### model="Gaussian" # Define the spatial-coordinates of the points: set.seed(3) N=400 # number of location sites x <- runif(N, 0, 1) set.seed(6) y <- runif(N, 0, 1) coords <- cbind(x,y) # Define spatial matrix covariates X=cbind(rep(1,N),runif(N)) # Set the covariance model's parameters: corrmodel <- "Matern" mean <- 0.2 mean1 <- -0.5 sill <- 1 nugget <- 0 scale <- 0.2/3 smooth=0.5 param<-list(mean=mean,mean1=mean1,sill=sill,nugget=nugget,scale=scale,smooth=smooth) # Simulation of the spatial Gaussian RF: data <- GeoSim(coordx=coords,model=model,corrmodel=corrmodel, param=param,X=X)$data fixed<-list(nugget=nugget,smooth=smooth) start<-list(mean=mean,mean1=mean1,scale=scale,sill=sill) ################################################################ ### ### Maximum pairwise likelihood fitting of ### Gaussian RFs with exponential correlation. ### ############################################################### fit1 <- GeoFit2(data=data,coordx=coords,corrmodel=corrmodel, optimizer="BFGS",neighb=3,likelihood="Conditional", type="Pairwise", start=start,fixed=fixed,X=X) print(fit1) ############################################################### ############ Examples of spatial non-Gaussian RFs ############# ############################################################### ################################################################ ### ### Example 2. Maximum pairwise likelihood fitting of ### a LogGaussian RF with Generalized Wendland correlation ### ############################################################### set.seed(524) # Define the spatial-coordinates of the points: N=500 x <- runif(N, 0, 1) y <- runif(N, 0, 1) coords <- cbind(x,y) X=cbind(rep(1,N),runif(N)) mean=1; mean1=2 # regression parameters nugget=0 sill=0.5 scale=0.2 smooth=0 model="LogGaussian" corrmodel="GenWend" param=list(mean=mean,mean1=mean1,sill=sill,scale=scale, nugget=nugget,power2=4,smooth=smooth) # Simulation of a non stationary LogGaussian RF: data <- GeoSim(coordx=coords, corrmodel=corrmodel,model=model,X=X, param=param)$data fixed<-list(nugget=nugget,power2=4,smooth=smooth) start<-list(mean=mean,mean1=mean1,scale=scale,sill=sill) I=Inf lower<-list(mean=-I,mean1=-I,scale=0,sill=0) upper<-list(mean= I,mean1= I,scale=I,sill=I) # Maximum pairwise composite-likelihood fitting of the RF: fit <- GeoFit2(data=data,coordx=coords,corrmodel=corrmodel, model=model, neighb=3,likelihood="Conditional",type="Pairwise",X=X, optimizer="nlminb",lower=lower,upper=upper, start=start,fixed=fixed) print(unlist(fit$param)) ################################################################ ### ### Example 3. Maximum pairwise likelihood fitting of ### SinhAsinh RFs with Wendland0 correlation ### ############################################################### set.seed(261) model="SinhAsinh" # Define the spatial-coordinates of the points: x <- runif(500, 0, 1) y <- runif(500, 0, 1) coords <- cbind(x,y) corrmodel="Wend0" mean=0;nugget=0 sill=1 skew=-0.5 tail=1.5 power2=4 c_supp=0.2 # model parameters param=list(power2=power2,skew=skew,tail=tail, mean=mean,sill=sill,scale=c_supp,nugget=nugget) data <- GeoSim(coordx=coords, corrmodel=corrmodel,model=model, param=param)$data plot(density(data)) fixed=list(power2=power2,nugget=nugget) start=list(scale=c_supp,skew=skew,tail=tail,mean=mean,sill=sill) # Maximum pairwise likelihood: fit1 <- GeoFit2(data=data,coordx=coords,corrmodel=corrmodel, model=model, neighb=3,likelihood="Marginal",type="Pairwise", start=start,fixed=fixed) print(unlist(fit1$param))library(GeoModels) ############################################################### ############ Examples of spatial Gaussian RFs ################ ############################################################### ################################################################ ### ### Example 1 : Maximum pairwise conditional likelihood fitting ### of a Gaussian RF with Matern correlation ### ############################################################### model="Gaussian" # Define the spatial-coordinates of the points: set.seed(3) N=400 # number of location sites x <- runif(N, 0, 1) set.seed(6) y <- runif(N, 0, 1) coords <- cbind(x,y) # Define spatial matrix covariates X=cbind(rep(1,N),runif(N)) # Set the covariance model's parameters: corrmodel <- "Matern" mean <- 0.2 mean1 <- -0.5 sill <- 1 nugget <- 0 scale <- 0.2/3 smooth=0.5 param<-list(mean=mean,mean1=mean1,sill=sill,nugget=nugget,scale=scale,smooth=smooth) # Simulation of the spatial Gaussian RF: data <- GeoSim(coordx=coords,model=model,corrmodel=corrmodel, param=param,X=X)$data fixed<-list(nugget=nugget,smooth=smooth) start<-list(mean=mean,mean1=mean1,scale=scale,sill=sill) ################################################################ ### ### Maximum pairwise likelihood fitting of ### Gaussian RFs with exponential correlation. ### ############################################################### fit1 <- GeoFit2(data=data,coordx=coords,corrmodel=corrmodel, optimizer="BFGS",neighb=3,likelihood="Conditional", type="Pairwise", start=start,fixed=fixed,X=X) print(fit1) ############################################################### ############ Examples of spatial non-Gaussian RFs ############# ############################################################### ################################################################ ### ### Example 2. Maximum pairwise likelihood fitting of ### a LogGaussian RF with Generalized Wendland correlation ### ############################################################### set.seed(524) # Define the spatial-coordinates of the points: N=500 x <- runif(N, 0, 1) y <- runif(N, 0, 1) coords <- cbind(x,y) X=cbind(rep(1,N),runif(N)) mean=1; mean1=2 # regression parameters nugget=0 sill=0.5 scale=0.2 smooth=0 model="LogGaussian" corrmodel="GenWend" param=list(mean=mean,mean1=mean1,sill=sill,scale=scale, nugget=nugget,power2=4,smooth=smooth) # Simulation of a non stationary LogGaussian RF: data <- GeoSim(coordx=coords, corrmodel=corrmodel,model=model,X=X, param=param)$data fixed<-list(nugget=nugget,power2=4,smooth=smooth) start<-list(mean=mean,mean1=mean1,scale=scale,sill=sill) I=Inf lower<-list(mean=-I,mean1=-I,scale=0,sill=0) upper<-list(mean= I,mean1= I,scale=I,sill=I) # Maximum pairwise composite-likelihood fitting of the RF: fit <- GeoFit2(data=data,coordx=coords,corrmodel=corrmodel, model=model, neighb=3,likelihood="Conditional",type="Pairwise",X=X, optimizer="nlminb",lower=lower,upper=upper, start=start,fixed=fixed) print(unlist(fit$param)) ################################################################ ### ### Example 3. Maximum pairwise likelihood fitting of ### SinhAsinh RFs with Wendland0 correlation ### ############################################################### set.seed(261) model="SinhAsinh" # Define the spatial-coordinates of the points: x <- runif(500, 0, 1) y <- runif(500, 0, 1) coords <- cbind(x,y) corrmodel="Wend0" mean=0;nugget=0 sill=1 skew=-0.5 tail=1.5 power2=4 c_supp=0.2 # model parameters param=list(power2=power2,skew=skew,tail=tail, mean=mean,sill=sill,scale=c_supp,nugget=nugget) data <- GeoSim(coordx=coords, corrmodel=corrmodel,model=model, param=param)$data plot(density(data)) fixed=list(power2=power2,nugget=nugget) start=list(scale=c_supp,skew=skew,tail=tail,mean=mean,sill=sill) # Maximum pairwise likelihood: fit1 <- GeoFit2(data=data,coordx=coords,corrmodel=corrmodel, model=model, neighb=3,likelihood="Marginal",type="Pairwise", start=start,fixed=fixed) print(unlist(fit1$param))
For a given set of spatial location sites (and temporal instants), the function computes optimal linear prediction and associated mean square error for the Gaussian and non Gaussian case.
GeoKrig(estobj=NULL,data, coordx, coordy=NULL, coordz=NULL, coordt=NULL, coordx_dyn=NULL, corrmodel,distance="Eucl", grid=FALSE, loc, method="cholesky", model="Gaussian", n=1,nloc=NULL,mse=FALSE, param, anisopars=NULL,radius=1, sparse=FALSE, time=NULL, type_krig="Simple",weigthed=TRUE,which=1, copula=NULL, X=NULL,Xloc=NULL,Mloc=NULL,spobj=NULL,spdata=NULL,varcov=NULL)GeoKrig(estobj=NULL,data, coordx, coordy=NULL, coordz=NULL, coordt=NULL, coordx_dyn=NULL, corrmodel,distance="Eucl", grid=FALSE, loc, method="cholesky", model="Gaussian", n=1,nloc=NULL,mse=FALSE, param, anisopars=NULL,radius=1, sparse=FALSE, time=NULL, type_krig="Simple",weigthed=TRUE,which=1, copula=NULL, X=NULL,Xloc=NULL,Mloc=NULL,spobj=NULL,spdata=NULL,varcov=NULL)
estobj |
An object of class Geofit that includes information about data, model and estimates. |
data |
A |
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordz |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordt |
A numeric vector giving 1-dimension of
temporal coordinates used for prediction; the default is |
coordx_dyn |
A list of |
corrmodel |
String; the name of a correlation model, for the description see the Section Details. |
distance |
String; the name of the spatial distance. The default
is |
grid |
Logical; if |
loc |
A numeric ( |
method |
String; the type of matrix decomposition used in the simulation. Default is |
n |
Numeric; the number of trials in a binomial random fields.
Default is |
nloc |
Numeric; the number of trials of the locations sites to be predicted in a binomial random fields.
Default is |
mse |
Logical; if |
model |
String; the type of RF and therefore the densities associated to the likelihood
objects. |
param |
A list of parameter values required for the correlation model.See the Section Details. |
anisopars |
A list of two elements: "angle" and "ratio" i.e. the anisotropy angle and the anisotropy ratio, respectively. |
radius |
Numeric: the radius of the sphere if coordinates are passed in lon/lat format;Default value is 1. |
sparse |
Logical; if |
time |
A numeric ( |
type_krig |
String; the type of kriging. If |
weigthed |
Logical; if |
which |
Numeric; In the case of bivariate cokriging it indicates which variable to predict. It can be 1 or 2 |
copula |
String; the type of copula. It can be "Clayton" or "Gaussian" |
X |
Numeric; Matrix of spatio(temporal)covariates in the linear mean specification. |
Xloc |
Numeric; Matrix of spatio(temporal)covariates in the linear mean specification associated to predicted locations. |
Mloc |
Numeric; Vector of spatio(temporal) estimated means associated to predicted locations. |
spobj |
An object of class sp or spacetime |
spdata |
Character:The name of data in the sp or spacetime object |
varcov |
Inverse of the covariance matrix estimates. |
Best linear unbiased predictor and associated mean square error is computed
for Gaussian and some non Gaussian cases.
Specifically, for a spatial or spatio-temporal or spatial bivariate dataset, given a set of spatial locations and
temporal istants and a correlation model
corrmodel with some fixed parameters and given the type of RF (model) the function computes
simple kriging, for the specified spatial locations
loc and temporal instants time, providing also the respective mean square error.
For the choice of the spatial or spatio temporal correlation model see details in GeoCovmatrix function.
The list param specifies mean and covariance parameters, see CorrParam and GeoCovmatrix for details. The type_krig parameter indicates the type of kriging. In the
case of simple kriging, the known mean can be specified by the parameter
mean in the list param (See examples).
Returns an object of class Kg.
An object of class Kg is a list containing
at most the following components:
bivariate |
|
coordx |
A |
coordy |
A |
coordz |
A |
coordt |
A |
corrmodel |
String: the correlation model; |
covmatrix |
The covariance matrix. |
data |
The vector or matrix or array of data used for prediction |
distance |
String: the type of spatial distance; |
grid |
|
loc |
A ( |
n |
The number of trial for Binomial RFs |
nozero |
In the case of sparse simple kriging the percentage of non zero values in the covariance matrix. Otherwise is NULL. |
numcoord |
Numeric:he number |
numloc |
Numeric: the number |
numtime |
Numeric: the number |
numt |
Numeric: the number |
model |
The type of RF, see |
param |
Numeric: The covariance parameters; |
pred |
A ( |
radius |
Numeric: the radius of the sphere if coordinates are pssed in lon/lat format; |
spacetime |
|
time |
A |
type |
String: the type of kriging (Standard). |
type_krig |
String: the type of kriging (simple or universal) |
mse |
A ( |
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
Gaetan, C. and Guyon, X. (2010) Spatial Statistics and Modelling. Spring Verlang, New York.
library(GeoModels) ################################################################ ########### Examples of spatial kriging ############ ################################################################ ################################################################ ### ### Example 1. Spatial kriging of a ### Gaussian random fields with Gen wendland correlation. ### ################################################################ model="Gaussian" set.seed(79) x = runif(300, 0, 1) y = runif(300, 0, 1) coords=cbind(x,y) # Set the exponential cov parameters: corrmodel = "GenWend" mean=0; sill=5; nugget=0 scale=0.2;smooth=0;power2=4 param=list(mean=mean,sill=sill,nugget=nugget,scale=scale,smooth=smooth,power2=power2) # Simulation of the spatial Gaussian random field: data = GeoSim(coordx=coords, corrmodel=corrmodel,model=model, param=param)$data ## estimation with pairwise likelihood fixed=list(nugget=nugget,smooth=0,power2=power2) start=list(mean=0,scale=scale,sill=1) I=Inf lower=list(mean=-I,scale=0,sill=0) upper=list(mean= I,scale=I,sill=I) # Maximum pairwise likelihood fitting : fit = GeoFit(data, coordx=coords, corrmodel=corrmodel,model=model, likelihood='Marginal', type='Pairwise',neighb=3, optimizer="nlminb", lower=lower,upper=upper, start=start,fixed=fixed) # locations to predict xx=seq(0,1,0.03) loc_to_pred=as.matrix(expand.grid(xx,xx)) ## first option #param=append(fit$param,fit$fixed) #pr=GeoKrig(loc=loc_to_pred,coordx=coords,corrmodel=corrmodel, # model=model,param=param,data=data,mse=TRUE) ## second option using object GeoFit pr=GeoKrig(fit,loc=loc_to_pred,mse=TRUE) colour = rainbow(100) opar=par(no.readonly = TRUE) par(mfrow=c(1,3)) quilt.plot(coords,data,col=colour) # simple kriging map prediction image.plot(xx, xx, matrix(pr$pred,ncol=length(xx)),col=colour, xlab="",ylab="", main=" Kriging ") # simple kriging MSE map prediction variance image.plot(xx, xx, matrix(pr$mse,ncol=length(xx)),col=colour, xlab="",ylab="",main="Std error") par(opar) ################################################################ ### ### Example 2. Spatial kriging of a Skew ### Gaussian random fields with Matern correlation. ### ################################################################ model="SkewGaussian" set.seed(79) x = runif(300, 0, 1) y = runif(300, 0, 1) coords=cbind(x,y) # Set the exponential cov parameters: corrmodel = "Matern" mean=0 sill=2 nugget=0 scale=0.1 smooth=0.5 skew=3 param=list(mean=mean,sill=sill,nugget=nugget,scale=scale,smooth=smooth,skew=skew) # Simulation of the spatial skew Gaussian random field: data = GeoSim(coordx=coords, corrmodel=corrmodel,model=model, param=param)$data fixed=list(nugget=nugget,smooth=smooth) start=list(mean=0,scale=scale,sill=1,skew=skew) I=Inf lower=list(mean=-I,scale=0,sill=0,skew=-I) upper=list(mean= I,scale=I,sill=I,skew=I) # Maximum pairwise likelihood fitting : fit = GeoFit2(data, coordx=coords, corrmodel=corrmodel,model=model, likelihood='Marginal', type='Pairwise',neighb=3, optimizer="nlminb", lower=lower,upper=upper, start=start,fixed=fixed) # locations to predict xx=seq(0,1,0.03) loc_to_pred=as.matrix(expand.grid(xx,xx)) ## optimal linear kriging pr=GeoKrig(fit,loc=loc_to_pred,mse=TRUE) colour = rainbow(100) opar=par(no.readonly = TRUE) par(mfrow=c(1,3)) quilt.plot(coords,data,col=colour) # simple kriging map prediction image.plot(xx, xx, matrix(pr$pred,ncol=length(xx)),col=colour, xlab="",ylab="", main=" Kriging ") # simple kriging MSE map prediction variance image.plot(xx, xx, matrix(pr$mse,ncol=length(xx)),col=colour, xlab="",ylab="",main="Std error") par(opar) ################################################################ ### ### Example 3. Spatial kriging of a ### Gamma random field with mean spatial regression ### ############################################################### set.seed(312) model="Gamma" corrmodel = "GenWend" # Define the spatial-coordinates of the points: NN=300 coords=cbind(runif(NN),runif(NN)) ## matrix covariates a0=rep(1,NN) a1=runif(NN,0,1) X=cbind(a0,a1) ##Set model parameters shape=2 ## regression parameters mean = 1;mean1= -0.2 # correlation parameters nugget = 0;power2=4 scale = 0.3;smooth=0 ## simulation param=list(shape=shape,nugget=nugget,mean=mean,mean1=mean1, scale=scale,power2=power2,smooth=smooth) data = GeoSim(coordx=coords,corrmodel=corrmodel, param=param, model=model,X=X)$data #####starting and fixed parameters fixed=list(nugget=nugget,power2=power2,smooth=smooth) start=list(mean=mean,mean1=mean1, scale=scale,shape=shape) ## estimation with pairwise likelihood fit2 = GeoFit(data=data,coordx=coords,corrmodel=corrmodel,X=X, neighb=3,likelihood="Conditional",type="Pairwise", start=start,fixed=fixed, model = model) # locations to predict with associated covariates xx=seq(0,1,0.03) loc_to_pred=as.matrix(expand.grid(xx,xx)) NP=nrow(loc_to_pred) a0=rep(1,NP) a1=runif(NP,0,1) Xloc=cbind(a0,a1) #optimal linear kriging pr=GeoKrig(fit2,loc=loc_to_pred,Xloc=Xloc,sparse=TRUE,mse=TRUE) ## map opar=par(no.readonly = TRUE) par(mfrow=c(1,3)) quilt.plot(coords,data,main="Data") map=matrix(pr$pred,ncol=length(xx)) mapmse=matrix(pr$mse,ncol=length(xx)) image.plot(xx, xx, map, xlab="",ylab="",main="Kriging ") image.plot(xx, xx, mapmse, xlab="",ylab="",main="MSE") par(opar) ################################################################ ########### Examples of spatio temporal kriging ############ ################################################################ ################################################################ ### ### Example 4. Spatio temporal simple kriging of n locations ### sites and m temporal instants for a Gaussian random fields ### with estimated double Wendland correlation. ### ############################################################### model="Gaussian" # Define the spatial-coordinates of the points: x = runif(300, 0, 1) y = runif(300, 0, 1) coords=cbind(x,y) times=1:4 # Define model correlation modek and associated parameters corrmodel="Wend0_Wend0" param=list(nugget=0,mean=0,power2_s=4,power2_t=4, scale_s=0.2,scale_t=2,sill=1) # Simulation of the space time Gaussian random field: set.seed(31) data=GeoSim(coordx=coords,coordt=times,corrmodel=corrmodel,sparse=TRUE, param=param)$data # Maximum pairwise likelihood fitting of the space time random field: start = list(scale_s=0.15,scale_t=2,sill=1,mean=0) fixed = list(nugget=0,power2_s=4,power2_t=4) fit = GeoFit(data, coordx=coords, coordt=times, model=model, corrmodel=corrmodel, likelihood='Conditional', type='Pairwise',start=start,fixed=fixed, neighb=3,maxtime=1) # locations to predict xx=seq(0,1,0.04) loc_to_pred=as.matrix(expand.grid(xx,xx)) # Define the times to predict times_to_pred=2 pr=GeoKrig(fit,loc=loc_to_pred,time=times_to_pred,sparse=TRUE,mse=TRUE) opar=par(no.readonly = TRUE) par(mfrow=c(1,3)) zlim=c(-2.5,2.5) colour = rainbow(100) quilt.plot(coords,data[2,] ,col=colour,main = paste(" data at Time 2")) image.plot(xx, xx, matrix(pr$pred,ncol=length(xx)),col=colour, main = paste(" Kriging at Time 2"),ylab="") image.plot(xx, xx, matrix(pr$mse,ncol=length(xx)),col=colour, main = paste("Std err Time at time 2"),ylab="") par(opar) ################################################################ ### ### Example r. Spatial bivariate simple cokriging of n locations ### sites for a bivariate Gaussian random fields ### with estimated Matern correlation. ### ############################################################### #set.seed(6) #NN=1500 # number of spatial locations #x = runif(NN, 0, 1); #y = runif(NN, 0, 1) #coords=cbind(x,y) ## setting parameters #mean_1 = 2; mean_2= -1 #nugget_1 =0;nugget_2=0 #sill_1 =0.5; sill_2 =1; ### correlation parameters #CorrParam("Bi_Matern") #scale_1=0.2/3; scale_2=0.15/3; scale_12=0.5*(scale_2+scale_1) #smooth_1=smooth_2=smooth_12=0.5 #pcol = -0.4 #param= list(nugget_1=nugget_1,nugget_2=nugget_2, # sill_1=sill_1,sill_2=sill_2, # mean_1=mean_1,mean_2=mean_2, # smooth_1=smooth_1, smooth_2=smooth_2,smooth_12=smooth_12, # scale_1=scale_1, scale_2=scale_2,scale_12=scale_12, # pcol=pcol) ## simulation #data = GeoSim(coordx=coords, corrmodel="Bi_Matern",model=model,param=param)$data #fixed=list(mean_1=mean_1,mean_2=mean_2, nugget_1=nugget_1,nugget_2=nugget_2, # smooth_1=smooth_1, smooth_2=smooth_2,smooth_12=smooth_12) #start=list( sill_1=sill_1,sill_2=sill_2, # scale_1=scale_1,scale_2=scale_2,scale_12=scale_12, pcol=pcol) ## estimation with maximum likelihood #fit = GeoFit(data=data,coordx=coords, corrmodel="Bi_Matern", #likelihood="Marginal",type="Pairwise",optimizer="BFGS",neighb=5, #start=start,fixed=fixed) ###### co-kriging for the fist component ############## #xx=seq(0,1,0.022) #loc_to_pred=as.matrix(expand.grid(xx,xx)) #pr1 = GeoKrig(fit,which=1,mse=TRUE,loc=loc_to_pred) #opar=par(no.readonly = TRUE) #par(mfrow=c(1,2)) #zlim=c(-2.5,2.5) #colour = rainbow(100) #quilt.plot(coords,data[1,] ,col=colour,main = paste(" Fist component")) #quilt.plot(loc_to_pred,pr1$pred,col=colour, # main = paste(" Kriging first component"),ylab="") #par(opar)library(GeoModels) ################################################################ ########### Examples of spatial kriging ############ ################################################################ ################################################################ ### ### Example 1. Spatial kriging of a ### Gaussian random fields with Gen wendland correlation. ### ################################################################ model="Gaussian" set.seed(79) x = runif(300, 0, 1) y = runif(300, 0, 1) coords=cbind(x,y) # Set the exponential cov parameters: corrmodel = "GenWend" mean=0; sill=5; nugget=0 scale=0.2;smooth=0;power2=4 param=list(mean=mean,sill=sill,nugget=nugget,scale=scale,smooth=smooth,power2=power2) # Simulation of the spatial Gaussian random field: data = GeoSim(coordx=coords, corrmodel=corrmodel,model=model, param=param)$data ## estimation with pairwise likelihood fixed=list(nugget=nugget,smooth=0,power2=power2) start=list(mean=0,scale=scale,sill=1) I=Inf lower=list(mean=-I,scale=0,sill=0) upper=list(mean= I,scale=I,sill=I) # Maximum pairwise likelihood fitting : fit = GeoFit(data, coordx=coords, corrmodel=corrmodel,model=model, likelihood='Marginal', type='Pairwise',neighb=3, optimizer="nlminb", lower=lower,upper=upper, start=start,fixed=fixed) # locations to predict xx=seq(0,1,0.03) loc_to_pred=as.matrix(expand.grid(xx,xx)) ## first option #param=append(fit$param,fit$fixed) #pr=GeoKrig(loc=loc_to_pred,coordx=coords,corrmodel=corrmodel, # model=model,param=param,data=data,mse=TRUE) ## second option using object GeoFit pr=GeoKrig(fit,loc=loc_to_pred,mse=TRUE) colour = rainbow(100) opar=par(no.readonly = TRUE) par(mfrow=c(1,3)) quilt.plot(coords,data,col=colour) # simple kriging map prediction image.plot(xx, xx, matrix(pr$pred,ncol=length(xx)),col=colour, xlab="",ylab="", main=" Kriging ") # simple kriging MSE map prediction variance image.plot(xx, xx, matrix(pr$mse,ncol=length(xx)),col=colour, xlab="",ylab="",main="Std error") par(opar) ################################################################ ### ### Example 2. Spatial kriging of a Skew ### Gaussian random fields with Matern correlation. ### ################################################################ model="SkewGaussian" set.seed(79) x = runif(300, 0, 1) y = runif(300, 0, 1) coords=cbind(x,y) # Set the exponential cov parameters: corrmodel = "Matern" mean=0 sill=2 nugget=0 scale=0.1 smooth=0.5 skew=3 param=list(mean=mean,sill=sill,nugget=nugget,scale=scale,smooth=smooth,skew=skew) # Simulation of the spatial skew Gaussian random field: data = GeoSim(coordx=coords, corrmodel=corrmodel,model=model, param=param)$data fixed=list(nugget=nugget,smooth=smooth) start=list(mean=0,scale=scale,sill=1,skew=skew) I=Inf lower=list(mean=-I,scale=0,sill=0,skew=-I) upper=list(mean= I,scale=I,sill=I,skew=I) # Maximum pairwise likelihood fitting : fit = GeoFit2(data, coordx=coords, corrmodel=corrmodel,model=model, likelihood='Marginal', type='Pairwise',neighb=3, optimizer="nlminb", lower=lower,upper=upper, start=start,fixed=fixed) # locations to predict xx=seq(0,1,0.03) loc_to_pred=as.matrix(expand.grid(xx,xx)) ## optimal linear kriging pr=GeoKrig(fit,loc=loc_to_pred,mse=TRUE) colour = rainbow(100) opar=par(no.readonly = TRUE) par(mfrow=c(1,3)) quilt.plot(coords,data,col=colour) # simple kriging map prediction image.plot(xx, xx, matrix(pr$pred,ncol=length(xx)),col=colour, xlab="",ylab="", main=" Kriging ") # simple kriging MSE map prediction variance image.plot(xx, xx, matrix(pr$mse,ncol=length(xx)),col=colour, xlab="",ylab="",main="Std error") par(opar) ################################################################ ### ### Example 3. Spatial kriging of a ### Gamma random field with mean spatial regression ### ############################################################### set.seed(312) model="Gamma" corrmodel = "GenWend" # Define the spatial-coordinates of the points: NN=300 coords=cbind(runif(NN),runif(NN)) ## matrix covariates a0=rep(1,NN) a1=runif(NN,0,1) X=cbind(a0,a1) ##Set model parameters shape=2 ## regression parameters mean = 1;mean1= -0.2 # correlation parameters nugget = 0;power2=4 scale = 0.3;smooth=0 ## simulation param=list(shape=shape,nugget=nugget,mean=mean,mean1=mean1, scale=scale,power2=power2,smooth=smooth) data = GeoSim(coordx=coords,corrmodel=corrmodel, param=param, model=model,X=X)$data #####starting and fixed parameters fixed=list(nugget=nugget,power2=power2,smooth=smooth) start=list(mean=mean,mean1=mean1, scale=scale,shape=shape) ## estimation with pairwise likelihood fit2 = GeoFit(data=data,coordx=coords,corrmodel=corrmodel,X=X, neighb=3,likelihood="Conditional",type="Pairwise", start=start,fixed=fixed, model = model) # locations to predict with associated covariates xx=seq(0,1,0.03) loc_to_pred=as.matrix(expand.grid(xx,xx)) NP=nrow(loc_to_pred) a0=rep(1,NP) a1=runif(NP,0,1) Xloc=cbind(a0,a1) #optimal linear kriging pr=GeoKrig(fit2,loc=loc_to_pred,Xloc=Xloc,sparse=TRUE,mse=TRUE) ## map opar=par(no.readonly = TRUE) par(mfrow=c(1,3)) quilt.plot(coords,data,main="Data") map=matrix(pr$pred,ncol=length(xx)) mapmse=matrix(pr$mse,ncol=length(xx)) image.plot(xx, xx, map, xlab="",ylab="",main="Kriging ") image.plot(xx, xx, mapmse, xlab="",ylab="",main="MSE") par(opar) ################################################################ ########### Examples of spatio temporal kriging ############ ################################################################ ################################################################ ### ### Example 4. Spatio temporal simple kriging of n locations ### sites and m temporal instants for a Gaussian random fields ### with estimated double Wendland correlation. ### ############################################################### model="Gaussian" # Define the spatial-coordinates of the points: x = runif(300, 0, 1) y = runif(300, 0, 1) coords=cbind(x,y) times=1:4 # Define model correlation modek and associated parameters corrmodel="Wend0_Wend0" param=list(nugget=0,mean=0,power2_s=4,power2_t=4, scale_s=0.2,scale_t=2,sill=1) # Simulation of the space time Gaussian random field: set.seed(31) data=GeoSim(coordx=coords,coordt=times,corrmodel=corrmodel,sparse=TRUE, param=param)$data # Maximum pairwise likelihood fitting of the space time random field: start = list(scale_s=0.15,scale_t=2,sill=1,mean=0) fixed = list(nugget=0,power2_s=4,power2_t=4) fit = GeoFit(data, coordx=coords, coordt=times, model=model, corrmodel=corrmodel, likelihood='Conditional', type='Pairwise',start=start,fixed=fixed, neighb=3,maxtime=1) # locations to predict xx=seq(0,1,0.04) loc_to_pred=as.matrix(expand.grid(xx,xx)) # Define the times to predict times_to_pred=2 pr=GeoKrig(fit,loc=loc_to_pred,time=times_to_pred,sparse=TRUE,mse=TRUE) opar=par(no.readonly = TRUE) par(mfrow=c(1,3)) zlim=c(-2.5,2.5) colour = rainbow(100) quilt.plot(coords,data[2,] ,col=colour,main = paste(" data at Time 2")) image.plot(xx, xx, matrix(pr$pred,ncol=length(xx)),col=colour, main = paste(" Kriging at Time 2"),ylab="") image.plot(xx, xx, matrix(pr$mse,ncol=length(xx)),col=colour, main = paste("Std err Time at time 2"),ylab="") par(opar) ################################################################ ### ### Example r. Spatial bivariate simple cokriging of n locations ### sites for a bivariate Gaussian random fields ### with estimated Matern correlation. ### ############################################################### #set.seed(6) #NN=1500 # number of spatial locations #x = runif(NN, 0, 1); #y = runif(NN, 0, 1) #coords=cbind(x,y) ## setting parameters #mean_1 = 2; mean_2= -1 #nugget_1 =0;nugget_2=0 #sill_1 =0.5; sill_2 =1; ### correlation parameters #CorrParam("Bi_Matern") #scale_1=0.2/3; scale_2=0.15/3; scale_12=0.5*(scale_2+scale_1) #smooth_1=smooth_2=smooth_12=0.5 #pcol = -0.4 #param= list(nugget_1=nugget_1,nugget_2=nugget_2, # sill_1=sill_1,sill_2=sill_2, # mean_1=mean_1,mean_2=mean_2, # smooth_1=smooth_1, smooth_2=smooth_2,smooth_12=smooth_12, # scale_1=scale_1, scale_2=scale_2,scale_12=scale_12, # pcol=pcol) ## simulation #data = GeoSim(coordx=coords, corrmodel="Bi_Matern",model=model,param=param)$data #fixed=list(mean_1=mean_1,mean_2=mean_2, nugget_1=nugget_1,nugget_2=nugget_2, # smooth_1=smooth_1, smooth_2=smooth_2,smooth_12=smooth_12) #start=list( sill_1=sill_1,sill_2=sill_2, # scale_1=scale_1,scale_2=scale_2,scale_12=scale_12, pcol=pcol) ## estimation with maximum likelihood #fit = GeoFit(data=data,coordx=coords, corrmodel="Bi_Matern", #likelihood="Marginal",type="Pairwise",optimizer="BFGS",neighb=5, #start=start,fixed=fixed) ###### co-kriging for the fist component ############## #xx=seq(0,1,0.022) #loc_to_pred=as.matrix(expand.grid(xx,xx)) #pr1 = GeoKrig(fit,which=1,mse=TRUE,loc=loc_to_pred) #opar=par(no.readonly = TRUE) #par(mfrow=c(1,2)) #zlim=c(-2.5,2.5) #colour = rainbow(100) #quilt.plot(coords,data[1,] ,col=colour,main = paste(" Fist component")) #quilt.plot(loc_to_pred,pr1$pred,col=colour, # main = paste(" Kriging first component"),ylab="") #par(opar)
For a given set of spatial location sites (and temporal instants),
the function computes optmal local linear prediction and the associated mean squared error
for the Gaussian and non Gaussian case using a spatial (temporal) neighborhood
computed using the function GeoNeighborhood
GeoKrigloc(estobj=NULL,data, coordx, coordy=NULL, coordz=NULL,coordt=NULL, coordx_dyn=NULL, corrmodel, distance="Eucl", grid=FALSE, loc, neighb=NULL, maxdist=NULL, maxtime=NULL, method="cholesky", model="Gaussian", n=1,nloc=NULL, mse=FALSE, param, anisopars=NULL,radius=1, sparse=FALSE, time=NULL, type="Standard", type_krig="Simple",weigthed=TRUE, which=1, copula=NULL,X=NULL,Xloc=NULL,Mloc=NULL,varcov=NULL, spobj=NULL,spdata=NULL,parallel=FALSE,ncores=NULL,progress=TRUE)GeoKrigloc(estobj=NULL,data, coordx, coordy=NULL, coordz=NULL,coordt=NULL, coordx_dyn=NULL, corrmodel, distance="Eucl", grid=FALSE, loc, neighb=NULL, maxdist=NULL, maxtime=NULL, method="cholesky", model="Gaussian", n=1,nloc=NULL, mse=FALSE, param, anisopars=NULL,radius=1, sparse=FALSE, time=NULL, type="Standard", type_krig="Simple",weigthed=TRUE, which=1, copula=NULL,X=NULL,Xloc=NULL,Mloc=NULL,varcov=NULL, spobj=NULL,spdata=NULL,parallel=FALSE,ncores=NULL,progress=TRUE)
estobj |
An object of class Geofit that includes information about data, model and estimates. |
data |
A |
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordz |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordt |
A numeric vector giving 1-dimension of
temporal coordinates used for prediction; the default is |
coordx_dyn |
A list of |
corrmodel |
String; the name of a correlation model, for the description see the Section Details. |
distance |
String; the name of the spatial distance. The default
is |
grid |
Logical; if |
loc |
A numeric ( |
neighb |
Numeric; an optional positive integer indicating the order of the neighborhood. |
maxdist |
Numeric; an optional positive value indicating the distance in the spatial neighborhood. |
maxtime |
Numeric; an optional positive integer value indicating the order of the temporal neighborhood. |
method |
String; the type of matrix decomposition used in the simulation. Default is |
n |
Numeric; the number of trials in a binomial random fields.
Default is |
nloc |
Numeric; the number of trials of the locations sites to be predicted in the binomial random field. If missing then a rounded mean of n is considered. |
mse |
Logical; if |
model |
String; the type of RF and therefore the densities associated to the likelihood
objects. |
param |
A list of parameter values required for the correlation model.See the Section Details. |
anisopars |
A list of two elements: "angle" and "ratio" i.e. the anisotropy angle and the anisotropy ratio, respectively. |
radius |
Numeric: the radius of the sphere if coordinates are passed in lon/lat format;Default value is 1. |
sparse |
Logical; if |
time |
A numeric ( |
type |
String; if |
type_krig |
String; the type of kriging. If |
weigthed |
Logical; if |
which |
Numeric; In the case of bivariate (tapered) cokriging it indicates which variable to predict. It can be 1 or 2 |
copula |
String; the type of copula. It can be "Clayton" or "Gaussian" |
X |
Numeric; Matrix of spatio(temporal)covariates in the linear mean specification. |
Xloc |
Numeric; Matrix of spatio(temporal)covariates in the linear mean specification associated to predicted locations. |
Mloc |
Numeric; Vector of spatio(temporal) estimated means associated to predicted locations. |
varcov |
Inverse of the covariance matrix estimates. |
spobj |
An object of class sp or spacetime |
spdata |
Character:The name of data in the sp or spacetime object |
parallel |
Logical; if |
ncores |
Numeric; number of cores involved in parallelization. |
progress |
If TRUE then a progress bar is shown. |
This function use the GeoKrig with a
spatial or spatio-temporal neighborhood computed using the function GeoNeighborhood.
The neighborhood is specified with the option maxdist and maxtime.
Returns an object of class Kg.
An object of class Kg is a list containing
at most the following components:
bivariate |
|
coordx |
A |
coordy |
A |
coordz |
A |
coordt |
A |
corrmodel |
String: the correlation model; |
covmatrix |
The covariance matrix if |
data |
The vector or matrix or array of data used for prediction |
distance |
String: the type of spatial distance; |
grid |
|
loc |
A ( |
n |
The number of trial for Binomial RFs |
nozero |
In the case of tapered simple kriging the percentage of non zero values in the covariance matrix. Otherwise is NULL. |
numcoord |
Numeric:he number |
numloc |
Numeric: the number |
numtime |
Numeric: the number |
numt |
Numeric: the number |
model |
The type of RF, see |
param |
Numeric: The covariance parameters; |
pred |
A ( |
radius |
Numeric: the radius of the sphere if coordinates are pssed in lon/lat format; |
spacetime |
|
tapmod |
String: the taper model if |
time |
A |
type |
String: the type of kriging (Standard or Tapering). |
type_krig |
String: the type of kriging: Simple or Universal |
mse |
A ( |
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
Gaetan, C. and Guyon, X. (2010) Spatial Statistics and Modelling. Spring Verlang, New York. Furrer R., Genton, M.G. and Nychka D. (2006). Covariance Tapering for Interpolation of Large Spatial Datasets. Journal of Computational and Graphical Statistics, 15-3, 502–523.
################################################################ ############### Examples of Spatial local kriging ############# ################################################################ require(GeoModels) #### model="Gaussian" # Define the spatial-coordinates of the points: set.seed(759) x = runif(1000, 0, 1) y = runif(1000, 0, 1) coords=cbind(x,y) # Set the exponential cov parameters: corrmodel = "GenWend" mean=0; sill=1 nugget=0; scale=0.2 param=list(mean=mean,sill=sill,nugget=nugget,smooth=0, scale=scale,power2=4) # Simulation of the spatial Gaussian random field: data = GeoSim(coordx=coords, corrmodel=corrmodel, param=param)$data # Maximum pairwise likelihood fitting of the space time random field: start=list(scale=scale,sill=sill,mean=mean) fixed=list(power2=4,smooth=0,nugget=0) fit = GeoFit(data, coordx=coords, corrmodel=corrmodel, start=start,fixed=fixed, likelihood='Conditional', type='Pairwise', neighb=3) # locations to predict loc_to_pred=matrix(runif(8),4,2) ################################################################ ### ### Example 1. Comparing spatial kriging with local kriging for ### a Gaussian random field with GenWend correlation. ### ############################################################### param=append(fit$param,fit$fixed) pr=GeoKrig(fit,loc=loc_to_pred,mse=TRUE) pr_loc=GeoKrigloc(fit,loc=loc_to_pred,neighb=100,mse=TRUE) pr$pred; pr_loc$pred ############################################################ #### Example: spatio temporal Gaussian local kriging ###### ############################################################ require(GeoModels) require(fields) set.seed(78) coords=cbind(runif(100),runif(100)) coordt=seq(0,5,0.25) corrmodel="Matern_Matern" param=list(nugget=0,mean=0,scale_s=0.2/3,scale_t=0.25/3,sill=2, smooth_s=0.5,smooth_t=0.5) data = GeoSim(coordx=coords, coordt=coordt, corrmodel=corrmodel, param=param)$data # Maximum pairwise likelihood fitting of the space time random field: start = list(scale_s=0.2/3,scale_t=0.25,sill=2,mean=0) fixed = list(smooth_s=0.5,smooth_t=0.5,nugget=0) I=Inf lower=list(scale_s=0,scale_t=0,sill=0,mean=-I) upper=list(scale_s=I,scale_t=I,sill=I,mean=I) fit = GeoFit(data, coordx=coords, coordt=coordt, model=model, corrmodel=corrmodel, likelihood='Conditional', type='Pairwise',start=start,fixed=fixed, optimizer="nlminb",lower=lower,upper=upper, neighb=3,maxtime=1) ## four location to predict loc_to_pred=matrix(runif(8),4,2) ## three temporal instants to predict time=c(0.5,1.5,3.5) pr=GeoKrig(fit,loc=loc_to_pred,time=time,mse=TRUE) pr_loc=GeoKrigloc(fit,loc=loc_to_pred,time=time, neigh=25,maxtime=1, mse=TRUE) ## full and local prediction pr$pred pr_loc$pred ############################################################ #### Example: spatio bivariate Gaussian local cokriging ###### ############################################################ #set.seed(6) #NN=1500 # number of spatial locations #x = runif(NN, 0, 1); #y = runif(NN, 0, 1) #coords=cbind(x,y) ## setting parameters #mean_1 = 2; mean_2= -1 #nugget_1 =0;nugget_2=0 #sill_1 =0.5; sill_2 =1; ### correlation parameters #CorrParam("Bi_Matern") #scale_1=0.2/3; scale_2=0.15/3; scale_12=0.5*(scale_2+scale_1) #smooth_1=smooth_2=smooth_12=0.5 #pcol = -0.4 #param= list(nugget_1=nugget_1,nugget_2=nugget_2, # sill_1=sill_1,sill_2=sill_2, # mean_1=mean_1,mean_2=mean_2, # smooth_1=smooth_1, smooth_2=smooth_2,smooth_12=smooth_12, # scale_1=scale_1, scale_2=scale_2,scale_12=scale_12, # pcol=pcol) ## simulation #data = GeoSim(coordx=coords, corrmodel="Bi_Matern",model=model,param=param)$data #fixed=list(mean_1=mean_1,mean_2=mean_2, nugget_1=nugget_1,nugget_2=nugget_2, # smooth_1=smooth_1, smooth_2=smooth_2,smooth_12=smooth_12) #start=list( sill_1=sill_1,sill_2=sill_2, # scale_1=scale_1,scale_2=scale_2,scale_12=scale_12, pcol=pcol) ## estimation with maximum likelihood #fit = GeoFit(data=data,coordx=coords, corrmodel="Bi_Matern", # likelihood="Marginal",type="Pairwise",optimizer="BFGS",neighb=5, #start=start,fixed=fixed) ###### co-kriging for the fist component ############## #xx=seq(0,1,0.022) #loc_to_pred=as.matrix(expand.grid(xx,xx)) #pr1 = GeoKrigloc(fit,which=1,mse=TRUE,loc=loc_to_pred,neighb=100) #opar=par(no.readonly = TRUE) #par(mfrow=c(1,2)) #zlim=c(-2.5,2.5) #colour = rainbow(100) #quilt.plot(coords,data[1,] ,col=colour,main = paste(" Fist component")) #quilt.plot(loc_to_pred,pr1$pred,col=colour, # main = paste(" Kriging first component"),ylab="") #par(opar)################################################################ ############### Examples of Spatial local kriging ############# ################################################################ require(GeoModels) #### model="Gaussian" # Define the spatial-coordinates of the points: set.seed(759) x = runif(1000, 0, 1) y = runif(1000, 0, 1) coords=cbind(x,y) # Set the exponential cov parameters: corrmodel = "GenWend" mean=0; sill=1 nugget=0; scale=0.2 param=list(mean=mean,sill=sill,nugget=nugget,smooth=0, scale=scale,power2=4) # Simulation of the spatial Gaussian random field: data = GeoSim(coordx=coords, corrmodel=corrmodel, param=param)$data # Maximum pairwise likelihood fitting of the space time random field: start=list(scale=scale,sill=sill,mean=mean) fixed=list(power2=4,smooth=0,nugget=0) fit = GeoFit(data, coordx=coords, corrmodel=corrmodel, start=start,fixed=fixed, likelihood='Conditional', type='Pairwise', neighb=3) # locations to predict loc_to_pred=matrix(runif(8),4,2) ################################################################ ### ### Example 1. Comparing spatial kriging with local kriging for ### a Gaussian random field with GenWend correlation. ### ############################################################### param=append(fit$param,fit$fixed) pr=GeoKrig(fit,loc=loc_to_pred,mse=TRUE) pr_loc=GeoKrigloc(fit,loc=loc_to_pred,neighb=100,mse=TRUE) pr$pred; pr_loc$pred ############################################################ #### Example: spatio temporal Gaussian local kriging ###### ############################################################ require(GeoModels) require(fields) set.seed(78) coords=cbind(runif(100),runif(100)) coordt=seq(0,5,0.25) corrmodel="Matern_Matern" param=list(nugget=0,mean=0,scale_s=0.2/3,scale_t=0.25/3,sill=2, smooth_s=0.5,smooth_t=0.5) data = GeoSim(coordx=coords, coordt=coordt, corrmodel=corrmodel, param=param)$data # Maximum pairwise likelihood fitting of the space time random field: start = list(scale_s=0.2/3,scale_t=0.25,sill=2,mean=0) fixed = list(smooth_s=0.5,smooth_t=0.5,nugget=0) I=Inf lower=list(scale_s=0,scale_t=0,sill=0,mean=-I) upper=list(scale_s=I,scale_t=I,sill=I,mean=I) fit = GeoFit(data, coordx=coords, coordt=coordt, model=model, corrmodel=corrmodel, likelihood='Conditional', type='Pairwise',start=start,fixed=fixed, optimizer="nlminb",lower=lower,upper=upper, neighb=3,maxtime=1) ## four location to predict loc_to_pred=matrix(runif(8),4,2) ## three temporal instants to predict time=c(0.5,1.5,3.5) pr=GeoKrig(fit,loc=loc_to_pred,time=time,mse=TRUE) pr_loc=GeoKrigloc(fit,loc=loc_to_pred,time=time, neigh=25,maxtime=1, mse=TRUE) ## full and local prediction pr$pred pr_loc$pred ############################################################ #### Example: spatio bivariate Gaussian local cokriging ###### ############################################################ #set.seed(6) #NN=1500 # number of spatial locations #x = runif(NN, 0, 1); #y = runif(NN, 0, 1) #coords=cbind(x,y) ## setting parameters #mean_1 = 2; mean_2= -1 #nugget_1 =0;nugget_2=0 #sill_1 =0.5; sill_2 =1; ### correlation parameters #CorrParam("Bi_Matern") #scale_1=0.2/3; scale_2=0.15/3; scale_12=0.5*(scale_2+scale_1) #smooth_1=smooth_2=smooth_12=0.5 #pcol = -0.4 #param= list(nugget_1=nugget_1,nugget_2=nugget_2, # sill_1=sill_1,sill_2=sill_2, # mean_1=mean_1,mean_2=mean_2, # smooth_1=smooth_1, smooth_2=smooth_2,smooth_12=smooth_12, # scale_1=scale_1, scale_2=scale_2,scale_12=scale_12, # pcol=pcol) ## simulation #data = GeoSim(coordx=coords, corrmodel="Bi_Matern",model=model,param=param)$data #fixed=list(mean_1=mean_1,mean_2=mean_2, nugget_1=nugget_1,nugget_2=nugget_2, # smooth_1=smooth_1, smooth_2=smooth_2,smooth_12=smooth_12) #start=list( sill_1=sill_1,sill_2=sill_2, # scale_1=scale_1,scale_2=scale_2,scale_12=scale_12, pcol=pcol) ## estimation with maximum likelihood #fit = GeoFit(data=data,coordx=coords, corrmodel="Bi_Matern", # likelihood="Marginal",type="Pairwise",optimizer="BFGS",neighb=5, #start=start,fixed=fixed) ###### co-kriging for the fist component ############## #xx=seq(0,1,0.022) #loc_to_pred=as.matrix(expand.grid(xx,xx)) #pr1 = GeoKrigloc(fit,which=1,mse=TRUE,loc=loc_to_pred,neighb=100) #opar=par(no.readonly = TRUE) #par(mfrow=c(1,2)) #zlim=c(-2.5,2.5) #colour = rainbow(100) #quilt.plot(coords,data[1,] ,col=colour,main = paste(" Fist component")) #quilt.plot(loc_to_pred,pr1$pred,col=colour, # main = paste(" Kriging first component"),ylab="") #par(opar)
Given a set of spatial locations (and possibly temporal instants) the function returns the vector (or matrix) of kriging weights, the covariance matrix used in the kriging system and, optionally, the inverse of the left-hand-side matrix dor a specified neighborhhod
GeoKriglocWeights(coordx, coordy=NULL, coordz=NULL, coordt=NULL, coordx_dyn=NULL, corrmodel, distance="Eucl", grid=FALSE, loc, neighb=NULL, maxdist=NULL, maxtime=NULL, method="cholesky", model="Gaussian", n=1, nloc=NULL, param, anisopars=NULL, radius=1, sparse=FALSE, time=NULL, which=1, copula=NULL, X=NULL, Xloc=NULL, Mloc=NULL,parallel=TRUE)GeoKriglocWeights(coordx, coordy=NULL, coordz=NULL, coordt=NULL, coordx_dyn=NULL, corrmodel, distance="Eucl", grid=FALSE, loc, neighb=NULL, maxdist=NULL, maxtime=NULL, method="cholesky", model="Gaussian", n=1, nloc=NULL, param, anisopars=NULL, radius=1, sparse=FALSE, time=NULL, which=1, copula=NULL, X=NULL, Xloc=NULL, Mloc=NULL,parallel=TRUE)
coordx |
Numeric ( |
coordy |
Optional numeric vector giving an additional spatial coordinate
dimension. Ignored if |
coordz |
Optional numeric vector giving a third spatial coordinate dimension. |
coordt |
Optional numeric vector of temporal coordinates
(length |
coordx_dyn |
List of |
corrmodel |
Character string naming a valid correlation model.
See |
distance |
Character string specifying the spatial distance.
Default is |
grid |
Logical. If |
loc |
Numeric ( |
neighb |
Numeric; an optional positive integer indicating the order of the neighborhood. |
maxdist |
Numeric; an optional positive value indicating the distance in the spatial neighborhood. |
maxtime |
Numeric; an optional positive integer value indicating the order of the temporal neighborhood. |
method |
Character string indicating the matrix factorisation
used to solve the kriging system: |
model |
Character string specifying the random field type
(e.g.\ |
n |
Integer. Number of trials for Binomial random fields
(default |
nloc |
Integer. Number of trials for the prediction locations
in Binomial random fields (default |
param |
Named list of covariance and mean parameters.
See |
anisopars |
List with components |
radius |
Positive numeric value: sphere radius when
coordinates are lon/lat (default |
sparse |
Logical. If |
time |
Numeric vector of length |
which |
Integer ( |
copula |
Character string naming a copula when a non-Gaussian
dependence structure is used ( |
X |
Numeric matrix of spatio-temporal covariates at data locations. |
Xloc |
Numeric matrix of spatio-temporal covariates at prediction locations. |
Mloc |
Numeric; Vector of spatio(temporal) estimated means associated to predicted locations. |
parallel |
Logical; if |
The function builds the kriging system
where is the covariance matrix between observed
locations and the vector of
covariances between observed and prediction locations.
The solution is returned together with
and, optionally, .
Universal kriging with covariates is supported; in that case the
generalised least squares estimate of the mean parameters is appended.
No actual prediction is carried out; for full kriging use
GeoKrig.
An object of class KgWeights, a list containing:
weights |
Numeric vector (or matrix) of kriging weights. |
covmat |
Covariance matrix |
invcov |
Inverse of |
beta |
Estimated regression coefficients when covariates are supplied. |
type |
Character string: |
model |
Input |
corrmodel |
Input |
spacetime |
Logical: |
sparse |
Logical: was a sparse algorithm used? |
loc |
Copy of the |
time |
Copy of the |
Moreno Bevilacqua, [email protected], Víctor Morales-Oñate, [email protected], Christian Caamaño-Carrillo, [email protected]
Gaetan, C. and Guyon, X. (2010) Spatial Statistics and Modeling. Springer-Verlag, New York.
GeoKrig for full prediction,
GeoKrigloc for local prediction,
GeoCovmatrix for covariance model details,
Given a set of spatial locations (and possibly temporal instants) the function returns the vector (or matrix) of kriging weights, the covariance matrix used in the kriging system and, optionally, the inverse of the left-hand-side matrix.
GeoKrigWeights( coordx, coordy = NULL, coordz = NULL, coordt = NULL, coordx_dyn = NULL, corrmodel, distance = "Eucl", grid = FALSE, loc, method = "cholesky", model = "Gaussian", n = 1, nloc = NULL, param, anisopars = NULL, radius = 1, sparse = FALSE, time = NULL, which = 1, copula = NULL, X = NULL, Xloc = NULL, Mloc=NULL)GeoKrigWeights( coordx, coordy = NULL, coordz = NULL, coordt = NULL, coordx_dyn = NULL, corrmodel, distance = "Eucl", grid = FALSE, loc, method = "cholesky", model = "Gaussian", n = 1, nloc = NULL, param, anisopars = NULL, radius = 1, sparse = FALSE, time = NULL, which = 1, copula = NULL, X = NULL, Xloc = NULL, Mloc=NULL)
coordx |
Numeric ( |
coordy |
Optional numeric vector giving an additional spatial coordinate
dimension. Ignored if |
coordz |
Optional numeric vector giving a third spatial coordinate dimension. |
coordt |
Optional numeric vector of temporal coordinates
(length |
coordx_dyn |
List of |
corrmodel |
Character string naming a valid correlation model.
See |
distance |
Character string specifying the spatial distance.
Default is |
grid |
Logical. If |
loc |
Numeric ( |
method |
Character string indicating the matrix factorisation
used to solve the kriging system: |
model |
Character string specifying the random field type
(e.g.\ |
n |
Integer. Number of trials for Binomial random fields
(default |
nloc |
Integer. Number of trials for the prediction locations
in Binomial random fields (default |
param |
Named list of covariance and mean parameters.
See |
anisopars |
List with components |
radius |
Positive numeric value: sphere radius when
coordinates are lon/lat (default |
sparse |
Logical. If |
time |
Numeric vector of length |
which |
Integer ( |
copula |
Character string naming a copula when a non-Gaussian
dependence structure is used ( |
X |
Numeric matrix of spatio-temporal covariates at data locations. |
Xloc |
Numeric matrix of spatio-temporal covariates at prediction locations. |
Mloc |
Numeric; Vector of spatio(temporal) estimated means associated to predicted locations. |
The function builds the kriging system
where is the covariance matrix between observed
locations and the vector of
covariances between observed and prediction locations.
The solution is returned together with
and, optionally, .
Universal kriging with covariates is supported; in that case the
generalised least squares estimate of the mean parameters is appended.
No actual prediction is carried out; for full kriging use
GeoKrig.
An object of class KgWeights, a list containing:
weights |
Numeric vector (or matrix) of kriging weights. |
covmat |
Covariance matrix |
invcov |
Inverse of |
beta |
Estimated regression coefficients when covariates are supplied. |
type |
Character string: |
model |
Input |
corrmodel |
Input |
spacetime |
Logical: |
sparse |
Logical: was a sparse algorithm used? |
loc |
Copy of the |
time |
Copy of the |
Moreno Bevilacqua, [email protected], Víctor Morales-Oñate, [email protected], Christian Caamaño-Carrillo, [email protected]
Gaetan, C. and Guyon, X. (2010) Spatial Statistics and Modeling. Springer-Verlag, New York.
GeoKrig for full prediction,
GeoKrigloc for local prediction,
GeoCovmatrix for covariance model details,
library(GeoModels) ################################################################ ################################################################ ### ### Example 1. Spatial kriging weights for ### Gaussian random fields with Gen wendland correlation. ### ################################################################ model="Gaussian" set.seed(79) x = runif(300, 0, 1) y = runif(300, 0, 1) coords=cbind(x,y) corrmodel = "GenWend" mean=0; sill=5; nugget=0 scale=0.2;smooth=0;power2=4 param=list(mean=mean,sill=sill,nugget=nugget,scale=scale,smooth=smooth,power2=power2) # Simulation of the spatial Gaussian random field: data = GeoSim(coordx=coords, corrmodel=corrmodel,model=model, param=param)$data xx=seq(0,1,0.25) loc_to_pred=as.matrix(expand.grid(xx,xx)) W=GeoKrigWeights(,coordx=coords,loc=loc_to_pred,corrmodel=corrmodel, model=model,param=param) dim(W$weights) ### kriging weightslibrary(GeoModels) ################################################################ ################################################################ ### ### Example 1. Spatial kriging weights for ### Gaussian random fields with Gen wendland correlation. ### ################################################################ model="Gaussian" set.seed(79) x = runif(300, 0, 1) y = runif(300, 0, 1) coords=cbind(x,y) corrmodel = "GenWend" mean=0; sill=5; nugget=0 scale=0.2;smooth=0;power2=4 param=list(mean=mean,sill=sill,nugget=nugget,scale=scale,smooth=smooth,power2=power2) # Simulation of the spatial Gaussian random field: data = GeoSim(coordx=coords, corrmodel=corrmodel,model=model, param=param)$data xx=seq(0,1,0.25) loc_to_pred=as.matrix(expand.grid(xx,xx)) W=GeoKrigWeights(,coordx=coords,loc=loc_to_pred,corrmodel=corrmodel, model=model,param=param) dim(W$weights) ### kriging weights
The function deletes NA values from a spatial or spatio-temporal dataset
GeoNA(data, coordx, coordy=NULL,coordz=NULL, coordt=NULL, coordx_dyn=NULL, grid=FALSE, X=NULL, setting="spatial")GeoNA(data, coordx, coordy=NULL,coordz=NULL, coordt=NULL, coordx_dyn=NULL, grid=FALSE, X=NULL, setting="spatial")
data |
A |
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordz |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordt |
A numeric vector giving 1-dimension of
temporal coordinates; the default is |
coordx_dyn |
A list of |
grid |
Logical; if |
X |
Numeric; Matrix of spatio(temporal) covariates in the linear mean specification. |
setting |
String; are data spatial, spatio-temporal or spatial bivariate
(respectively |
Returns a list containing the following components:
coordx |
A |
coordy |
A |
coordt |
A |
data |
The data without NAvalues |
grid |
|
perc |
The percentage of NA values . |
setting |
Are data of spatial or spatio-temporal or spatial bivariate type |
X |
Covariates matrix |
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
library(GeoModels) # Define the spatial-coordinates of the points: set.seed(79) x = runif(200, 0, 1) y = runif(200, 0, 1) coords=cbind(x,y) # Set the exponential cov parameters: corrmodel = "Matern" mean=0 sill=1 nugget=0 scale=0.3/3 smooth=0.5 param=list(mean=mean,sill=sill,nugget=nugget,scale=scale,smooth=smooth) # Simulation of the spatial Gaussian random field: data = GeoSim(coordx=coords, corrmodel=corrmodel, param=param)$data data[1:100]=NA # removing NA a=GeoNA(data,coordx=coords) a$perc # percentage of NA values #a$coordx# spatial coordinates without missing values #a$data # data without missinng valueslibrary(GeoModels) # Define the spatial-coordinates of the points: set.seed(79) x = runif(200, 0, 1) y = runif(200, 0, 1) coords=cbind(x,y) # Set the exponential cov parameters: corrmodel = "Matern" mean=0 sill=1 nugget=0 scale=0.3/3 smooth=0.5 param=list(mean=mean,sill=sill,nugget=nugget,scale=scale,smooth=smooth) # Simulation of the spatial Gaussian random field: data = GeoSim(coordx=coords, corrmodel=corrmodel, param=param)$data data[1:100]=NA # removing NA a=GeoNA(data,coordx=coords) a$perc # percentage of NA values #a$coordx# spatial coordinates without missing values #a$data # data without missinng values
Given a set of spatio (temporal) locations and data, the procedure selects a spatio (temporal) neighborhood associated to some given spatio (temporal) locations. The neighborhood is computed using a fixed spatio (temporal) threshold or considering a fixed number of spatio (temporal) neighbors.
GeoNeighborhood(data=NULL, coordx, coordy=NULL,coordz=NULL, coordt=NULL, coordx_dyn=NULL, bivariate=FALSE, distance="Eucl", grid=FALSE, loc, neighb=NULL,maxdist=NULL, maxtime=NULL, radius=1, time=NULL, X=NULL,M=NULL,spobj=NULL,spdata=NULL, parallel=FALSE,ncores=NULL)GeoNeighborhood(data=NULL, coordx, coordy=NULL,coordz=NULL, coordt=NULL, coordx_dyn=NULL, bivariate=FALSE, distance="Eucl", grid=FALSE, loc, neighb=NULL,maxdist=NULL, maxtime=NULL, radius=1, time=NULL, X=NULL,M=NULL,spobj=NULL,spdata=NULL, parallel=FALSE,ncores=NULL)
data |
An optional |
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordz |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordt |
A numeric vector giving 1-dimension of
temporal coordinates. Optional argument, the default is |
coordx_dyn |
A list of |
bivariate |
If TRUE then data is considered as spatial bivariate data. |
distance |
String; the name of the spatial distance. The default
is |
grid |
Logical; if |
loc |
A ( |
neighb |
Numeric; an optional positive integer indicating the order of spatial neighborhood. |
maxdist |
Numeric; a positive value indicating the maximum spatial distance considered in the spatial neighborhood selection. |
maxtime |
Numeric; an optional positive integer indicating the order of temporal neighborhood. |
radius |
Numeric; a value indicating the radius of the sphere when using the great circle distance. Default value is 1. |
time |
Numeric; a value giving the temporal instant for which a neighborhood is computed. |
X |
Numeric; an optional Matrix of spatio (temporal) covariates. |
M |
Numeric; an estimated spatio (temporal) mean vector. |
spobj |
An object of class sp or spacetime |
spdata |
Character:The name of data in the sp or spacetime object |
parallel |
Logical; if |
ncores |
Numeric; number of cores involved in parallelization. |
Returns a list containing the following informations:
coordx |
A list of the matrix coordinates of the computed spatial neighborhood ; |
coordt |
A vector of the computed temporal neighborhood; |
data |
A list of the vector of data associated with the spatio (temporal) neighborhood; |
distance |
The type of spatial distance; |
numcoord |
The vector of numbers of location sites involved the spatial neighborhood; |
numtime |
The vector of numbers of temporal insttants involved the temporal neighborhood; |
radius |
The radius of the sphere if coordinates are passed in lon/lat format; |
spacetime |
|
X |
The matrix of spatio (temporal) covariates associated with the computed spatio (temporal) neighborhood; |
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
library(GeoModels) ########################################## #### Example: spatial neighborhood ###### ########################################## set.seed(75) coords=cbind(runif(500),runif(500)) param=list(nugget=0,mean=0,scale=0.2,sill=1, power2=4,smooth=1) data_all = GeoSim(coordx=coords, corrmodel="GenWend", param=param)$data plot(coords) ##two locations loc_to_pred=matrix(c(0.3,0.5,0.7,0.2),2,2) points(loc_to_pred,pch=20) neigh=GeoNeighborhood(data_all, coordx=coords, loc=loc_to_pred,neighb=8) # two Neighborhoods neigh$coordx points(neigh$coordx[[1]],pch=20,col="red") points(neigh$coordx[[2]],pch=20,col="blue") # associated data neigh$data ################################################### #### Example: spatio temporal spatial neighborhood# ################################################### set.seed(78) coords=matrix(runif(80),40,2) coordt=seq(0,6,0.25) param=list(nugget=0,mean=0,scale_s=0.2/3,scale_t=0.25/3,sill=2) data_all = GeoSim(coordx=coords, coordt=coordt,corrmodel="Exp_Exp", param=param)$data ## two location to predict loc_to_pred=matrix(runif(4),2,2) ## three temporal instants to predict time=c(1,2) plot(coords,xlim=c(0,1),ylim=c(0,1)) points(loc_to_pred,pch=20) neigh=GeoNeighborhood(data_all, coordx=coords, coordt=coordt, loc=loc_to_pred,time=time,neighb=3,maxtime=0.5) # first spatio-temporal neighborhoods # with associated data neigh$coordx[[1]] neigh$coordt[[1]] neigh$data[[1]] plot(coords) points(loc_to_pred,pch=20) points(neigh$coordx[[1]],col="red",pch=20) ################################################### #### Example: bivariate spatial neighborhood ##### ################################################### set.seed(79) coords=matrix(runif(100),50,2) param=list(mean_1=0,mean_2=0,scale=0.12,smooth=0.5, sill_1=1,sill_2=1,nugget_1=0,nugget_2=0,pcol=0.5) data_all = GeoSim(coordx=coords,corrmodel="Bi_matern_sep", param=param)$data ## two location to predict loc_to_pred=matrix(runif(4),2,2) neigh=GeoNeighborhood(data_all, coordx=coords,bivariate=TRUE, loc=loc_to_pred,neighb=5) plot(coords) points(loc_to_pred,pch=20) points(neigh$coordx[[1]],col="red",pch=20) points(neigh$coordx[[2]],col="red",pch=20)library(GeoModels) ########################################## #### Example: spatial neighborhood ###### ########################################## set.seed(75) coords=cbind(runif(500),runif(500)) param=list(nugget=0,mean=0,scale=0.2,sill=1, power2=4,smooth=1) data_all = GeoSim(coordx=coords, corrmodel="GenWend", param=param)$data plot(coords) ##two locations loc_to_pred=matrix(c(0.3,0.5,0.7,0.2),2,2) points(loc_to_pred,pch=20) neigh=GeoNeighborhood(data_all, coordx=coords, loc=loc_to_pred,neighb=8) # two Neighborhoods neigh$coordx points(neigh$coordx[[1]],pch=20,col="red") points(neigh$coordx[[2]],pch=20,col="blue") # associated data neigh$data ################################################### #### Example: spatio temporal spatial neighborhood# ################################################### set.seed(78) coords=matrix(runif(80),40,2) coordt=seq(0,6,0.25) param=list(nugget=0,mean=0,scale_s=0.2/3,scale_t=0.25/3,sill=2) data_all = GeoSim(coordx=coords, coordt=coordt,corrmodel="Exp_Exp", param=param)$data ## two location to predict loc_to_pred=matrix(runif(4),2,2) ## three temporal instants to predict time=c(1,2) plot(coords,xlim=c(0,1),ylim=c(0,1)) points(loc_to_pred,pch=20) neigh=GeoNeighborhood(data_all, coordx=coords, coordt=coordt, loc=loc_to_pred,time=time,neighb=3,maxtime=0.5) # first spatio-temporal neighborhoods # with associated data neigh$coordx[[1]] neigh$coordt[[1]] neigh$data[[1]] plot(coords) points(loc_to_pred,pch=20) points(neigh$coordx[[1]],col="red",pch=20) ################################################### #### Example: bivariate spatial neighborhood ##### ################################################### set.seed(79) coords=matrix(runif(100),50,2) param=list(mean_1=0,mean_2=0,scale=0.12,smooth=0.5, sill_1=1,sill_2=1,nugget_1=0,nugget_2=0,pcol=0.5) data_all = GeoSim(coordx=coords,corrmodel="Bi_matern_sep", param=param)$data ## two location to predict loc_to_pred=matrix(runif(4),2,2) neigh=GeoNeighborhood(data_all, coordx=coords,bivariate=TRUE, loc=loc_to_pred,neighb=5) plot(coords) points(loc_to_pred,pch=20) points(neigh$coordx[[1]],col="red",pch=20) points(neigh$coordx[[2]],col="red",pch=20)
The procedure performs different pairwise composite likelihood estimation using user's specified spatial or spatiotemporal neighboords in the weight function. The neighbor minimizing the sum of the squared differences between the estimated semivariogram and the empirical semivariogram is selected. The procedure needs an object obtained using the GeoVariogram function.
GeoNeighbSelect(data, coordx, coordy=NULL,coordz=NULL, coordt=NULL, coordx_dyn=NULL, copula=NULL,corrmodel=NULL, distance="Eucl",fixed=NULL,anisopars=NULL, est.aniso=c(FALSE,FALSE), grid=FALSE, likelihood='Marginal',lower=NULL, neighb=c(1,2,3,4,5),p_neighb=1,maxtime=Inf, memdist=TRUE,model='Gaussian', n=1, ncores=NULL,optimizer='Nelder-Mead', parallel=FALSE, bivariate=FALSE,radius=1, start=NULL,type='Pairwise', upper=NULL, weighted=FALSE,X=NULL,spobj=NULL,spdata=NULL,vario=NULL,progress=TRUE)GeoNeighbSelect(data, coordx, coordy=NULL,coordz=NULL, coordt=NULL, coordx_dyn=NULL, copula=NULL,corrmodel=NULL, distance="Eucl",fixed=NULL,anisopars=NULL, est.aniso=c(FALSE,FALSE), grid=FALSE, likelihood='Marginal',lower=NULL, neighb=c(1,2,3,4,5),p_neighb=1,maxtime=Inf, memdist=TRUE,model='Gaussian', n=1, ncores=NULL,optimizer='Nelder-Mead', parallel=FALSE, bivariate=FALSE,radius=1, start=NULL,type='Pairwise', upper=NULL, weighted=FALSE,X=NULL,spobj=NULL,spdata=NULL,vario=NULL,progress=TRUE)
data |
A |
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordz |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordt |
A numeric vector assigning 1-dimension of
temporal coordinates. Optional argument, the default is |
coordx_dyn |
A list of |
copula |
String; the type of copula. It can be "Clayton" or "Gaussian" |
corrmodel |
String; the name of a correlation model, for the description see the Section Details. |
distance |
String; the name of the spatial distance. The default is |
fixed |
An optional named list giving the values of the parameters that will be considered as known values. The listed parameters for a given correlation function will be not estimated. |
anisopars |
A list of two elements: "angle" and "ratio" i.e. the anisotropy angle and the anisotropy ratio, respectively. |
est.aniso |
A bivariate logical vector providing which anisotropic parameters must be estimated. |
grid |
Logical; if |
likelihood |
String; the configuration of the composite
likelihood. |
lower |
An optional named list giving the values for the lower bound of the space parameter
when the optimizer is |
neighb |
Numeric; a vector of positive integers indicating the order of neighborhood in the weight function of composite likelihood (see Section Details in GeoFit). |
p_neighb |
Numeric; a value in |
maxtime |
Numeric; an optional positive integer indicating the order of temporal neighborhood in the composite likelihood computation. |
memdist |
Logical; if |
model |
String; the type of random fields and therefore the densities associated to the likelihood
objects. |
n |
Numeric; number of trials in a binomial random fields; number of successes in a negative binomial random fields |
ncores |
Numeric; the number of cores involved in the parallelization |
optimizer |
String; the optimization algorithm
(see |
parallel |
Logical; if |
bivariate |
Logical; if |
radius |
Numeric; the radius of the sphere in the case of lon-lat coordinates. Default value is 1. |
start |
An optional named list with the initial values of the
parameters that are used by the numerical routines in maximization
procedure. |
type |
String; the type of the likelihood objects. If |
upper |
An optional named list giving the values for the upper bound
of the space parameter when the optimizer is or |
weighted |
Logical; if |
X |
Numeric; Matrix of spatio(temporal)covariates in the linear mean specification. |
spobj |
An object of class sp or spacetime |
spdata |
Character:The name of data in the sp or spacetime object |
vario |
An object of the class GeoVariogram obtained using the GeoVariogram function |
progress |
Logic; If TRUE then a progress bar is shown. |
The procedure performs different pairwise composite likelihood estimation using user's specified spatial or spatiotemporal neighboords in the weight function. The neighbor minimizing the sum of the squared differences between the estimated semivariogram and the empirical semivariogram is selected. The procedure needs an object obtained using the GeoVariogram function.
Returns a list containing the estimates for each neighborhood, the optimal neighborhood selected, and, if the selected neighborhood is large, a recommended alternative.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
library(GeoModels) ######### spatial case set.seed(32) N=500 # number of location sites x <- runif(N, 0, 1) y <- runif(N, 0, 1) coords <- cbind(x,y) mean <- 0.2 # Set the covariance model's parameters: corrmodel <- "Matern" sill <- 1;nugget <- 0 scale <- 0.2/3;smooth=0.5 model="Gaussian" param<-list(mean=mean,sill=sill,nugget=nugget,scale=scale,smooth=smooth) # Simulation data <- GeoSim(coordx=coords,corrmodel=corrmodel, param=param,model=model)$data I=Inf fixed<-list(nugget=nugget) start<-list(mean=mean,scale=scale,smooth=smooth,sill=sill) lower<-list(mean=-I,scale=0,sill=0,smooth=0) upper<-list(mean=I,scale=I,sill=I,smooth=I) vario = GeoVariogram(coordx=coords,data=data,maxdist=0.3,numbins=15) neighb=c(1,2,3,4) ## trying different neighbs selK <- GeoNeighbSelect(vario=vario,data=data,coordx=coords,corrmodel=corrmodel, model=model,neighb=neighb, likelihood="Conditional",type="Pairwise",parallel=FALSE, optimizer="nlminb",lower=lower,upper=upper, start=start,fixed=fixed) print(selK$best_neighb) ## selected neighborlibrary(GeoModels) ######### spatial case set.seed(32) N=500 # number of location sites x <- runif(N, 0, 1) y <- runif(N, 0, 1) coords <- cbind(x,y) mean <- 0.2 # Set the covariance model's parameters: corrmodel <- "Matern" sill <- 1;nugget <- 0 scale <- 0.2/3;smooth=0.5 model="Gaussian" param<-list(mean=mean,sill=sill,nugget=nugget,scale=scale,smooth=smooth) # Simulation data <- GeoSim(coordx=coords,corrmodel=corrmodel, param=param,model=model)$data I=Inf fixed<-list(nugget=nugget) start<-list(mean=mean,scale=scale,smooth=smooth,sill=sill) lower<-list(mean=-I,scale=0,sill=0,smooth=0) upper<-list(mean=I,scale=I,sill=I,smooth=I) vario = GeoVariogram(coordx=coords,data=data,maxdist=0.3,numbins=15) neighb=c(1,2,3,4) ## trying different neighbs selK <- GeoNeighbSelect(vario=vario,data=data,coordx=coords,corrmodel=corrmodel, model=model,neighb=neighb, likelihood="Conditional",type="Pairwise",parallel=FALSE, optimizer="nlminb",lower=lower,upper=upper, start=start,fixed=fixed) print(selK$best_neighb) ## selected neighbor
The function returns nearest-neighbour pair indices for spatial, spatio-temporal, or bivariate data. Optionally, a stochastic thinning mechanism can be applied to retain only a subset of the candidate nearest-neighbour pairs.
GeoNeighIndex(coordx, coordy=NULL, coordz=NULL, coordt=NULL, coordx_dyn=NULL, distance="Eucl", neighb=4, maxdist=NULL, maxtime=1, radius=1, bivariate=FALSE, p_neighb=1, thin_method="bernoulli")GeoNeighIndex(coordx, coordy=NULL, coordz=NULL, coordt=NULL, coordx_dyn=NULL, distance="Eucl", neighb=4, maxdist=NULL, maxtime=1, radius=1, bivariate=FALSE, p_neighb=1, thin_method="bernoulli")
coordx |
A numeric ( |
coordy |
A numeric vector giving one dimension of spatial coordinates; optional argument,
default is |
coordz |
A numeric vector giving one dimension of spatial coordinates; optional argument,
default is |
coordt |
A numeric vector giving the temporal coordinates. Optional argument,
default is |
coordx_dyn |
A list of numeric coordinate matrices containing spatial coordinates that may vary
over time. For spatio-temporal data, the list length must equal the number of time points. For
bivariate data with different spatial supports, the list must have length two, with one coordinate
matrix for each variable. Optional argument, default is |
distance |
String; the name of the spatial distance. Default is |
neighb |
Numeric; a positive integer indicating the nearest-neighbour order. In the bivariate case, it may also be a vector of length three, corresponding to within-variable 1, cross-variable, and within-variable 2 neighbourhood sizes. |
maxdist |
A numeric value denoting the maximum spatial distance; see Details. In the bivariate case, it may also be a vector of length three, corresponding to within-variable 1, cross-variable, and within-variable 2 distance thresholds. |
maxtime |
A numeric value denoting the maximum temporal distance; see Details. |
radius |
Numeric; a value indicating the radius of the sphere when using great-circle distances.
Default value is |
bivariate |
Logical; if |
p_neighb |
Numeric; a value in |
thin_method |
String; stochastic thinning scheme. Available options are |
The function first builds a candidate set of directed nearest-neighbour pairs. For purely spatial data,
the candidate set contains spatial nearest-neighbour pairs. For spatio-temporal data, the function includes
within-time spatial pairs, pure temporal same-site pairs, and cross-time spatio-temporal pairs up to
maxtime. For bivariate data, the function includes within-variable and cross-variable pairs.
If thin_method="bernoulli" and p_neighb<1, candidate pairs are retained independently with
calibrated Bernoulli probabilities. These probabilities may depend on pair features, such as spatial or
temporal lag, but they are calibrated so that the expected number of retained pairs is approximately
times the number of candidate pairs.
If thin_method="TargetBalanced", the function applies a hard-core greedy TargetBalanceding procedure. A random
permutation of the candidate pairs is scanned, and a pair is retained only if neither endpoint has already
been used by a previously retained pair. Therefore no observation index is used in more than one retained
pair. In this case p_neighb is not a marginal inclusion probability. It defines the nominal target
, where is the number of candidate pairs, but the final number of retained
pairs is bounded above by , where is the number of observation indices,
and may be smaller due to TargetBalanceding feasibility.
If thin_method="bernoulli" and p_neighb=1, no thinning is applied. If
thin_method="TargetBalanced" and p_neighb=1, the function attempts to retain as many pairs as allowed
by the hard-core TargetBalanceding constraint; this is not equivalent to no thinning.
Returns a list containing some of the following components:
colidx |
Vector of neighbour indices. |
rowidx |
Vector of target indices. |
lags |
Vector of spatial distances. |
lagt |
Vector of temporal distances, returned for spatio-temporal data. |
first |
Variable indicator for the first component of a bivariate pair, returned for bivariate data. |
second |
Variable indicator for the second component of a bivariate pair, returned for bivariate data. |
maxdist |
Maximum spatial distance used to construct the candidate pairs, when available. |
neighb |
Nearest-neighbour order used to construct the candidate pairs, when available. |
n_candidates |
Number of candidate pairs before thinning. |
n_retained |
Number of pairs retained after thinning or TargetBalanceding. |
target_retained |
Target number of retained pairs. For Bernoulli thinning this is the expected retained count. For hard-core TargetBalanceding this is the capped target count. |
target_retained_raw |
Uncapped target number of retained pairs, returned for hard-core TargetBalanceding. |
TargetBalanceding_cap |
Maximum number of endpoint-disjoint pairs, returned for hard-core TargetBalanceding. |
effective_fraction |
Observed retained fraction, |
expected_retained |
Expected retained count under calibrated Bernoulli thinning. |
thin_method |
Thinning method used. |
p_neighb_interpretation |
Text description of how |
Moreno Bevilacqua, [email protected], https://sites.google.com/view/moreno-bevilacqua/home, Victor Morales Onate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian Caamano-Carrillo, [email protected], https://www.researchgate.net/profile/Christian-Caamano
require(GeoModels) NN <- 400 coords <- cbind(runif(NN), runif(NN)) corrmodel <- "Matern" scale <- 0.5/3 param <- list(mean=0, sill=1, nugget=0, scale=scale, smooth=0.5) set.seed(951) data <- GeoSim(coordx=coords, corrmodel=corrmodel, model="Gaussian", param=param)$data sel <- GeoNeighIndex(coordx=coords, neighb=5) data1 <- data[sel$colidx] data2 <- data[sel$rowidx] ## plotting pairs that are neighbours of order 5 plot(data1, data2, xlab="", ylab="", main="h-scatterplot, neighb=5") ## Bernoulli thinning: p_neighb controls the expected retained fraction sel_ber <- GeoNeighIndex(coordx=coords, neighb=5, p_neighb=0.2, thin_method="bernoulli") data1 <- data[sel_ber$colidx] data2 <- data[sel_ber$rowidx] ## plotting a random fraction of pairs that are neighbours of order 5 plot(data1, data2, xlab="", ylab="", main="h-scatterplot, neighb=5")require(GeoModels) NN <- 400 coords <- cbind(runif(NN), runif(NN)) corrmodel <- "Matern" scale <- 0.5/3 param <- list(mean=0, sill=1, nugget=0, scale=scale, smooth=0.5) set.seed(951) data <- GeoSim(coordx=coords, corrmodel=corrmodel, model="Gaussian", param=param)$data sel <- GeoNeighIndex(coordx=coords, neighb=5) data1 <- data[sel$colidx] data2 <- data[sel$rowidx] ## plotting pairs that are neighbours of order 5 plot(data1, data2, xlab="", ylab="", main="h-scatterplot, neighb=5") ## Bernoulli thinning: p_neighb controls the expected retained fraction sel_ber <- GeoNeighIndex(coordx=coords, neighb=5, p_neighb=0.2, thin_method="bernoulli") data1 <- data[sel_ber$colidx] data2 <- data[sel_ber$rowidx] ## plotting a random fraction of pairs that are neighbours of order 5 plot(data1, data2, xlab="", ylab="", main="h-scatterplot, neighb=5")
Given a set of spatio (temporal) locations and data, the procedure select the spatial or spatiotemporal ouliers using a specific algorithm.
GeoOutlier(data, coordx, coordy=NULL,coordz=NULL, coordt=NULL, coordx_dyn=NULL, distance="Eucl", grid=FALSE, neighb=10,alpha=0.001, method="Z-Median", radius=1, bivariate=FALSE,X=NULL)GeoOutlier(data, coordx, coordy=NULL,coordz=NULL, coordt=NULL, coordx_dyn=NULL, distance="Eucl", grid=FALSE, neighb=10,alpha=0.001, method="Z-Median", radius=1, bivariate=FALSE,X=NULL)
data |
An optional |
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordz |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordt |
A numeric vector giving 1-dimension of
temporal coordinates. Optional argument, the default is |
coordx_dyn |
A list of |
distance |
String; the name of the spatial distance. The default
is |
grid |
Logical; if |
neighb |
Numeric; an optional positive integer indicating the order of neighborhoodused for Z-Median algorithm. |
alpha |
Numeric; a numeric value between 0 and 1 used for Z-Median algorithm. |
method |
String; The name of the algorithm for detecting spatial ouliers. Default is Z-median proposed in Chen et al. (2008) |
radius |
Numeric; a value indicating the radius of the sphere when using the great circle distance. Default value is 1. |
bivariate |
If TRUE then data is considered as spatial bivariate data. |
X |
Numeric; an optional Matrix of spatio (temporal) covariates. |
Return a matrix or a list containing the dected spatial or spatio-temporal outliers
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
Chen D, Lu C, Kou Y, Chen F (2008) On detecting spatial outliers. Geoinformatica 12:455–475
Bevilacqua M., Caamaño C., Arellano-Valle R. B., Camilo Gomez C. (2022) A class of random fields with two-piece marginal distributions for modeling point-referenced data with spatial outliers. Test 10.1007/s11749-021-00797-5
library(GeoModels) set.seed(1428) NN = 1500 coords = cbind(runif(NN),runif(NN)) ### scale=0.5/3 corrmodel = "Matern"; param = list(mean=0,sill=1,nugget=0,scale=scale,smooth=0.5,skew=0) data = GeoSim(coordx = coords,corrmodel = corrmodel, model = "TwoPieceGaussian",param = param)$data K=15 #parameter for outliers detection alghoritm alpha=0.005 #parameter for outliers detection alghoritm outlier=GeoOutlier(data=data, coordx = coords,neighb=K,alpha=alpha) quilt.plot(coords,data) for (i in 1:nrow(outlier)) plotrix::draw.circle(outlier[i,1], outlier[i,2],radius=0.02,lwd=2) nrow(outlier) # number of outliers param = list(mean=0,sill=1,nugget=0.4,scale=scale,smooth=0.5) data = GeoSim(coordx = coords,corrmodel = corrmodel, model = "Gaussian",param = param)$data K=15 #parameter for outliers detection alghoritm alpha=0.005 #parameter for outliers detection alghoritm outlier=GeoOutlier(data=data, coordx = coords,neighb=K,alpha=alpha) quilt.plot(coords,data) for (i in 1:nrow(outlier)) plotrix::draw.circle(outlier[i,1], outlier[i,2],radius=0.02,lwd=2) nrow(outlier) # number of outlierslibrary(GeoModels) set.seed(1428) NN = 1500 coords = cbind(runif(NN),runif(NN)) ### scale=0.5/3 corrmodel = "Matern"; param = list(mean=0,sill=1,nugget=0,scale=scale,smooth=0.5,skew=0) data = GeoSim(coordx = coords,corrmodel = corrmodel, model = "TwoPieceGaussian",param = param)$data K=15 #parameter for outliers detection alghoritm alpha=0.005 #parameter for outliers detection alghoritm outlier=GeoOutlier(data=data, coordx = coords,neighb=K,alpha=alpha) quilt.plot(coords,data) for (i in 1:nrow(outlier)) plotrix::draw.circle(outlier[i,1], outlier[i,2],radius=0.02,lwd=2) nrow(outlier) # number of outliers param = list(mean=0,sill=1,nugget=0.4,scale=scale,smooth=0.5) data = GeoSim(coordx = coords,corrmodel = corrmodel, model = "Gaussian",param = param)$data K=15 #parameter for outliers detection alghoritm alpha=0.005 #parameter for outliers detection alghoritm outlier=GeoOutlier(data=data, coordx = coords,neighb=K,alpha=alpha) quilt.plot(coords,data) for (i in 1:nrow(outlier)) plotrix::draw.circle(outlier[i,1], outlier[i,2],radius=0.02,lwd=2) nrow(outlier) # number of outliers
The procedure for a given GeoFit object applies the probability integral tranformation or the normal score transformation to the data
GeoPit(object,type="Uniform")GeoPit(object,type="Uniform")
object |
A GeoFit object |
.
type |
The type of transformation. If "Uniform" then the probability integral tranformation is performed. If "Gaussian" then the normal score transformation is performed. |
Returns an (updated) object of class GeoFit
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
library(GeoModels) model="Beta2" copula="Clayton" set.seed(221) NN=800 x <- runif(NN);y <- runif(NN) coords=cbind(x,y) shape=1.5 scale=0.2;power2=4 smooth=0 nugget=0 nu=8 corrmodel="GenWend" min=-2;max=1 mean=0 param=list(smooth=smooth,power2=power2, min=min,max=max, mean=mean, nu=nu, scale=scale,nugget=nugget,shape=shape) optimizer="nlminb" data <- GeoSimCopula(coordx=coords, corrmodel=corrmodel, model=model,param=param,copula=copula)$data I=50 fixed<-list(nugget=nugget,sill=1,scale=scale,smooth=smooth,power2=power2,min=min,max=max,nu=nu) start<-list(shape=shape,mean=mean) lower<-list(shape=0,mean=-I) upper<-list(shape=10,mean=I) #### maximum independence likelihood fit1 <- GeoFit(data=data,coordx=coords,corrmodel=corrmodel, model=model,likelihood="Marginal",type="Independence", optimizer=optimizer,lower=lower, upper=upper,copula=copula, start=start,fixed=fixed) ## PIT transformation aa=GeoPit(fit1,type="Uniform") hist(aa$data,freq=FALSE) GeoScatterplot(aa$data,coords,neighb=c(1,2)) ## Normal score transformation bb=GeoPit(fit1,type="Gaussian") hist(bb$data,freq=FALSE) GeoScatterplot(bb$data,coords,neighb=c(1,2))library(GeoModels) model="Beta2" copula="Clayton" set.seed(221) NN=800 x <- runif(NN);y <- runif(NN) coords=cbind(x,y) shape=1.5 scale=0.2;power2=4 smooth=0 nugget=0 nu=8 corrmodel="GenWend" min=-2;max=1 mean=0 param=list(smooth=smooth,power2=power2, min=min,max=max, mean=mean, nu=nu, scale=scale,nugget=nugget,shape=shape) optimizer="nlminb" data <- GeoSimCopula(coordx=coords, corrmodel=corrmodel, model=model,param=param,copula=copula)$data I=50 fixed<-list(nugget=nugget,sill=1,scale=scale,smooth=smooth,power2=power2,min=min,max=max,nu=nu) start<-list(shape=shape,mean=mean) lower<-list(shape=0,mean=-I) upper<-list(shape=10,mean=I) #### maximum independence likelihood fit1 <- GeoFit(data=data,coordx=coords,corrmodel=corrmodel, model=model,likelihood="Marginal",type="Independence", optimizer=optimizer,lower=lower, upper=upper,copula=copula, start=start,fixed=fixed) ## PIT transformation aa=GeoPit(fit1,type="Uniform") hist(aa$data,freq=FALSE) GeoScatterplot(aa$data,coords,neighb=c(1,2)) ## Normal score transformation bb=GeoPit(fit1,type="Gaussian") hist(bb$data,freq=FALSE) GeoScatterplot(bb$data,coords,neighb=c(1,2))
Based on a GeoFit object, the procedure plots a quantile-quantile plot or compares the fitted density with the histogram of the data. It is useful as diagnostic tool.
GeoQQ(fit,type="Q",add=FALSE,ylim=c(0,1),xlim=NULL,breaks=10,...)GeoQQ(fit,type="Q",add=FALSE,ylim=c(0,1),xlim=NULL,breaks=10,...)
fit |
A GeoFit object possibly obtained from |
type |
The type of plot. If Q then a qq-plot (default) is performed. If D then a comparison between histrogram and the estimated marginal density is performed |
add |
Logical; if TRUE the the estimated density ia added over an existing one |
ylim |
Numeric; a vector of length 2 used for the ylab parameter of the histogram plot. |
xlim |
Numeric; a vector of length 2 used for the xlab parameter of the histogram plot. |
breaks |
Numeric; an integer number specifyng the number of cells ofthe histogram plot if the option type=D is chosen. |
... |
Optional parameters passed to the plot function. |
Produces a plot. No values are returned.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
library(GeoModels) ################## ### Example 1 ################## set.seed(21) model="Tukeyh";tail=0.1 N=400 # number of location sites # Set the coordinates of the points: x = runif(N, 0, 1) y = runif(N, 0, 1) coords=cbind(x,y) # regression parameters mean = 5 mean1=0.8 X=cbind(rep(1,N),runif(N)) # correlation parameters: corrmodel = "Wend0" sill = 1 nugget = 0 scale = 0.3 power2=4 param=list(mean=mean,mean1=mean1, sill=sill, nugget=nugget, scale=scale,tail=tail,power2=power2) # Simulation of the Gaussian RF: data = GeoSim(coordx=coords, corrmodel=corrmodel, X=X,model=model,param=param)$data start=list(mean=mean,mean1=mean1, scale=scale,tail=tail) fixed=list(nugget=nugget,sill=sill,power2=power2) # Maximum composite-likelihood fitting fit = GeoFit(data,coordx=coords, corrmodel=corrmodel,model=model,X=X, likelihood="Conditional",type='Pairwise',start=start, fixed=fixed,neighb=4) res=GeoResiduals(fit) GeoQQ(res,type="Q") GeoQQ(res,type="D",lwd=2,ylim=c(0,0.5),breaks=20) ################## ### Example 2 ################## set.seed(21) model="Weibull";shape=1.5 N=600 # number of location sites # Set the coordinates of the points: x = runif(N, 0, 1) y = runif(N, 0, 1) coords=cbind(x,y) # regression parameters mean = 0 # correlation parameters: corrmodel = "Matern" smooth=0.5 nugget = 0 scale = 0.2/3 param=list(mean=mean, sill=1, nugget=nugget, scale=scale,smooth=smooth, shape=shape) # Simulation of the Gaussian RF: data = GeoSim(coordx=coords, corrmodel=corrmodel,model=model,param=param)$data start=list(mean=mean, scale=scale,shape=shape) I=Inf lower=list(mean=-I, scale=0,shape=0) upper=list(mean= I, scale=I,shape=I) I=Inf fixed=list(nugget=nugget,sill=1,smooth=smooth) # Maximum composite-likelihood fitting fit = GeoFit(data,coordx=coords, corrmodel=corrmodel,model=model, likelihood="Conditional",type='Pairwise',start=start, optimizer="nlminb",lower=lower,upper=upper, fixed=fixed,neighb=3) GeoQQ(fit,type="Q") GeoQQ(fit,type="D",lwd=2,ylim=c(0,1),breaks=20)library(GeoModels) ################## ### Example 1 ################## set.seed(21) model="Tukeyh";tail=0.1 N=400 # number of location sites # Set the coordinates of the points: x = runif(N, 0, 1) y = runif(N, 0, 1) coords=cbind(x,y) # regression parameters mean = 5 mean1=0.8 X=cbind(rep(1,N),runif(N)) # correlation parameters: corrmodel = "Wend0" sill = 1 nugget = 0 scale = 0.3 power2=4 param=list(mean=mean,mean1=mean1, sill=sill, nugget=nugget, scale=scale,tail=tail,power2=power2) # Simulation of the Gaussian RF: data = GeoSim(coordx=coords, corrmodel=corrmodel, X=X,model=model,param=param)$data start=list(mean=mean,mean1=mean1, scale=scale,tail=tail) fixed=list(nugget=nugget,sill=sill,power2=power2) # Maximum composite-likelihood fitting fit = GeoFit(data,coordx=coords, corrmodel=corrmodel,model=model,X=X, likelihood="Conditional",type='Pairwise',start=start, fixed=fixed,neighb=4) res=GeoResiduals(fit) GeoQQ(res,type="Q") GeoQQ(res,type="D",lwd=2,ylim=c(0,0.5),breaks=20) ################## ### Example 2 ################## set.seed(21) model="Weibull";shape=1.5 N=600 # number of location sites # Set the coordinates of the points: x = runif(N, 0, 1) y = runif(N, 0, 1) coords=cbind(x,y) # regression parameters mean = 0 # correlation parameters: corrmodel = "Matern" smooth=0.5 nugget = 0 scale = 0.2/3 param=list(mean=mean, sill=1, nugget=nugget, scale=scale,smooth=smooth, shape=shape) # Simulation of the Gaussian RF: data = GeoSim(coordx=coords, corrmodel=corrmodel,model=model,param=param)$data start=list(mean=mean, scale=scale,shape=shape) I=Inf lower=list(mean=-I, scale=0,shape=0) upper=list(mean= I, scale=I,shape=I) I=Inf fixed=list(nugget=nugget,sill=1,smooth=smooth) # Maximum composite-likelihood fitting fit = GeoFit(data,coordx=coords, corrmodel=corrmodel,model=model, likelihood="Conditional",type='Pairwise',start=start, optimizer="nlminb",lower=lower,upper=upper, fixed=fixed,neighb=3) GeoQQ(fit,type="Q") GeoQQ(fit,type="D",lwd=2,ylim=c(0,1),breaks=20)
The procedure return a GeoFit object associated to the estimated residuals. For a random field Y defined on the real line (Gaussian, Skew Gaussian, Tukeyh etcc) they are computed as (Y-m)/sqrt(v) where m and v are the estimated mean and variance respectively.
For a random field Y defined on the positive real line (Gamma, Weibull, Log-Gaussian) they are computed as Y/m where m is the estimated mean.
In the first case residuals have zero mean and unut variance with a specific distribution defined on the real line.
In the second case residuals have unit mean with a specific distribution defined on the positive real line.
When the function is coupled with the functions GeoQQ and GeoCovariogram, it is useful as diagnostic tool
(See examples).
GeoResiduals(fit)GeoResiduals(fit)
fit |
A fitted object obtained from the
|
Returns an (updated) object of class GeoFit
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
library(GeoModels) ########################### ###Example 1: Residuals using a Gaussian RF ########################### set.seed(211) model="Gaussian"; N=700 # number of location sites # Set the coordinates of the points: x = runif(N, 0, 1) y = runif(N, 0, 1) coords=cbind(x,y) # regression parameters mean = 5 mean1=0.8 X=cbind(rep(1,N),runif(N)) # correlation parameters: corrmodel = "Wend0" sill = 1 nugget = 0 scale = 0.3 power2=4 param=list(mean=mean,mean1=mean1, sill=sill, nugget=nugget, scale=scale,power2=power2) # Simulation of the Gaussian RF: data = GeoSim(coordx=coords, corrmodel=corrmodel, X=X,model=model,param=param)$data start=list(mean=mean,mean1=mean1, scale=scale,sill=sill) fixed=list(nugget=nugget,power2=power2) # Maximum composite-likelihood fitting fit = GeoFit(data,coordx=coords, corrmodel=corrmodel,model=model,X=X, likelihood="Conditional",type='Pairwise',start=start, fixed=fixed,neighb=3) res=GeoResiduals(fit) mean(res$data) # should be approx 0 var(res$data) # should be approx 1 # checking goodness of fit marginal model GeoQQ(res);GeoQQ(res,type="D",col="red",ylim=c(0,0.5),breaks=20); # Empirical estimation of the variogram for the residuals: vario = GeoVariogram(res$data,coordx=coords,maxdist=0.5) # Comparison between empirical amd estimated semivariogram for the residuals GeoCovariogram(res, show.vario=TRUE, vario=vario,pch=20) ########################### ###Example 2: Residuals using a Weibull RF ########################### model="Weibull";shape=4 N=700 # number of location sites # Set the coordinates of the points: x = runif(N, 0, 1) y = runif(N, 0, 1) coords=cbind(x,y) # regression parameters mean = 5 mean1=0.8 X=cbind(rep(1,N),runif(N)) # correlation parameters: corrmodel = "Wend0" sill = 1 nugget = 0 scale = 0.3 power2=4 param=list(mean=mean,mean1=mean1, sill=sill, nugget=nugget, scale=scale,shape=shape,power2=power2) # Simulation of the Gaussian RF: data = GeoSim(coordx=coords, corrmodel=corrmodel, X=X,model=model,param=param)$data I=Inf start=list(mean=mean,mean1=mean1, scale=scale,shape=shape) lower=list(mean=-I,mean1=-I, scale=0,shape=0) upper=list(mean= I,mean1= I, scale=I,shape=I) fixed=list(nugget=nugget,sill=sill,power2=power2) # Maximum composite-likelihood fitting fit = GeoFit(data,coordx=coords, corrmodel=corrmodel,model=model,X=X, likelihood="Conditional",type='Pairwise',start=start, optimizer="nlminb", lower=lower,upper=upper, fixed=fixed,neighb=3) res=GeoResiduals(fit) mean(res$data) # should be approx 1 # checking goodness of fit marginal model GeoQQ(res);GeoQQ(res,type="D",lwd=2,ylim=c(0,1.7),breaks=20); # Empirical estimation of the variogram for the residuals: vario = GeoVariogram(res$data,coordx=coords,maxdist=0.5) # Comparison between empirical amd estimated semivariogram for the residuals GeoCovariogram(res, show.vario=TRUE, vario=vario,pch=20)library(GeoModels) ########################### ###Example 1: Residuals using a Gaussian RF ########################### set.seed(211) model="Gaussian"; N=700 # number of location sites # Set the coordinates of the points: x = runif(N, 0, 1) y = runif(N, 0, 1) coords=cbind(x,y) # regression parameters mean = 5 mean1=0.8 X=cbind(rep(1,N),runif(N)) # correlation parameters: corrmodel = "Wend0" sill = 1 nugget = 0 scale = 0.3 power2=4 param=list(mean=mean,mean1=mean1, sill=sill, nugget=nugget, scale=scale,power2=power2) # Simulation of the Gaussian RF: data = GeoSim(coordx=coords, corrmodel=corrmodel, X=X,model=model,param=param)$data start=list(mean=mean,mean1=mean1, scale=scale,sill=sill) fixed=list(nugget=nugget,power2=power2) # Maximum composite-likelihood fitting fit = GeoFit(data,coordx=coords, corrmodel=corrmodel,model=model,X=X, likelihood="Conditional",type='Pairwise',start=start, fixed=fixed,neighb=3) res=GeoResiduals(fit) mean(res$data) # should be approx 0 var(res$data) # should be approx 1 # checking goodness of fit marginal model GeoQQ(res);GeoQQ(res,type="D",col="red",ylim=c(0,0.5),breaks=20); # Empirical estimation of the variogram for the residuals: vario = GeoVariogram(res$data,coordx=coords,maxdist=0.5) # Comparison between empirical amd estimated semivariogram for the residuals GeoCovariogram(res, show.vario=TRUE, vario=vario,pch=20) ########################### ###Example 2: Residuals using a Weibull RF ########################### model="Weibull";shape=4 N=700 # number of location sites # Set the coordinates of the points: x = runif(N, 0, 1) y = runif(N, 0, 1) coords=cbind(x,y) # regression parameters mean = 5 mean1=0.8 X=cbind(rep(1,N),runif(N)) # correlation parameters: corrmodel = "Wend0" sill = 1 nugget = 0 scale = 0.3 power2=4 param=list(mean=mean,mean1=mean1, sill=sill, nugget=nugget, scale=scale,shape=shape,power2=power2) # Simulation of the Gaussian RF: data = GeoSim(coordx=coords, corrmodel=corrmodel, X=X,model=model,param=param)$data I=Inf start=list(mean=mean,mean1=mean1, scale=scale,shape=shape) lower=list(mean=-I,mean1=-I, scale=0,shape=0) upper=list(mean= I,mean1= I, scale=I,shape=I) fixed=list(nugget=nugget,sill=sill,power2=power2) # Maximum composite-likelihood fitting fit = GeoFit(data,coordx=coords, corrmodel=corrmodel,model=model,X=X, likelihood="Conditional",type='Pairwise',start=start, optimizer="nlminb", lower=lower,upper=upper, fixed=fixed,neighb=3) res=GeoResiduals(fit) mean(res$data) # should be approx 1 # checking goodness of fit marginal model GeoQQ(res);GeoQQ(res,type="D",lwd=2,ylim=c(0,1.7),breaks=20); # Empirical estimation of the variogram for the residuals: vario = GeoVariogram(res$data,coordx=coords,maxdist=0.5) # Comparison between empirical amd estimated semivariogram for the residuals GeoCovariogram(res, show.vario=TRUE, vario=vario,pch=20)
The function produces h-scatterplots for the spatial, spatio-temporal and bivariate setting.
GeoScatterplot(data, coordx, coordy=NULL, coordz=NULL, coordt=NULL, coordx_dyn=NULL, distance='Eucl', grid=FALSE, maxdist=NULL,neighb=NULL, times=NULL, numbins=4, radius=1, bivariate=FALSE,...)GeoScatterplot(data, coordx, coordy=NULL, coordz=NULL, coordt=NULL, coordx_dyn=NULL, distance='Eucl', grid=FALSE, maxdist=NULL,neighb=NULL, times=NULL, numbins=4, radius=1, bivariate=FALSE,...)
data |
A |
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordz |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordt |
A numeric vector assigning 1-dimension of
temporal coordinates. Optional argument, the default is |
coordx_dyn |
A list of |
distance |
String; the name of the spatial distance. The default
is |
grid |
Logical; if |
maxdist |
A numeric value denoting the spatial maximum distance, see the Section Details. |
neighb |
Numeric; an optional positive integer indicating the order of neighborhood. See the Section Details for more information. |
times |
A numeric vector denoting the temporal instants involved Details. |
numbins |
A numeric value denoting the numbers of bins, see the Section Details. |
radius |
Numeric; a value indicating the radius of the sphere when using the great circle distance. Default value is 1. |
bivariate |
Logical; if |
... |
Optional parameters passed to the plot function. |
h-scatterplot is the plot of the pair values that are neighborhood of a certain order or with distances belonging to a certain interval. In the first case a (vector of) neighborhood must be specified. In the second case a maximum distance (maxdist) and a number of lag-bins (numbins) must be specified. The method based on neighborhoods is recommended in particular for large datasets.
Produces a plot. No values are returned.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
library(GeoModels) set.seed(514) NN = 600 coords = cbind(runif(NN),runif(NN)) param = list(mean=0,sill=1,nugget=0,power2=4,scale=0.4,smooth=0) corrmodel = "GenWend"; model = "Gaussian" data = GeoSim(coordx = coords,corrmodel = corrmodel, model = model,param = param)$data # h-scatterplots for given a vector of neighborhoods GeoScatterplot(data,coords,neighb=c(2,4))library(GeoModels) set.seed(514) NN = 600 coords = cbind(runif(NN),runif(NN)) param = list(mean=0,sill=1,nugget=0,power2=4,scale=0.4,smooth=0) corrmodel = "GenWend"; model = "Gaussian" data = GeoSim(coordx = coords,corrmodel = corrmodel, model = model,param = param)$data # h-scatterplots for given a vector of neighborhoods GeoScatterplot(data,coords,neighb=c(2,4))
The function computes predictive scores for observed validation values and predicted values, optionally using predictive variances or 95 percent prediction intervals.
GeoScores(data_to_pred, probject = NULL, pred = NULL, mse = NULL, score = c("pe", "crps", "intscore", "coverage"), lower95 = NULL, upper95 = NULL, threshold = 0.5, na.rm = TRUE)GeoScores(data_to_pred, probject = NULL, pred = NULL, mse = NULL, score = c("pe", "crps", "intscore", "coverage"), lower95 = NULL, upper95 = NULL, threshold = 0.5, na.rm = TRUE)
data_to_pred |
Numeric vector, matrix or array containing the observed validation values. Values are internally coerced to a numeric vector. |
probject |
Optional object of class |
pred |
Numeric vector, matrix or array of point predictions. This argument is
required when |
mse |
Optional numeric vector, matrix or array of prediction variances. Predictive
standard errors are computed as |
score |
Character vector specifying which predictive scores should be computed.
Possible values are |
lower95 |
Optional numeric vector, matrix or array containing the lower bounds of the
95 percent prediction intervals. If supplied together with
|
upper95 |
Optional numeric vector, matrix or array containing the upper bounds of the
95 percent prediction intervals. See |
threshold |
Numeric threshold used to compute the Brier score |
na.rm |
Logical. If |
GeoScores computes point prediction scores and probabilistic
predictive scores. Predictions and prediction variances can be supplied
directly through pred and mse, or indirectly through a
GeoKrig or GeoKrigloc object supplied to probject.
The point prediction option "pe" returns the mean absolute error and
the root mean squared prediction error.
The scores "brie", "lscore", "pit" and "crps"
are computed under the assumption that the predictive distribution is
Gaussian, with mean equal to the point prediction and standard deviation equal
to the predictive standard error. If mse is supplied, the predictive
standard error is sqrt(mse). If mse is absent and both
lower95 and upper95 are supplied, the predictive standard error
is approximated as
where and are the lower and upper bounds of the 95 percent
prediction interval.
The Brier score is computed for the binary event , using
the Gaussian predictive probability
, where is the
prediction and is the predictive standard error.
The logarithmic score is returned as the negative log predictive density, averaged over validation observations:
The CRPS is computed using the closed-form expression for a Gaussian predictive distribution.
For "pit", if probject is a GeoKrig or
GeoKrigloc object and GeoPit is available, the PIT values are
obtained through GeoPit(probject, type = "Uniform")$data; otherwise
they are computed as pnorm(data_to_pred, mean = pred, sd = sqrt(mse)).
The 95 percent interval score is computed as
with . If lower95 and upper95 are supplied,
they are used directly as and ; otherwise the interval is
computed from the Gaussian predictive distribution using pred and
mse. The empirical coverage is the proportion of validation values
falling inside the corresponding 95 percent intervals.
A list containing only the components requested through score. Possible
components are:
MAE |
Mean absolute error. Returned when |
RMSPE |
Root mean squared prediction error. Returned when |
Brier |
Brier score for the binary event |
LogScore |
Mean negative log predictive density under a Gaussian predictive
distribution. Returned when |
PIT |
Probability integral transform values. Returned when |
CRPS |
Mean continuous ranked probability score under a Gaussian predictive
distribution. Returned when |
IS95 |
Mean interval score for the 95 percent prediction intervals. Returned when
|
Cvg95 |
Empirical coverage of the 95 percent prediction intervals. Returned when
|
Moreno Bevilacqua, [email protected], https://sites.google.com/view/moreno-bevilacqua/home,
Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/,
Christian Caamaño-Carrillo, [email protected], https://www.researchgate.net/profile/Christian-Caamano
Gneiting, T. and Raftery, A. E. (2007). Strictly Proper Scoring Rules, Prediction, and Estimation. Journal of the American Statistical Association, 102, 359–378.
Heaton, M. J., Datta, A., Finley, A. O., Furrer, R., Guinness, J., Guhaniyogi, R., Gerber, F., Gramacy, R. B., Hammerling, D., Katzfuss, M., Lindgren, F., Nychka, D. W., Sun, F., and Zammit-Mangion, A. (2019). A Case Study Competition Among Methods for Analyzing Large Spatial Data. Journal of Agricultural, Biological, and Environmental Statistics, 24, 398–425.
library(GeoModels) ################################################################ ######### Example of predictive score computation ############# ################################################################ model <- "Gaussian" set.seed(79) N <- 1000 x <- runif(N, 0, 1) y <- runif(N, 0, 1) coords <- cbind(x, y) # Set covariance parameters corrmodel <- "GenWend" mean <- 0 sill <- 5 nugget <- 0 scale <- 0.2 smooth <- 0 power2 <- 4 param <- list(mean = mean, sill = sill, nugget = nugget, scale = scale, smooth = smooth, power2 = power2) # Simulation of the spatial Gaussian random field data <- GeoSim(coordx = coords, corrmodel = corrmodel, param = param)$data # Training and validation split sel <- sample(1:N, N * 0.8) coords_est <- coords[sel, ] coords_to_pred <- coords[-sel, ] data_est <- data[sel] data_to_pred <- data[-sel] # Pairwise likelihood fitting fixed <- list(nugget = nugget, smooth = smooth, power2 = power2) start <- list(mean = 0, scale = scale, sill = 1) I <- Inf lower <- list(mean = -I, scale = 0, sill = 0) upper <- list(mean = I, scale = I, sill = I) fit <- GeoFit(data_est, coordx = coords_est, corrmodel = corrmodel, model = model, likelihood = "Marginal", type = "Pairwise", neighb = 3, optimizer = "nlminb", lower = lower, upper = upper, start = start, fixed = fixed) # Prediction at validation locations pr <- GeoKrig(fit,loc = coords_to_pred, data = data_est, mse = TRUE) # Predictive scores from pred and mse Pr_scores <- GeoScores(data_to_pred, pred = pr$pred, mse = pr$mse, score = c("pe", "brie", "crps", "lscore", "pit", "intscore", "coverage"), threshold = 0) Pr_scores$MAE Pr_scores$RMSPE Pr_scores$Brier Pr_scores$CRPS Pr_scores$LogScore Pr_scores$IS95 Pr_scores$Cvg95library(GeoModels) ################################################################ ######### Example of predictive score computation ############# ################################################################ model <- "Gaussian" set.seed(79) N <- 1000 x <- runif(N, 0, 1) y <- runif(N, 0, 1) coords <- cbind(x, y) # Set covariance parameters corrmodel <- "GenWend" mean <- 0 sill <- 5 nugget <- 0 scale <- 0.2 smooth <- 0 power2 <- 4 param <- list(mean = mean, sill = sill, nugget = nugget, scale = scale, smooth = smooth, power2 = power2) # Simulation of the spatial Gaussian random field data <- GeoSim(coordx = coords, corrmodel = corrmodel, param = param)$data # Training and validation split sel <- sample(1:N, N * 0.8) coords_est <- coords[sel, ] coords_to_pred <- coords[-sel, ] data_est <- data[sel] data_to_pred <- data[-sel] # Pairwise likelihood fitting fixed <- list(nugget = nugget, smooth = smooth, power2 = power2) start <- list(mean = 0, scale = scale, sill = 1) I <- Inf lower <- list(mean = -I, scale = 0, sill = 0) upper <- list(mean = I, scale = I, sill = I) fit <- GeoFit(data_est, coordx = coords_est, corrmodel = corrmodel, model = model, likelihood = "Marginal", type = "Pairwise", neighb = 3, optimizer = "nlminb", lower = lower, upper = upper, start = start, fixed = fixed) # Prediction at validation locations pr <- GeoKrig(fit,loc = coords_to_pred, data = data_est, mse = TRUE) # Predictive scores from pred and mse Pr_scores <- GeoScores(data_to_pred, pred = pr$pred, mse = pr$mse, score = c("pe", "brie", "crps", "lscore", "pit", "intscore", "coverage"), threshold = 0) Pr_scores$MAE Pr_scores$RMSPE Pr_scores$Brier Pr_scores$CRPS Pr_scores$LogScore Pr_scores$IS95 Pr_scores$Cvg95
Simulation of Gaussian and some non Gaussian spatial, spatio-temporal and spatial bivariate random fields. The function return a realization of a random Field for a given covariance model and covariance parameters.Simulation is based on Cholesky decomposition.
GeoSim(coordx, coordy=NULL,coordz=NULL, coordt=NULL, coordx_dyn=NULL, corrmodel, distance="Eucl", grid=FALSE, method="cholesky", model='Gaussian', n=1, param,anisopars=NULL,radius=1, sparse=FALSE,X=NULL,spobj=NULL,nrep=1,progress=TRUE)GeoSim(coordx, coordy=NULL,coordz=NULL, coordt=NULL, coordx_dyn=NULL, corrmodel, distance="Eucl", grid=FALSE, method="cholesky", model='Gaussian', n=1, param,anisopars=NULL,radius=1, sparse=FALSE,X=NULL,spobj=NULL,nrep=1,progress=TRUE)
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordz |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordt |
A numeric vector giving 1-dimension of
temporal coordinates. Optional argument, the default is |
coordx_dyn |
A list of |
corrmodel |
String; the name of a correlation model, for the description see the Section Details. |
distance |
String; the name of the spatial distance. The default
is |
grid |
Logical; if |
method |
String; the type of matrix decomposition used in the simulation.
Default is cholesky. The other possible choices is |
model |
String; the type of RF and therefore the densities associated to the likelihood
objects. |
n |
Numeric; the number of trials for binomial RFs.
The number of successes in the negative Binomial RFs. Default is |
param |
A list of parameter values required in the simulation procedure of RFs, see Examples. |
anisopars |
A list of two elements "angle" and "ratio" i.e. the anisotropy angle and the anisotropy ratio, respectively. |
radius |
Numeric; a value indicating the radius of the sphere when using the great circle distance. Default value is 1. |
sparse |
Logical; if |
X |
Numeric; Matrix of space-time covariates. |
spobj |
An object of class sp or spacetime |
nrep |
Numeric; Numbers of indipendent replicates. |
progress |
Logic; If TRUE then a progress bar is shown. |
Returns an object of class GeoSim.
An object of class GeoSim is a list containing
at most the following components:
bivariate |
Logical: |
coordx |
A |
coordy |
A |
coordz |
A |
coordt |
A |
coordx_dyn |
A list of dynamical (in time) spatial coordinates; |
corrmodel |
The correlation model; see |
data |
The vector or matrix or array of data, see
|
distance |
The type of spatial distance; |
method |
The method of simulation |
model |
The type of RF, see |
n |
The number of trial for Binomial RFs;the number of successes in a negative Binomial RFs; |
numcoord |
The number of spatial coordinates; |
numtime |
The number the temporal realisations of the RF; |
param |
The vector of parameters' estimates; |
radius |
The radius of the sphere if coordinates are passed in lon/lat format; |
spacetime |
|
nrep |
The number of indipendent replicates; |
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
library(GeoModels) library(mapproj) ################################################################ ### ### Example 1. Simulation of a spatial Gaussian RF ### with Matern and Generalized Wendland correlations ############################################################### # Define the spatial-coordinates of the points: x <- runif(500);y <- runif(500) coords=cbind(x,y) set.seed(261) # Simulation of a spatial Gaussian RF with Matern correlation function data1 <- GeoSim(coordx=coords, corrmodel="Matern", param=list(smooth=0.5, mean=0,sill=1,scale=0.4/3,nugget=0))$data set.seed(261) data2 <- GeoSim(coordx=coords, corrmodel="GenWend", param=list(smooth=0, power2=4,mean=0,sill=1,scale=0.4,nugget=0))$data opar=par(no.readonly = TRUE) par(mfrow=c(1,2)) quilt.plot(coords,data1,main="Matern",xlab="",ylab="") quilt.plot(coords,data2,main="Wendland",xlab="",ylab="") par(opar) ################################################################ ### ### Example 2. Simulation of a spatial geometric RF ### with underlying Wend0 correlation ### ################################################################ # Define the spatial-coordinates of the points: x <- runif(800);y <- runif(800) coords <- cbind(x,y) set.seed(251) # Simulation of a spatial Binomial RF: sim <- GeoSim(coordx=coords, corrmodel="Wend0", model="BinomialNeg",n=1,sparse=TRUE, param=list(nugget=0,mean=0,scale=.2,power2=4)) quilt.plot(coords,sim$data,nlevel=max(sim$data),col=terrain.colors(max(sim$data+1))) ################################################################ ### ### Example 3. Simulation of a spatial Weibull RF ### with underlying Matern correlation on a regular grid ### ############################################################### # Define the spatial-coordinates of the points: x <- seq(0,1,0.032) y <- seq(0,1,0.032) set.seed(261) # Simulation of a spatial Gaussian RF with Matern correlation function data1 <- GeoSim(x,y,grid=TRUE, corrmodel="Matern",model="Weibull", param=list(shape=1.2,mean=0,scale=0.3/3,nugget=0,smooth=0.5))$data image.plot(x,y,data1,main="Weibull RF",xlab="",ylab="") ################################################################ ### ### Example 4. Simulation of a spatial t RF ### with with underlying Generalized Wendland correlation ### ############################################################### # Define the spatial-coordinates of the points: x <- seq(0,1,0.03) y <- seq(0,1,0.03) set.seed(268) # Simulation of a spatial Gaussian RF with Matern correlation function data1 <- GeoSim(x,y,grid=TRUE, corrmodel="GenWend",model="StudentT", sparse=TRUE, param=list(df=1/4,mean=0,sill=1,scale=0.3,nugget=0,smooth=1,power2=5))$data image.plot(x,y,data1,col=terrain.colors(100),main="Student-t RF",xlab="",ylab="") ################################################################ ### ### Example 5. Simulation of a sinhasinh RF ### with underlying Wend0 correlation. ### ############################################################### # Define the spatial-coordinates of the points: x <- runif(500, 0, 2) y <- runif(500, 0, 2) coords <- cbind(x,y) set.seed(261) corrmodel="Wend0" # Simulation of a spatial Gaussian RF: param=list(power2=4,skew=0,tail=1, mean=0,sill=1,scale=0.2,nugget=0) ## gaussian case data0 <- GeoSim(coordx=coords, corrmodel=corrmodel, model="SinhAsinh", param=param,sparse=TRUE)$data plot(density(data0),xlim=c(-7,7)) param=list(power2=4,skew=0,tail=0.7, mean=0,sill=1,scale=0.2,nugget=0) ## heavy tails data1 <- GeoSim(coordx=coords, corrmodel=corrmodel, model="SinhAsinh", param=param,sparse=TRUE)$data lines(density(data1),lty=2) param=list(power2=4,skew=0.5,tail=1, mean=0,sill=1,scale=0.2,nugget=0) ## asymmetry data2 <- GeoSim(coordx=coords, corrmodel=corrmodel, model="SinhAsinh", param=param,sparse=TRUE)$data lines(density(data2),lty=3) ################################################################ ### ### Example 6. Simulation of a bivariate Gaussian RF ### with bivariate Matern correlation model ### ############################################################### # Define the spatial-coordinates of the points: x <- runif(500, 0, 2) y <- runif(500, 0, 2) coords <- cbind(x,y) # Simulation of a bivariate spatial Gaussian RF: # with a separable Bivariate Matern param=list(mean_1=4,mean_2=2,smooth_1=0.5,smooth_2=0.5,smooth_12=0.5, scale_1=0.12,scale_2=0.1,scale_12=0.15, sill_1=1,sill_2=1,nugget_1=0,nugget_2=0,pcol=0.5) data <- GeoSim(coordx=coords,corrmodel="Bi_matern", param=param)$data opar=par(no.readonly = TRUE) par(mfrow=c(1,2)) quilt.plot(coords,data[1,],col=terrain.colors(100),main="1",xlab="",ylab="") quilt.plot(coords,data[2,],col=terrain.colors(100),main="2",xlab="",ylab="") par(opar) ################################################################ ### ### Example 7. Simulation of a spatio temporal Gaussian RF. ### observed on fixed location sites with double Matern correlation ### ############################################################### coordt=1:5 # Define the spatial-coordinates of the points: x <- runif(50, 0, 2) y <- runif(50, 0, 2) coords <- cbind(x,y) param<-list(nugget=0,mean=0,scale_s=0.2/3,scale_t=2/3,sill=1,smooth_s=0.5,smooth_t=0.5) data <- GeoSim(coordx=coords, coordt=coordt, corrmodel="Matern_Matern", param=param)$data dim(data) ################################################################ ### ### Example 8. Simulation of a spatio temporal Gaussian RF. ### observed on dynamical location sites with double Matern correlation ### ############################################################### # Define the dynamical spatial-coordinates of the points: coordt=1:5 coordx_dyn=list() maxN=30 set.seed(8) for(k in 1:length(coordt)) { NN=sample(1:maxN,size=1) x <- runif(NN, 0, 1) y <- runif(NN, 0, 1) coordx_dyn[[k]]=cbind(x,y) } coordx_dyn param<-list(nugget=0,mean=0,scale_s=0.2/3,scale_t=2/3,sill=1,smooth_s=0.5,smooth_t=0.5) data <- GeoSim(coordx_dyn=coordx_dyn, coordt=coordt, corrmodel="Matern_Matern", param=param)$data ## spatial realization at first temporal instants data[[1]] ## spatial realization at third temporal instants data[[3]] ################################################################ ### ### Example 9. Simulation of a Gaussian RF ### with a Wend0 correlation in the north emisphere of the planet earth ### using geodesic distance ############################################################### distance="Geod";radius=6371 NN=3000 ## total point on the sphere on lon/lat format set.seed(80) coords=cbind(runif(NN,-180,180),runif(NN,0,90)) ## Set the wendland parameters corrmodel <- "Wend0" param<-list(mean=0,sill=1,nugget=0,scale=1000,power2=3) # Simulation of a spatial Gaussian RF on the sphere #set.seed(2) data <- GeoSim(coordx=coords,corrmodel=corrmodel,sparse=TRUE, distance=distance,radius=radius,param=param)$data #require(globe) #globe::globeearth(eye=place("newyorkcity")) #globe::globepoints(loc=coords,pch=20,col = cm.colors(length(data),alpha=0.4)[rank(data)])library(GeoModels) library(mapproj) ################################################################ ### ### Example 1. Simulation of a spatial Gaussian RF ### with Matern and Generalized Wendland correlations ############################################################### # Define the spatial-coordinates of the points: x <- runif(500);y <- runif(500) coords=cbind(x,y) set.seed(261) # Simulation of a spatial Gaussian RF with Matern correlation function data1 <- GeoSim(coordx=coords, corrmodel="Matern", param=list(smooth=0.5, mean=0,sill=1,scale=0.4/3,nugget=0))$data set.seed(261) data2 <- GeoSim(coordx=coords, corrmodel="GenWend", param=list(smooth=0, power2=4,mean=0,sill=1,scale=0.4,nugget=0))$data opar=par(no.readonly = TRUE) par(mfrow=c(1,2)) quilt.plot(coords,data1,main="Matern",xlab="",ylab="") quilt.plot(coords,data2,main="Wendland",xlab="",ylab="") par(opar) ################################################################ ### ### Example 2. Simulation of a spatial geometric RF ### with underlying Wend0 correlation ### ################################################################ # Define the spatial-coordinates of the points: x <- runif(800);y <- runif(800) coords <- cbind(x,y) set.seed(251) # Simulation of a spatial Binomial RF: sim <- GeoSim(coordx=coords, corrmodel="Wend0", model="BinomialNeg",n=1,sparse=TRUE, param=list(nugget=0,mean=0,scale=.2,power2=4)) quilt.plot(coords,sim$data,nlevel=max(sim$data),col=terrain.colors(max(sim$data+1))) ################################################################ ### ### Example 3. Simulation of a spatial Weibull RF ### with underlying Matern correlation on a regular grid ### ############################################################### # Define the spatial-coordinates of the points: x <- seq(0,1,0.032) y <- seq(0,1,0.032) set.seed(261) # Simulation of a spatial Gaussian RF with Matern correlation function data1 <- GeoSim(x,y,grid=TRUE, corrmodel="Matern",model="Weibull", param=list(shape=1.2,mean=0,scale=0.3/3,nugget=0,smooth=0.5))$data image.plot(x,y,data1,main="Weibull RF",xlab="",ylab="") ################################################################ ### ### Example 4. Simulation of a spatial t RF ### with with underlying Generalized Wendland correlation ### ############################################################### # Define the spatial-coordinates of the points: x <- seq(0,1,0.03) y <- seq(0,1,0.03) set.seed(268) # Simulation of a spatial Gaussian RF with Matern correlation function data1 <- GeoSim(x,y,grid=TRUE, corrmodel="GenWend",model="StudentT", sparse=TRUE, param=list(df=1/4,mean=0,sill=1,scale=0.3,nugget=0,smooth=1,power2=5))$data image.plot(x,y,data1,col=terrain.colors(100),main="Student-t RF",xlab="",ylab="") ################################################################ ### ### Example 5. Simulation of a sinhasinh RF ### with underlying Wend0 correlation. ### ############################################################### # Define the spatial-coordinates of the points: x <- runif(500, 0, 2) y <- runif(500, 0, 2) coords <- cbind(x,y) set.seed(261) corrmodel="Wend0" # Simulation of a spatial Gaussian RF: param=list(power2=4,skew=0,tail=1, mean=0,sill=1,scale=0.2,nugget=0) ## gaussian case data0 <- GeoSim(coordx=coords, corrmodel=corrmodel, model="SinhAsinh", param=param,sparse=TRUE)$data plot(density(data0),xlim=c(-7,7)) param=list(power2=4,skew=0,tail=0.7, mean=0,sill=1,scale=0.2,nugget=0) ## heavy tails data1 <- GeoSim(coordx=coords, corrmodel=corrmodel, model="SinhAsinh", param=param,sparse=TRUE)$data lines(density(data1),lty=2) param=list(power2=4,skew=0.5,tail=1, mean=0,sill=1,scale=0.2,nugget=0) ## asymmetry data2 <- GeoSim(coordx=coords, corrmodel=corrmodel, model="SinhAsinh", param=param,sparse=TRUE)$data lines(density(data2),lty=3) ################################################################ ### ### Example 6. Simulation of a bivariate Gaussian RF ### with bivariate Matern correlation model ### ############################################################### # Define the spatial-coordinates of the points: x <- runif(500, 0, 2) y <- runif(500, 0, 2) coords <- cbind(x,y) # Simulation of a bivariate spatial Gaussian RF: # with a separable Bivariate Matern param=list(mean_1=4,mean_2=2,smooth_1=0.5,smooth_2=0.5,smooth_12=0.5, scale_1=0.12,scale_2=0.1,scale_12=0.15, sill_1=1,sill_2=1,nugget_1=0,nugget_2=0,pcol=0.5) data <- GeoSim(coordx=coords,corrmodel="Bi_matern", param=param)$data opar=par(no.readonly = TRUE) par(mfrow=c(1,2)) quilt.plot(coords,data[1,],col=terrain.colors(100),main="1",xlab="",ylab="") quilt.plot(coords,data[2,],col=terrain.colors(100),main="2",xlab="",ylab="") par(opar) ################################################################ ### ### Example 7. Simulation of a spatio temporal Gaussian RF. ### observed on fixed location sites with double Matern correlation ### ############################################################### coordt=1:5 # Define the spatial-coordinates of the points: x <- runif(50, 0, 2) y <- runif(50, 0, 2) coords <- cbind(x,y) param<-list(nugget=0,mean=0,scale_s=0.2/3,scale_t=2/3,sill=1,smooth_s=0.5,smooth_t=0.5) data <- GeoSim(coordx=coords, coordt=coordt, corrmodel="Matern_Matern", param=param)$data dim(data) ################################################################ ### ### Example 8. Simulation of a spatio temporal Gaussian RF. ### observed on dynamical location sites with double Matern correlation ### ############################################################### # Define the dynamical spatial-coordinates of the points: coordt=1:5 coordx_dyn=list() maxN=30 set.seed(8) for(k in 1:length(coordt)) { NN=sample(1:maxN,size=1) x <- runif(NN, 0, 1) y <- runif(NN, 0, 1) coordx_dyn[[k]]=cbind(x,y) } coordx_dyn param<-list(nugget=0,mean=0,scale_s=0.2/3,scale_t=2/3,sill=1,smooth_s=0.5,smooth_t=0.5) data <- GeoSim(coordx_dyn=coordx_dyn, coordt=coordt, corrmodel="Matern_Matern", param=param)$data ## spatial realization at first temporal instants data[[1]] ## spatial realization at third temporal instants data[[3]] ################################################################ ### ### Example 9. Simulation of a Gaussian RF ### with a Wend0 correlation in the north emisphere of the planet earth ### using geodesic distance ############################################################### distance="Geod";radius=6371 NN=3000 ## total point on the sphere on lon/lat format set.seed(80) coords=cbind(runif(NN,-180,180),runif(NN,0,90)) ## Set the wendland parameters corrmodel <- "Wend0" param<-list(mean=0,sill=1,nugget=0,scale=1000,power2=3) # Simulation of a spatial Gaussian RF on the sphere #set.seed(2) data <- GeoSim(coordx=coords,corrmodel=corrmodel,sparse=TRUE, distance=distance,radius=radius,param=param)$data #require(globe) #globe::globeearth(eye=place("newyorkcity")) #globe::globepoints(loc=coords,pch=20,col = cm.colors(length(data),alpha=0.4)[rank(data)])
Simulation of Gaussian and some non Gaussian spatial, spatio-temporal and spatial bivariate random fields using two approximate methods of simulation: circulant embeeding and spectral turning band. (see Examples).
GeoSimapprox(coordx, coordy=NULL, coordz=NULL,coordt=NULL, coordx_dyn=NULL,corrmodel, distance="Eucl",GPU=NULL, grid=FALSE,max.ext=1, method="TB", L=1000,model='Gaussian',parallel=FALSE,ncores=NULL, n=1,param,anisopars=NULL, radius=6371,X=NULL,spobj=NULL, nrep=1,progress=TRUE)GeoSimapprox(coordx, coordy=NULL, coordz=NULL,coordt=NULL, coordx_dyn=NULL,corrmodel, distance="Eucl",GPU=NULL, grid=FALSE,max.ext=1, method="TB", L=1000,model='Gaussian',parallel=FALSE,ncores=NULL, n=1,param,anisopars=NULL, radius=6371,X=NULL,spobj=NULL, nrep=1,progress=TRUE)
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordz |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordt |
A numeric vector giving 1-dimension of
temporal coordinates. Optional argument, the default is |
coordx_dyn |
A list of |
corrmodel |
String; the name of a correlation model, for the description see the Section Details. |
parallel |
Logical; if |
ncores |
Numeric; number of cores involved in parallelization. |
distance |
String; the name of the spatial distance. The default
is |
GPU |
Numeric; if |
grid |
Logical; if |
max.ext |
Numeric; The maximum extension of the simulation window (for the spatial CE method). |
method |
String; the type of approximation method. Default is |
L |
Numeric; the number of lines in the turning band method. |
model |
String; the type of RF and therefore the densities associated to the likelihood
objects. |
n |
Numeric; the number of trials for binomial RFs. The number of successes in the negative Binomial RFs. Default is |
param |
A list of parameter values required in the simulation procedure of RFs, see Examples. |
anisopars |
A list of two elements "angle" and "ratio" i.e. the anisotropy angle and the anisotropy ratio, respectively. |
radius |
Numeric; a value indicating the radius of the sphere when using the great circle distance. Default value is the radius of the earth in Km (i.e. 6371) |
X |
Numeric; Matrix of space-time covariates. |
spobj |
An object of class sp or spacetime |
nrep |
Numeric; Numbers of indipendent replicates. |
progress |
Logic; If TRUE then a progress bar is shown. |
Returns an object of class GeoSim.
An object of class GeoSim is a list containing
at most the following components:
bivariate |
Logical: |
coordx |
A |
coordy |
A |
coordt |
A |
coordx_dyn |
A list of dynamical (in time) spatial coordinates; |
corrmodel |
The correlation model; see |
data |
The vector or matrix or array of data, see
|
distance |
The type of spatial distance; |
method |
The method of simulation |
model |
The type of RF, see |
n |
The number of trial for Binomial RFs;the number of successes in a negative Binomial RFs; |
numcoord |
The number of spatial coordinates; |
numtime |
The number the temporal realisations of the RF; |
param |
The vector of parameters' estimates; |
radius |
The radius of the sphere if coordinates are passed in lon/lat format; |
spacetime |
|
nrep |
The number of indipendent replicates; |
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
T. Gneiting, H. Sevcikova, D. B. Percival, M. Schlather and Y. Jiang (2006) Fast and Exact Simulation of Large Gaussian Lattice Systems in R2: Exploring the Limits Journal of Computational and Graphical Statistics 15 (3)
M. Bevilacqua, X. Emery, F. Cuevas Pacheco (2025) Fast simulation of Gaussian random fields with flexible correlation models in Euclidean spaces arxiv
library(GeoModels) ################################################################ ### ### Example 1. Simulation of a large spatial Gaussian RF ### with Matern covariance model ### using circulant embeeding method ### It works only for regular grid ############################################################### set.seed(68) x = seq(0,1,0.005) y = seq(0,1,0.005) param=list(smooth=1.5,mean=0,sill=1,scale=0.2/3,nugget=0) # Simulation of a spatial Gaussian RF with Matern correlation function data1 <- GeoSimapprox(coordx=x,coordy=y, grid=TRUE,corrmodel="Matern", model="Gaussian", method="CE",param=param)$data fields::image.plot( matrix(data1, length(x), length(y), byrow = TRUE) ) ################################################################ ### ### Example 2. Simulation of a large spatial Tukey-h RF ### with GenWend-Matern covariance model ### using spectral Turning band method ### It works for (ir)regular grid ############################################################### set.seed(68) x = runif(50000) y = runif(50000) coords=cbind(x,y) param=list(smooth=0.5,mean=0,sill=1,scale=0.04,nugget=0,tail=0.15,power2=1/4) # Simulation of a spatial Gaussian RF with Matern correlation function data1 <- GeoSimapprox(coords, corrmodel="GenWend_Matern", model="Tukeyh", method="TB",param=param)$data quilt.plot(coords,data1) ################################################################ ### ### Example 3. Simulation of a large spacetime Gaussian RF ### with separable matern covariance model ### using Circular embeeding method ### It works for (large) regular time grid ############################################################### set.seed(68) coordt <- (0:100) coords <- cbind( runif(100, 0 ,1), runif(100, 0 ,1)) param <- list(mean = 0, sill = 1, nugget = 0.25, scale_s = 0.05, scale_t = 2, smooth_s = 0.5, smooth_t = 0.5) # Simulation of a spatial Gaussian RF with Matern correlation function param<-list(nugget=0,mean=0,scale_s=0.2/3,scale_t=2/3,sill=1,smooth_s=0.5,smooth_t=0.5) data <- GeoSimapprox(coordx=coords, coordt=coordt, corrmodel="Matern_Matern", model="Gaussian",method="CE",param=param)$data dim(data) ################################################################ ### ### Example 4. Simulation of a large spacetime Gaussian RF ### with separable GenWend covariance model ### using Circular embeeding method in time ############################################################### set.seed(68) # Simulation of a spatial Gaussian RF with Matern correlation function param<-list(nugget=0,mean=0,scale_s=0.2,scale_t=3,sill=1, smooth_s=0,smooth_t=0, power2_s=4,power2_t=4) data <- GeoSimapprox(coordx=coords, coordt=coordt, corrmodel="GenWend_GenWend", model="Gaussian",method="CE",param=param)$data dim(data) ################################################################ ### ### Example 6. Simulation of a large bivariate Gaussian RF ### with bivariate Matern correlation model ### using spectral Turning band method ############################################################### # Define the spatial-coordinates of the points: #x <- runif(20000, 0, 2) #y <- runif(20000, 0, 2) #coords <- cbind(x,y) # Simulation of a bivariate spatial Gaussian RF: # with a Bivariate Matern #set.seed(12) #param=list(mean_1=4,mean_2=2,smooth_1=0.5,smooth_2=0.5,smooth_12=0.5, # scale_1=0.12,scale_2=0.1,scale_12=0.15, # sill_1=1,sill_2=1,nugget_1=0,nugget_2=0,pcol=0.5) #data <- GeoSimapprox(coordx=coords,corrmodel="Bi_matern", # param=param,method="TB",L=1000)$data #opar=par(no.readonly = TRUE) #par(mfrow=c(1,2)) #quilt.plot(coords,data[1,],col=terrain.colors(100),main="1",xlab="",ylab="") #quilt.plot(coords,data[2,],col=terrain.colors(100),main="2",xlab="",ylab="")library(GeoModels) ################################################################ ### ### Example 1. Simulation of a large spatial Gaussian RF ### with Matern covariance model ### using circulant embeeding method ### It works only for regular grid ############################################################### set.seed(68) x = seq(0,1,0.005) y = seq(0,1,0.005) param=list(smooth=1.5,mean=0,sill=1,scale=0.2/3,nugget=0) # Simulation of a spatial Gaussian RF with Matern correlation function data1 <- GeoSimapprox(coordx=x,coordy=y, grid=TRUE,corrmodel="Matern", model="Gaussian", method="CE",param=param)$data fields::image.plot( matrix(data1, length(x), length(y), byrow = TRUE) ) ################################################################ ### ### Example 2. Simulation of a large spatial Tukey-h RF ### with GenWend-Matern covariance model ### using spectral Turning band method ### It works for (ir)regular grid ############################################################### set.seed(68) x = runif(50000) y = runif(50000) coords=cbind(x,y) param=list(smooth=0.5,mean=0,sill=1,scale=0.04,nugget=0,tail=0.15,power2=1/4) # Simulation of a spatial Gaussian RF with Matern correlation function data1 <- GeoSimapprox(coords, corrmodel="GenWend_Matern", model="Tukeyh", method="TB",param=param)$data quilt.plot(coords,data1) ################################################################ ### ### Example 3. Simulation of a large spacetime Gaussian RF ### with separable matern covariance model ### using Circular embeeding method ### It works for (large) regular time grid ############################################################### set.seed(68) coordt <- (0:100) coords <- cbind( runif(100, 0 ,1), runif(100, 0 ,1)) param <- list(mean = 0, sill = 1, nugget = 0.25, scale_s = 0.05, scale_t = 2, smooth_s = 0.5, smooth_t = 0.5) # Simulation of a spatial Gaussian RF with Matern correlation function param<-list(nugget=0,mean=0,scale_s=0.2/3,scale_t=2/3,sill=1,smooth_s=0.5,smooth_t=0.5) data <- GeoSimapprox(coordx=coords, coordt=coordt, corrmodel="Matern_Matern", model="Gaussian",method="CE",param=param)$data dim(data) ################################################################ ### ### Example 4. Simulation of a large spacetime Gaussian RF ### with separable GenWend covariance model ### using Circular embeeding method in time ############################################################### set.seed(68) # Simulation of a spatial Gaussian RF with Matern correlation function param<-list(nugget=0,mean=0,scale_s=0.2,scale_t=3,sill=1, smooth_s=0,smooth_t=0, power2_s=4,power2_t=4) data <- GeoSimapprox(coordx=coords, coordt=coordt, corrmodel="GenWend_GenWend", model="Gaussian",method="CE",param=param)$data dim(data) ################################################################ ### ### Example 6. Simulation of a large bivariate Gaussian RF ### with bivariate Matern correlation model ### using spectral Turning band method ############################################################### # Define the spatial-coordinates of the points: #x <- runif(20000, 0, 2) #y <- runif(20000, 0, 2) #coords <- cbind(x,y) # Simulation of a bivariate spatial Gaussian RF: # with a Bivariate Matern #set.seed(12) #param=list(mean_1=4,mean_2=2,smooth_1=0.5,smooth_2=0.5,smooth_12=0.5, # scale_1=0.12,scale_2=0.1,scale_12=0.15, # sill_1=1,sill_2=1,nugget_1=0,nugget_2=0,pcol=0.5) #data <- GeoSimapprox(coordx=coords,corrmodel="Bi_matern", # param=param,method="TB",L=1000)$data #opar=par(no.readonly = TRUE) #par(mfrow=c(1,2)) #quilt.plot(coords,data[1,],col=terrain.colors(100),main="1",xlab="",ylab="") #quilt.plot(coords,data[2,],col=terrain.colors(100),main="2",xlab="",ylab="")
Simulates spatial (spatio-temporal) Gaussian and non-Gaussian random fields conditioned on observed data using specified correlation models. For large conditioning datasets approximation methods like turning band can be used. For large locations to simlate local kriging can be used.
GeoSimcond(estobj = NULL, data, coordx, coordy = NULL, coordz = NULL, coordt = NULL, coordx_dyn = NULL, corrmodel, distance = "Eucl", grid = FALSE, loc, maxdist = NULL, maxtime = NULL, method = "Cholesky", model = "Gaussian", n = 1, nrep = 1, local = FALSE, L = 1000, neighb = NULL, param, anisopars = NULL, radius = 1, sparse = FALSE, time = NULL, copula = NULL, X = NULL, Xloc = NULL, Mloc = NULL, parallel=FALSE, ncores = NULL, progress=FALSE)GeoSimcond(estobj = NULL, data, coordx, coordy = NULL, coordz = NULL, coordt = NULL, coordx_dyn = NULL, corrmodel, distance = "Eucl", grid = FALSE, loc, maxdist = NULL, maxtime = NULL, method = "Cholesky", model = "Gaussian", n = 1, nrep = 1, local = FALSE, L = 1000, neighb = NULL, param, anisopars = NULL, radius = 1, sparse = FALSE, time = NULL, copula = NULL, X = NULL, Xloc = NULL, Mloc = NULL, parallel=FALSE, ncores = NULL, progress=FALSE)
estobj |
Object of class |
data |
Numeric vector/matrix/array of observed data |
coordx |
Numeric matrix of spatial coordinates (d x 2 or d x 3) |
coordy |
Optional numeric vector of y-coordinates |
coordz |
Optional numeric vector of z-coordinates |
coordt |
Optional numeric vector of temporal coordinates |
coordx_dyn |
Optional list of dynamic spatial coordinates |
corrmodel |
String specifying correlation model name |
distance |
String specifying distance metric (default: "Eucl") |
grid |
Logical for regular grid (default: FALSE) |
loc |
Numeric matrix of prediction locations (n x 2) |
maxdist |
Optional maximum distance for local kriging |
maxtime |
Optional maximum temporal distance |
method |
String for decomposition method ("Cholesky", "TB", or "CE") |
model |
String specifying random field type (default: "Gaussian") |
n |
Number of trials for binomial RFs (default: 1) |
nrep |
Number of independent replicates (default: 1) |
local |
Logical for local kriging (default: FALSE) |
L |
Number of lines for turning bands method (default: 1000) |
neighb |
Optional neighborhood order for local kriging |
param |
List of parameter values |
anisopars |
List with anisotropy angle and ratio |
radius |
Radius for spherical coordinates (default: Earth's radius) |
sparse |
Logical for sparse matrix algorithms (default: FALSE) |
time |
Optional vector of temporal instants to predict |
copula |
Optional string specifying copula type |
X |
Optional matrix of spatio-temporal covariates |
Xloc |
Optional matrix of covariates for prediction locations |
Mloc |
Optional vector of estimated means for prediction locations |
parallel |
If TRUE the the computation is parallelized |
ncores |
Numbers of cores involved in the parallelization |
progress |
If TRUE then a progress bar is shown. |
For Gaussian RF, performs conditional simulation using three steps:
Unconditional simulation at observed and prediction locations
Simple kriging estimates at observed locations
Combination to produce conditional simulations
For large datasets, approximate methods ("TB" or "CE") are recommended coupled with local kriging (local=TRUE and neighb=k) and using parallelization (parallel=T).
Returns an object of class GeoSimcond containing:
Simulated field realizations
Model parameters and settings
Spatial/temporal coordinates
Covariance information
Moreno Bevilacqua [email protected],\ Víctor Morales Oñate [email protected],\ Christian Caamaño-Carrillo [email protected]
Gaetan, C. and Guyon, X. (2010) Spatial Statistics and Modelling. Springer Verlag, New York.
library(GeoModels) ############################################## ## conditional simulation of a Gaussian rf ### ############################################## model="Gaussian" set.seed(79) ### conditioning locations x = runif(250, 0, 1) y = runif(250, 0, 1) coords=cbind(x,y) # Set the exponential cov parameters: corrmodel = "GenWend" mean=0; sill=1; nugget=0 scale=0.2;smooth=0;power2=4 param=list(mean=mean,sill=sill,nugget=nugget,scale=scale,smooth=smooth,power2=power2) # Simulation data = GeoSim(coordx=coords, corrmodel=corrmodel,model=model, param=param)$data ## estimation with pairwise likelihood fixed=list(nugget=nugget,smooth=smooth,power2=power2) start=list(mean=0,scale=scale,sill=1) I=Inf lower=list(mean=-I,scale=0,sill=0) upper=list(mean= I,scale=I,sill=I) # Maximum pairwise likelihood fitting : fit = GeoFit(data, coordx=coords, corrmodel=corrmodel,model=model, likelihood='Marginal', type='Pairwise',neighb=3, optimizer="nlminb", lower=lower,upper=upper, start=start,fixed=fixed) # locations to simulate xx=seq(0,1,0.025) loc_to_sim=as.matrix(expand.grid(xx,xx)) # Conditional simulation sim_result <- GeoSimcond(fit,loc = loc_to_sim,nrep=50) cond_mean=sim_result$cond_mean # conditional mean cond_var =sim_result$cond_var # conditional var par(mfrow=c(1,3)) quilt.plot(coords, data) quilt.plot(loc_to_sim, cond_mean) quilt.plot(loc_to_sim, cond_var) par(mfrow=c(1,1)) ############################################## ## conditional simulation of a LogGaussian rf ############################################## model="LogGaussian" set.seed(79) ### conditioning locations x = runif(500, 0, 1) y = runif(500, 0, 1) coords=cbind(x,y) # Set the exponential cov parameters: corrmodel = "Matern" mean=0; sill=.1; nugget=0 scale=0.2;smooth=0.5 param=list(mean=mean,sill=sill,nugget=nugget,scale=scale,smooth=smooth) # Simulation data = GeoSim(coordx=coords, corrmodel=corrmodel,model=model, param=param)$data ## estimation with pairwise likelihood fixed=list(nugget=nugget,smooth=smooth) start=list(mean=0,scale=scale,sill=1) I=Inf lower=list(mean=-I,scale=0,sill=0) upper=list(mean= I,scale=I,sill=I) # Maximum pairwise likelihood fitting : fit = GeoFit(data, coordx=coords, corrmodel=corrmodel,model=model, likelihood='Marginal', type='Pairwise',neighb=3, optimizer="nlminb", lower=lower,upper=upper, start=start,fixed=fixed) # locations to simulate xx=seq(0,1,0.025) loc_to_sim=as.matrix(expand.grid(xx,xx)) # Conditional simulation sim_result <- GeoSimcond(fit,loc = loc_to_sim,nrep=50) cond_mean=sim_result$cond_mean # conditional mean cond_var =sim_result$cond_var # conditional var par(mfrow=c(1,3)) quilt.plot(coords, data) quilt.plot(loc_to_sim,cond_mean) quilt.plot(loc_to_sim,cond_var) par(mfrow=c(1,1))library(GeoModels) ############################################## ## conditional simulation of a Gaussian rf ### ############################################## model="Gaussian" set.seed(79) ### conditioning locations x = runif(250, 0, 1) y = runif(250, 0, 1) coords=cbind(x,y) # Set the exponential cov parameters: corrmodel = "GenWend" mean=0; sill=1; nugget=0 scale=0.2;smooth=0;power2=4 param=list(mean=mean,sill=sill,nugget=nugget,scale=scale,smooth=smooth,power2=power2) # Simulation data = GeoSim(coordx=coords, corrmodel=corrmodel,model=model, param=param)$data ## estimation with pairwise likelihood fixed=list(nugget=nugget,smooth=smooth,power2=power2) start=list(mean=0,scale=scale,sill=1) I=Inf lower=list(mean=-I,scale=0,sill=0) upper=list(mean= I,scale=I,sill=I) # Maximum pairwise likelihood fitting : fit = GeoFit(data, coordx=coords, corrmodel=corrmodel,model=model, likelihood='Marginal', type='Pairwise',neighb=3, optimizer="nlminb", lower=lower,upper=upper, start=start,fixed=fixed) # locations to simulate xx=seq(0,1,0.025) loc_to_sim=as.matrix(expand.grid(xx,xx)) # Conditional simulation sim_result <- GeoSimcond(fit,loc = loc_to_sim,nrep=50) cond_mean=sim_result$cond_mean # conditional mean cond_var =sim_result$cond_var # conditional var par(mfrow=c(1,3)) quilt.plot(coords, data) quilt.plot(loc_to_sim, cond_mean) quilt.plot(loc_to_sim, cond_var) par(mfrow=c(1,1)) ############################################## ## conditional simulation of a LogGaussian rf ############################################## model="LogGaussian" set.seed(79) ### conditioning locations x = runif(500, 0, 1) y = runif(500, 0, 1) coords=cbind(x,y) # Set the exponential cov parameters: corrmodel = "Matern" mean=0; sill=.1; nugget=0 scale=0.2;smooth=0.5 param=list(mean=mean,sill=sill,nugget=nugget,scale=scale,smooth=smooth) # Simulation data = GeoSim(coordx=coords, corrmodel=corrmodel,model=model, param=param)$data ## estimation with pairwise likelihood fixed=list(nugget=nugget,smooth=smooth) start=list(mean=0,scale=scale,sill=1) I=Inf lower=list(mean=-I,scale=0,sill=0) upper=list(mean= I,scale=I,sill=I) # Maximum pairwise likelihood fitting : fit = GeoFit(data, coordx=coords, corrmodel=corrmodel,model=model, likelihood='Marginal', type='Pairwise',neighb=3, optimizer="nlminb", lower=lower,upper=upper, start=start,fixed=fixed) # locations to simulate xx=seq(0,1,0.025) loc_to_sim=as.matrix(expand.grid(xx,xx)) # Conditional simulation sim_result <- GeoSimcond(fit,loc = loc_to_sim,nrep=50) cond_mean=sim_result$cond_mean # conditional mean cond_var =sim_result$cond_var # conditional var par(mfrow=c(1,3)) quilt.plot(coords, data) quilt.plot(loc_to_sim,cond_mean) quilt.plot(loc_to_sim,cond_var) par(mfrow=c(1,1))
Simulation of Gaussian and some non Gaussian spatial, spatio-temporal and spatial bivariate random fields using Gaussian or Clayton copula. The function return a realization of a Random Field for a given covariance model and covariance parameters. Simulation is based on Cholesky decomposition.
GeoSimCopula(coordx, coordy=NULL,coordz=NULL, coordt=NULL, coordx_dyn=NULL, corrmodel, distance="Eucl", grid=FALSE, method="cholesky", model='Gaussian', n=1, param, anisopars=NULL,radius=1, sparse=FALSE, copula="Gaussian",X=NULL,spobj=NULL,nrep=1,progress=FALSE)GeoSimCopula(coordx, coordy=NULL,coordz=NULL, coordt=NULL, coordx_dyn=NULL, corrmodel, distance="Eucl", grid=FALSE, method="cholesky", model='Gaussian', n=1, param, anisopars=NULL,radius=1, sparse=FALSE, copula="Gaussian",X=NULL,spobj=NULL,nrep=1,progress=FALSE)
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordz |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordt |
A numeric vector giving 1-dimension of
temporal coordinates. Optional argument, the default is |
coordx_dyn |
A list of |
corrmodel |
String; the name of a correlation model, for the description see the Section Details. |
distance |
String; the name of the spatial distance. The default
is |
grid |
Logical; if |
method |
String; the type of matrix decomposition used in the simulation. Default is cholesky. The other possible choices is |
model |
String; the type of RF and therefore the densities associated to the likelihood
objects. |
n |
Numeric; the number of trials for binomial RFs. The number of successes in the negative Binomial RFs. Default is |
param |
A list of parameter values required in the simulation procedure of RFs, see Examples. |
anisopars |
A list of two elements "angle" and "ratio" i.e. the anisotropy angle and the anisotropy ratio, respectively. |
radius |
Numeric; a value indicating the radius of the sphere when using the great circle distance. Default value is 1. |
sparse |
Logical; if |
copula |
String; the type of copula. It can be "Clayton" or "Gaussian" |
X |
Numeric; Matrix of space-time covariates. |
spobj |
An object of class sp or spacetime |
nrep |
Numeric; Numbers of indipendent replicates. |
progress |
Logic; If TRUE then a progress bar is shown. |
Returns an object of class GeoSimCopula.
An object of class GeoSimCopula is a list containing
at most the following components:
bivariate |
Logical: |
coordx |
A |
coordy |
A |
coordt |
A |
coordx_dyn |
A list of dynamical (in time) spatial coordinates; |
corrmodel |
The correlation model; see |
data |
The vector or matrix or array of data, see
|
distance |
The type of spatial distance; |
method |
The method of simulation |
model |
The type of RF, see |
n |
The number of trial for Binomial RFs;the number of successes in a negative Binomial RFs; |
numcoord |
The number of spatial coordinates; |
numtime |
The number the temporal realisations of the RF; |
param |
A list of the parameters |
radius |
The radius of the sphere if coordinates are passed in lon/lat format; |
randseed |
The seed used for the random simulation; |
spacetime |
|
copula |
The type of copula |
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
Bevilacqua M., Alvarado E., Caamano C. (2024) A flexible Clayton-like spatial copula with application to bounded support data. Journal of Multivariate Analysis 201
library(GeoModels) ################################################################ ### ### Example: Simulation of a reparametrized Beta RF ### for beta regression ### with Gaussian and Clayton Copula ### with underlying Wendland correlation. ### ############################################################### set.seed(261) NN=1400 x <- runif(NN);y <- runif(NN) coords=cbind(x,y) corrmodel="GenWend" X=cbind(rep(1,NN),runif(NN)) NuisParam("Beta2",num_betas=2,copula="Gaussian") CorrParam("GenWend") #### Gaussian copula param=list(smooth=0,power2=4, min=0,max=1, mean=0.1,mean1=0.1,scale=0.3,nugget=0,shape=5) data <- GeoSimCopula(coordx=coords, corrmodel=corrmodel, model="Beta2",param=param, copula="Gaussian",sparse=TRUE,X=X)$data quilt.plot(coords,data) #### Clayton copula NuisParam("Beta2",num_betas=2,copula="Clayton") CorrParam("GenWend") param=list(smooth=0,power2=4, min=0,max=1, mean=0.2,mean1=0.1,scale=0.3,nugget=0,shape=6,nu=4) data1 <- GeoSimCopula(coordx=coords, corrmodel=corrmodel, model="Beta2",param=param, copula="Clayton",sparse=TRUE,X=X)$data hist(data1,freq=FALSE) quilt.plot(coords,data1)library(GeoModels) ################################################################ ### ### Example: Simulation of a reparametrized Beta RF ### for beta regression ### with Gaussian and Clayton Copula ### with underlying Wendland correlation. ### ############################################################### set.seed(261) NN=1400 x <- runif(NN);y <- runif(NN) coords=cbind(x,y) corrmodel="GenWend" X=cbind(rep(1,NN),runif(NN)) NuisParam("Beta2",num_betas=2,copula="Gaussian") CorrParam("GenWend") #### Gaussian copula param=list(smooth=0,power2=4, min=0,max=1, mean=0.1,mean1=0.1,scale=0.3,nugget=0,shape=5) data <- GeoSimCopula(coordx=coords, corrmodel=corrmodel, model="Beta2",param=param, copula="Gaussian",sparse=TRUE,X=X)$data quilt.plot(coords,data) #### Clayton copula NuisParam("Beta2",num_betas=2,copula="Clayton") CorrParam("GenWend") param=list(smooth=0,power2=4, min=0,max=1, mean=0.2,mean1=0.1,scale=0.3,nugget=0,shape=6,nu=4) data1 <- GeoSimCopula(coordx=coords, corrmodel=corrmodel, model="Beta2",param=param, copula="Clayton",sparse=TRUE,X=X)$data hist(data1,freq=FALSE) quilt.plot(coords,data1)
Performs an isotropy test based on parametric bootstrap by comparing an isotropic model (H0) with an anisotropic model (H1). A user-chosen spatial correlation model is fitted to spatial data, and the test statistic is a likelihood ratio between H1 (with anisotropy estimated) and H0 (anisotropy fixed at ratio = 1 and angle = 0). The p-value is computed via parametric bootstrap.
GeoTestIsotropy(data, coordx, start, fixed, optimizer = "bobyqa", model = "Gaussian", corrmodel = "Matern", lower = NULL, upper = NULL, B = 1000, likelihood = NULL, type = NULL, copula = NULL, neighb = 5, parallel = TRUE, ncores = NULL, progress = TRUE)GeoTestIsotropy(data, coordx, start, fixed, optimizer = "bobyqa", model = "Gaussian", corrmodel = "Matern", lower = NULL, upper = NULL, B = 1000, likelihood = NULL, type = NULL, copula = NULL, neighb = 5, parallel = TRUE, ncores = NULL, progress = TRUE)
data |
Numeric vector of observations (length |
coordx |
|
start |
Named list with the parameters to be estimated; names must match those expected by |
fixed |
Named list with the parameters kept fixed during estimation; together with |
optimizer |
Optimization algorithm to be used in |
model |
Marginal model for the data (e.g., |
corrmodel |
Spatial correlation model (e.g., |
lower, upper
|
Named lists with lower/upper bounds for parameters in |
B |
Number of parametric bootstrap replications (default |
likelihood |
Type of (composite) likelihood to pass to |
type |
Composite-likelihood type (e.g., |
copula |
Copula object for simulation via |
neighb |
Number of neighbors for composite-likelihood estimation, where applicable. |
parallel |
If |
ncores |
Number of cores to use in parallel; if |
progress |
If |
GeoTestIsotropy implements a likelihood ratio test (LRT) between:
H0: isotropic model with anisotropy parameters fixed at angle = 0, ratio = 1;
H1: anisotropic model with angle and ratio estimated.
The observed statistic is , truncated at zero if negative.
The null distribution is approximated by simulating B datasets under H0 with parameters equal to the H0 fit, and recomputing the LRT.
The p-value is computed as .
The function includes robust checks on parameter names, bounds, simulation method choice (Cholesky vs TB), and parallelization.
An (invisible) list with components:
statistic |
Observed LRT statistic. |
pvalue |
Bootstrap p-value. |
ratio_hat |
Estimated anisotropy ratio ( |
angle_hat |
Estimated anisotropy angle (radians/degrees according to |
corrmodel |
Correlation model used. |
model |
Marginal model used. |
fit_H0 |
|
fit_H1 |
|
B_rep |
Vector of LRT values obtained on the valid bootstrap replications. |
Moreno Bevilacqua [email protected] https://sites.google.com/view/moreno-bevilacqua/home
Víctor Morales Oñate [email protected] https://sites.google.com/site/moralesonatevictor/
Christian Caamaño-Carrillo [email protected] https://www.researchgate.net/profile/Christian-Caamano
GeoFit, GeoSim, GeoSimapprox, GeoVarestbootstrap
The function performs statistical hypothesis tests for nested models based on composite or standard likelihood versions of Wald-type and Wilks-type (likelihood ratio) statistics.
GeoTests(object1, object2, ..., statistic)GeoTests(object1, object2, ..., statistic)
object1 |
An object of class |
object2 |
An object of class |
... |
Further successively nested objects. |
statistic |
String; the name of the statistic used within the hypothesis test (see Details). |
The implemented hypothesis tests for nested models are based on the following statistics:
Wald-type (Wald);
Likelihood ratio or Wilks-type (Wilks under standard likelihood);
For composite likelihood available variants of the basic version are:
Rotnitzky and Jewell adjustment (WilksRJ);
Satterhwaite adjustment (WilksS);
Chandler and Bate adjustment (WilksCB);
Pace, Salvan and Sartori adjustment (WilksPSS);
More specifically,
consider an -dimensional random vector with
probability density function ,
where is a
-dimensional vector of parameters. Suppose that
can be partitioned in a -dimensional subvector
and -dimensional subvector . Assume also to be
interested in testing the specific values of the vector
. Then, one can use some statistical
hypothesis tests for testing the null hypothesis against the alternative . Composite likelihood versions
of 'Wald' statistis have the usual asymptotic
chi-square distribution with degree of freedom. The Wald-type statistic is
where is the
submatrix of the Godambe or Fisher information pertaining to and
is the maximum likelihood estimator from
the full model.
This statistic can be called from the
routine GeoTests assigning at the argument statistic
the value: Wald.
Alternatively to the Wald-type statistic one can use the composite version of the Wilks-type or likelihood ratio statistic, given by
In the composite likelihood case, the asymptotic distribution of the composite likelihood ratio statistic is given by
for , where are
iid copies of a chi-square one random variable and
are the eigenvalues of the matrix . There exist several adjustments
to the composite likelihood ratio statistic in order to get an
approximated . For example, Rotnitzky and Jewell
(1990) proposed the adjustment where is the average
of the eigenvalues . This statistic can be
called within the routine by the value: WilksRJ. A better
solution is proposed by Satterhwaite (1946) defining , where for
, is the effective number of the degree of
freedom. Note that in this case the distribution of the likelihood ratio
statistic is a chi-square random variable with degree of
freedom. This statistic can be called from the routine assigning the
value: WilksS. For the adjustments suggested by Chandler and
Bate (2007) we refere to the article (see
References). This versions can be called from the routine assigning
respectively the values: WilksCB.
An object of class c("data.frame"). The object contain a table
with the results of the tested models. The rows represent the
responses for each model and the columns the following results:
Num.Par |
The number of the model's parameters. |
Diff.Par |
The difference between the number of parameters of the model in the previous row and those in the actual row. |
Df |
The effective number of degree of freedom of the chi-square distribution. |
Chisq |
The observed value of the statistic. |
Pr(>chisq) |
The p-value of the quantile
|
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
Chandler, R. E., and Bate, S. (2007). Inference for Clustered Data Using the Independence log-likelihood. Biometrika, 94, 167–183.
Rotnitzky, A. and Jewell, N. P. (1990). Hypothesis Testing of Regression Parameters in Semiparametric Generalized Linear Models for Cluster Correlated Data. Biometrika, 77, 485–497.
Satterthwaite, F. E. (1946). An Approximate Distribution of Estimates of Variance Components. Biometrics Bulletin, 2, 110–114.
Varin, C., Reid, N. and Firth, D. (2011). An Overview of Composite Likelihood Methods. Statistica Sinica, 21, 5–42.
library(GeoModels) ################################################################ ### ### Example 1. Test on the parameter ### of a regression model using conditional composite likelihood ### ############################################################### set.seed(342) model="Gaussian" # Define the spatial-coordinates of the points: NN=1500 x = runif(NN, 0, 1) y = runif(NN, 0, 1) coords = cbind(x,y) # Parameters mean=1; mean1=-1.25; # regression parameters nugget=0; sill=1 # matrix covariates X=cbind(rep(1,nrow(coords)),runif(nrow(coords))) # model correlation corrmodel="Wend0" power2=4;c_supp=0.15 # simulation param=list(power2=power2,mean=mean,mean1=mean1, sill=sill,scale=c_supp,nugget=nugget) data = GeoSim(coordx=coords, corrmodel=corrmodel,model=model, param=param,X=X)$data I=Inf ##### H1: (regressian mean) fixed=list(nugget=nugget,power2=power2) start=list(mean=mean,mean1=mean1,scale=c_supp,sill=sill) lower=list(mean=-I,mean1=-I,scale=0,sill=0) upper=list(mean=I,mean1=I,scale=I,sill=I) # Maximum pairwise composite-likelihood fitting of the RF: fitH1 = GeoFit(data=data,coordx=coords,corrmodel=corrmodel, model=model, likelihood="Conditional",type="Pairwise",sensitivity=TRUE, lower=lower,upper=upper,neighb=3, optimizer="nlminb",X=X, start=start,fixed=fixed) unlist(fitH1$param) ##### H0: (constant mean i.e beta1=0) fixed=list(power2=power2,nugget=nugget,mean1=0) start=list(mean=mean,scale=c_supp,sill=sill) lower0=list(mean=-I,scale=0,sill=0) upper0=list(mean=I,scale=I,sill=I) # Maximum pairwise composite-likelihood fitting of the RF: fitH0 = GeoFit(data=data,coordx=coords,corrmodel=corrmodel, model=model, likelihood="Conditional",type="Pairwise",sensitivity=TRUE, lower=lower0,upper=upper0,neighb=3, optimizer="nlminb",X=X, start=start,fixed=fixed) unlist(fitH0$param) # not run ##fitH1=GeoVarestbootstrap(fitH1,K=100,optimizer="nlminb", ## lower=lower, upper=upper) ##fitH0=GeoVarestbootstrap(fitH0,K=100,optimizer="nlminb", ## lower=lower0, upper=upper0) # Composite likelihood Wald and ratio statistic statistic tests # rejecting null hypothesis beta1=0 ##GeoTests(fitH1, fitH0 ,statistic='Wald') ##GeoTests(fitH1, fitH0 , statistic='WilksS') ##GeoTests(fitH1, fitH0 , statistic='WilksCB') ################################################################ ### ### Example 2. Parametric test of Gaussianity ### using SinhAsinh random fields using standard likelihood ### ############################################################### set.seed(99) model="SinhAsinh" # Define the spatial-coordinates of the points: NN=200 x = runif(NN, 0, 1) y = runif(NN, 0, 1) coords = cbind(x,y) # Parameters mean=0; nugget=0; sill=1 ### skew and tail parameters skew=0;tail=1 ## H0 is Gaussianity # underlying model correlation corrmodel="Wend0" power2=4;c_supp=0.2 # simulation from Gaussian model (H0) param=list(power2=power2,skew=skew,tail=tail, mean=mean,sill=sill,scale=c_supp,nugget=nugget) data = GeoSim(coordx=coords, corrmodel=corrmodel,model=model, param=param)$data ##### H1: SinhAsinh model fixed=list(power2=power2,nugget=nugget,mean=mean) start=list(scale=c_supp,skew=skew,tail=tail,sill=sill) lower=list(scale=0,skew=-I, tail=0,sill=0) upper=list(scale=I,skew= I,tail=I,sill=I) # Maximum pairwise composite-likelihood fitting of the RF: fitH1 = GeoFit2(data=data,coordx=coords,corrmodel=corrmodel, model=model, likelihood="Full",type="Standard",varest=TRUE, lower=lower,upper=upper, optimizer="nlminb", start=start,fixed=fixed) unlist(fitH1$param) ##### H0: Gaussianity (i.e tail1=1, skew=0 fixed) fixed=list(power2=power2,nugget=nugget,mean=mean,tail=1,skew=0) start=list(scale=c_supp,sill=sill) lower=list(scale=0,sill=0) upper=list(scale=2,sill=5) # Maximum pairwise composite-likelihood fitting of the RF: fitH0 = GeoFit(data=data,coordx=coords,corrmodel=corrmodel, model=model, likelihood="Full",type="Standard",varest=TRUE, lower=lower,upper=upper, optimizer="nlminb", start=start,fixed=fixed) unlist(fitH0$param) # Standard likelihood Wald and ratio statistic statistic tests # not rejecting null hypothesis tail=1,skew=0 (Gaussianity) GeoTests(fitH1, fitH0,statistic='Wald') GeoTests(fitH1, fitH0,statistic='Wilks')library(GeoModels) ################################################################ ### ### Example 1. Test on the parameter ### of a regression model using conditional composite likelihood ### ############################################################### set.seed(342) model="Gaussian" # Define the spatial-coordinates of the points: NN=1500 x = runif(NN, 0, 1) y = runif(NN, 0, 1) coords = cbind(x,y) # Parameters mean=1; mean1=-1.25; # regression parameters nugget=0; sill=1 # matrix covariates X=cbind(rep(1,nrow(coords)),runif(nrow(coords))) # model correlation corrmodel="Wend0" power2=4;c_supp=0.15 # simulation param=list(power2=power2,mean=mean,mean1=mean1, sill=sill,scale=c_supp,nugget=nugget) data = GeoSim(coordx=coords, corrmodel=corrmodel,model=model, param=param,X=X)$data I=Inf ##### H1: (regressian mean) fixed=list(nugget=nugget,power2=power2) start=list(mean=mean,mean1=mean1,scale=c_supp,sill=sill) lower=list(mean=-I,mean1=-I,scale=0,sill=0) upper=list(mean=I,mean1=I,scale=I,sill=I) # Maximum pairwise composite-likelihood fitting of the RF: fitH1 = GeoFit(data=data,coordx=coords,corrmodel=corrmodel, model=model, likelihood="Conditional",type="Pairwise",sensitivity=TRUE, lower=lower,upper=upper,neighb=3, optimizer="nlminb",X=X, start=start,fixed=fixed) unlist(fitH1$param) ##### H0: (constant mean i.e beta1=0) fixed=list(power2=power2,nugget=nugget,mean1=0) start=list(mean=mean,scale=c_supp,sill=sill) lower0=list(mean=-I,scale=0,sill=0) upper0=list(mean=I,scale=I,sill=I) # Maximum pairwise composite-likelihood fitting of the RF: fitH0 = GeoFit(data=data,coordx=coords,corrmodel=corrmodel, model=model, likelihood="Conditional",type="Pairwise",sensitivity=TRUE, lower=lower0,upper=upper0,neighb=3, optimizer="nlminb",X=X, start=start,fixed=fixed) unlist(fitH0$param) # not run ##fitH1=GeoVarestbootstrap(fitH1,K=100,optimizer="nlminb", ## lower=lower, upper=upper) ##fitH0=GeoVarestbootstrap(fitH0,K=100,optimizer="nlminb", ## lower=lower0, upper=upper0) # Composite likelihood Wald and ratio statistic statistic tests # rejecting null hypothesis beta1=0 ##GeoTests(fitH1, fitH0 ,statistic='Wald') ##GeoTests(fitH1, fitH0 , statistic='WilksS') ##GeoTests(fitH1, fitH0 , statistic='WilksCB') ################################################################ ### ### Example 2. Parametric test of Gaussianity ### using SinhAsinh random fields using standard likelihood ### ############################################################### set.seed(99) model="SinhAsinh" # Define the spatial-coordinates of the points: NN=200 x = runif(NN, 0, 1) y = runif(NN, 0, 1) coords = cbind(x,y) # Parameters mean=0; nugget=0; sill=1 ### skew and tail parameters skew=0;tail=1 ## H0 is Gaussianity # underlying model correlation corrmodel="Wend0" power2=4;c_supp=0.2 # simulation from Gaussian model (H0) param=list(power2=power2,skew=skew,tail=tail, mean=mean,sill=sill,scale=c_supp,nugget=nugget) data = GeoSim(coordx=coords, corrmodel=corrmodel,model=model, param=param)$data ##### H1: SinhAsinh model fixed=list(power2=power2,nugget=nugget,mean=mean) start=list(scale=c_supp,skew=skew,tail=tail,sill=sill) lower=list(scale=0,skew=-I, tail=0,sill=0) upper=list(scale=I,skew= I,tail=I,sill=I) # Maximum pairwise composite-likelihood fitting of the RF: fitH1 = GeoFit2(data=data,coordx=coords,corrmodel=corrmodel, model=model, likelihood="Full",type="Standard",varest=TRUE, lower=lower,upper=upper, optimizer="nlminb", start=start,fixed=fixed) unlist(fitH1$param) ##### H0: Gaussianity (i.e tail1=1, skew=0 fixed) fixed=list(power2=power2,nugget=nugget,mean=mean,tail=1,skew=0) start=list(scale=c_supp,sill=sill) lower=list(scale=0,sill=0) upper=list(scale=2,sill=5) # Maximum pairwise composite-likelihood fitting of the RF: fitH0 = GeoFit(data=data,coordx=coords,corrmodel=corrmodel, model=model, likelihood="Full",type="Standard",varest=TRUE, lower=lower,upper=upper, optimizer="nlminb", start=start,fixed=fixed) unlist(fitH0$param) # Standard likelihood Wald and ratio statistic statistic tests # not rejecting null hypothesis tail=1,skew=0 (Gaussianity) GeoTests(fitH1, fitH0,statistic='Wald') GeoTests(fitH1, fitH0,statistic='Wilks')
Performs a parametric bootstrap likelihood-ratio test on the spatial scale parameter using the compactly supported GenWend correlation model.
Two hypotheses are compared: H0 imposes a maximum admissible scale (or independence), while H1 estimates scale freely.
The test statistic is the likelihood ratio and the p-value is obtained by parametric bootstrap under H0.
GeoTestsupp_space(data, coordx, start, fixed, model = "Gaussian", h0 = NULL, optimizer = "bobyqa", lower = NULL, upper = NULL, neighb = 5, B = 1000, likelihood = NULL, type = NULL, method = "Cholesky", parallel = TRUE, ncores = NULL, progress = TRUE)GeoTestsupp_space(data, coordx, start, fixed, model = "Gaussian", h0 = NULL, optimizer = "bobyqa", lower = NULL, upper = NULL, neighb = 5, B = 1000, likelihood = NULL, type = NULL, method = "Cholesky", parallel = TRUE, ncores = NULL, progress = TRUE)
data |
Numeric vector of observations of length |
coordx |
|
start |
Named list of parameters to be estimated. Names must match |
fixed |
Named list of parameters kept fixed. Together with |
model |
Marginal model for the data (default |
h0 |
Positive threshold for the scale parameter under H0. If |
optimizer |
Optimization method passed to |
lower, upper
|
Named lists with bounds for parameters in |
neighb |
Number of neighbors for composite likelihood when applicable. Ignored when the full likelihood is used. |
B |
Number of parametric bootstrap replications (default |
likelihood |
Type of (composite) likelihood to pass to |
type |
Composite-likelihood type (e.g., |
method |
Simulation method for bootstrap under H0: |
parallel |
If |
ncores |
Number of cores for parallelization. If |
progress |
If |
The function fixes the correlation model to corrmodel = "GenWend" (generalized Wendland, compact support).
Input validation ensures consistency of parameter names between start and fixed w.r.t. CorrParam(corrmodel) and NuisParam(model).
Automatic likelihood selection.
If , a composite-likelihood is used (likelihood = "Marginal", type = "Pairwise") with neighb neighbors; otherwise the full likelihood is used (likelihood = "Full", type = "Standard").
Threshold h0 and minimum distance.
Let be the minimum inter-point distance, computed with nabor. If h0 = NULL, the test defaults to independence with h0\_val = max(1e-6, d_min - 1e-6).
Under H0 one enforces scale <= h0 (or scale = h0\_val for independence), while under H1 the scale is estimated freely but capped above by a large, data-driven U\_big.
Likelihood-ratio statistic.
Let where and are the log-(composite) likelihoods under H0 and H1. The null distribution of is approximated via parametric bootstrap with B datasets simulated under H0; the p-value is computed as
Early exit. If the unconstrained fit under H1 already satisfies scale <= h0 (or <= h0\_val), the function returns lambda\_obs = 0 and pvalue = 1 without running the bootstrap.
Robust bounds. The helper automatically widens degenerate or ultra-narrow boxes and enforces positivity for sill and scale.
An (invisible) list with components:
d_min |
Minimum inter-point distance |
h0 |
Threshold actually used under H0. |
lambda_obs |
Observed likelihood-ratio statistic |
pvalue |
Bootstrap p-value. |
B_rep |
Vector of bootstrap statistics |
fit_H0 |
|
fit_H1 |
|
The function uses corrmodel = "GenWend" internally.
For very large n, method = "TB" may be preferable for speed.
Moreno Bevilacqua [email protected] https://sites.google.com/view/moreno-bevilacqua/home
Víctor Morales Oñate [email protected] https://sites.google.com/site/moralesonatevictor/
Christian Caamaño-Carrillo [email protected] https://www.researchgate.net/profile/Christian-Caamano
GeoFit, GeoSim, GeoSimapprox, GeoVarestbootstrap
GeoFit object using parametric bootstrap for std error estimationThe procedure update a GeoFit object computing stderr estimation, confidence intervals
and p-values using parametric bootstrap.
GeoVarestbootstrap(fit,K=100,sparse=FALSE, optimizer=NULL, lower=NULL, upper=NULL, method="cholesky",alpha=0.95, L=1000,parallel=TRUE,ncores=NULL,progress=TRUE)GeoVarestbootstrap(fit,K=100,sparse=FALSE, optimizer=NULL, lower=NULL, upper=NULL, method="cholesky",alpha=0.95, L=1000,parallel=TRUE,ncores=NULL,progress=TRUE)
fit |
A fitted object obtained from the
|
K |
The number of simulations in the parametric bootstrap. |
sparse |
Logical; if |
optimizer |
The type of optimization algorithm (see |
lower |
An optional named list giving the values for the lower bound of the space parameter
when the optimizer is |
upper |
An optional named list giving the values for the upper bound of the space parameter
when the optimizer is |
method |
String; The method of simulation. Default is |
alpha |
Numeric; The level of the confidence interval. |
L |
Numeric; the number of lines in the turning band method. |
parallel |
Logical; if |
ncores |
Numeric; number of cores involved in parallelization. |
progress |
Logic; If TRUE then a progress bar is shown. |
The function update a GeoFit object estimating stderr estimation
and confidence interval using parametric bootstrap.
Returns an (updated) object of class GeoFit.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
library(GeoModels) ################################################################ ### ### Example 1. Test on the parameter ### of a regression model using conditional composite likelihood ### ############################################################### set.seed(342) model="Gaussian" # Define the spatial-coordinates of the points: NN=3500 x = runif(NN, 0, 1) y = runif(NN, 0, 1) coords = cbind(x,y) # Parameters mean=1; mean1=-1.25; # regression parameters sill=1 # variance # matrix covariates X=cbind(rep(1,nrow(coords)),runif(nrow(coords))) # model correlation corrmodel="Matern" smooth=0.5;scale=0.1; nugget=0; # simulation param=list(smooth=smooth,mean=mean,mean1=mean1, sill=sill,scale=scale,nugget=nugget) data = GeoSim(coordx=coords, corrmodel=corrmodel, model=model, param=param,X=X)$data I=Inf fixed=list(nugget=nugget,smooth=smooth) start=list(mean=mean,mean1=mean1,scale=scale,sill=sill) lower=list(mean=-I,mean1=-I,scale=0,sill=0) upper=list(mean=I,mean1=I,scale=I,sill=I) # Maximum pairwise composite-likelihood fitting of the RF: fit = GeoFit(data=data,coordx=coords,corrmodel=corrmodel, model=model, likelihood="Conditional",type="Pairwise",sensitivity=TRUE, lower=lower,upper=upper,neighb=3, optimizer="nlminb",X=X, start=start,fixed=fixed) unlist(fit$param) #fit_update=GeoVarestbootstrap(fit,K=100,parallel=TRUE) #fit_update$stderr #fit_update$conf.int #fit_update$pvalueslibrary(GeoModels) ################################################################ ### ### Example 1. Test on the parameter ### of a regression model using conditional composite likelihood ### ############################################################### set.seed(342) model="Gaussian" # Define the spatial-coordinates of the points: NN=3500 x = runif(NN, 0, 1) y = runif(NN, 0, 1) coords = cbind(x,y) # Parameters mean=1; mean1=-1.25; # regression parameters sill=1 # variance # matrix covariates X=cbind(rep(1,nrow(coords)),runif(nrow(coords))) # model correlation corrmodel="Matern" smooth=0.5;scale=0.1; nugget=0; # simulation param=list(smooth=smooth,mean=mean,mean1=mean1, sill=sill,scale=scale,nugget=nugget) data = GeoSim(coordx=coords, corrmodel=corrmodel, model=model, param=param,X=X)$data I=Inf fixed=list(nugget=nugget,smooth=smooth) start=list(mean=mean,mean1=mean1,scale=scale,sill=sill) lower=list(mean=-I,mean1=-I,scale=0,sill=0) upper=list(mean=I,mean1=I,scale=I,sill=I) # Maximum pairwise composite-likelihood fitting of the RF: fit = GeoFit(data=data,coordx=coords,corrmodel=corrmodel, model=model, likelihood="Conditional",type="Pairwise",sensitivity=TRUE, lower=lower,upper=upper,neighb=3, optimizer="nlminb",X=X, start=start,fixed=fixed) unlist(fit$param) #fit_update=GeoVarestbootstrap(fit,K=100,parallel=TRUE) #fit_update$stderr #fit_update$conf.int #fit_update$pvalues
Computes an empirical estimate of the semivariogram for spatial, spatio-temporal, and bivariate random fields.
GeoVariogram(data, coordx, coordy=NULL, coordz=NULL, coordt=NULL, coordx_dyn=NULL, cloud=FALSE, distance="Eucl", grid=FALSE, maxdist=NULL, neighb=NULL, maxtime=NULL, numbins=NULL, radius=1, type='variogram', bivariate=FALSE, subsample=1, subsample_t=1)GeoVariogram(data, coordx, coordy=NULL, coordz=NULL, coordt=NULL, coordx_dyn=NULL, cloud=FALSE, distance="Eucl", grid=FALSE, maxdist=NULL, neighb=NULL, maxtime=NULL, numbins=NULL, radius=1, type='variogram', bivariate=FALSE, subsample=1, subsample_t=1)
data |
A numeric vector of length |
coordx |
Spatial coordinates. Either a numeric vector giving the first coordinate, or a
|
coordy |
A numeric vector giving the second spatial coordinate.
Optional, default is |
coordz |
A numeric vector giving the third spatial coordinate (if needed).
Optional, default is |
coordt |
A numeric vector of temporal coordinates. If |
coordx_dyn |
A list of |
cloud |
Logical; if |
distance |
String specifying the spatial distance. Default is |
grid |
Logical; if |
maxdist |
Numeric; maximum spatial distance to be considered in semivariogram estimation. See Details. |
neighb |
Numeric; an optional positive integer indicating the order of neighborhood (useful for large datasets). See Details. |
maxtime |
Numeric; maximum temporal lag to be considered for spatio-temporal semivariograms. See Details. |
numbins |
Numeric; number of distance bins used to compute the binned semivariogram. See Details. |
radius |
Numeric; radius of the sphere when using great-circle distances. Default is 1. |
type |
String; type of semivariogram. Currently available: |
bivariate |
Logical; if |
subsample |
Numeric in |
subsample_t |
Numeric in |
We report the definition of the semivariogram in the spatial case; extensions to spatio-temporal and bivariate settings are based on the same principles.
For a spatial random field , the (classical) binned semivariogram estimator is
defined as
where is the set of all sample pairs whose spatial distance falls within a tolerance
region around lag (equally spaced intervals are used when cloud=FALSE).
The numbins argument sets the number of spatial lag bins used when cloud=FALSE.
The maxdist argument sets the maximum spatial distance considered in the estimation.
The maxdist option can be combined with neighb to reduce the number of pairs when handling
large datasets, by restricting computations to local neighborhoods.
The maxtime argument sets the maximum temporal lag considered for spatio-temporal semivariograms.
The subsample and subsample_t arguments provide additional control for large datasets by
using only a proportion of spatial locations and/or time points.
Returns an object of class Variogram.
An object of class Variogram is a list containing (at most) the following components:
bins |
Spatial distance bins if |
bint |
Temporal distance bins if |
cloud |
Logical; |
centers |
Centers of the spatial bins. |
distance |
Type of spatial distance. |
lenbins |
Number of pairs in each spatial bin. |
lenbinst |
Number of pairs in each spatio-temporal bin. |
lenbint |
Number of pairs in each temporal bin. |
maxdist |
Maximum spatial distance used in the estimation; |
maxtime |
Maximum temporal lag used in the estimation; |
spacetime_dyn |
Logical; |
variograms |
Empirical spatial semivariogram. |
variogramst |
Empirical spatio-temporal semivariogram. |
variogramt |
Empirical temporal semivariogram. |
type |
Type of estimated semivariogram. |
Moreno Bevilacqua, [email protected], https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian Caamaño-Carrillo, [email protected], https://www.researchgate.net/profile/Christian-Caamano
Cressie, N. A. C. (1993) Statistics for Spatial Data. New York: Wiley.
Gaetan, C. and Guyon, X. (2010) Spatial Statistics and Modeling. Springer-Verlag, New York.
library(GeoModels) ################################################################ ### Example 1. Empirical semivariogram from a spatial Gaussian ### random field with Matérn correlation. ################################################################ set.seed(514) x = runif(200, 0, 1) y = runif(200, 0, 1) coords = cbind(x,y) corrmodel = "Matern" mean = 0 sill = 1 nugget = 0 scale = 0.3/3 smooth = 0.5 data = GeoSim(coordx=coords, corrmodel=corrmodel, param=list(mean=mean, smooth=smooth, sill=sill, nugget=nugget, scale=scale))$data vario = GeoVariogram(coordx=coords, data=data, maxdist=0.6) plot(vario, pch=20, ylim=c(0,1), ylab="Semivariogram", xlab="Distance") ################################################################ ### Example 2. Empirical semivariogram for a spatio-temporal ### Gaussian random field with Gneiting correlation. ################################################################ set.seed(331) x = runif(200, 0, 1) y = runif(200, 0, 1) coords = cbind(x,y) times = seq(1,10,1) data = GeoSim(coordx=coords, coordt=times, corrmodel="gneiting", param=list(mean=0, scale_s=0.08, scale_t=0.4, sill=1, nugget=0, power_s=1, power_t=1, sep=0.5))$data vario_st = GeoVariogram(data=data, coordx=coords, coordt=times, maxtime=7, maxdist=0.5) plot(vario_st, pch=20) ################################################################ ### Example 3. Empirical (cross-)semivariograms for a bivariate ### Gaussian random field with Bi-Matérn covariance. ################################################################ set.seed(293) x = runif(400, 0, 1) y = runif(400, 0, 1) coords = cbind(x,y) param = list(mean_1=0, mean_2=0, scale_1=0.1/3, scale_2=0.15/3, scale_12=0.15/3, sill_1=1, sill_2=1, nugget_1=0, nugget_2=0, smooth_1=0.5, smooth_12=0.5, smooth_2=0.5, pcol=0.3) data = GeoSim(coordx=coords, corrmodel="Bi_matern", param=param)$data biv_vario = GeoVariogram(data, coordx=coords, bivariate=TRUE, maxdist=0.5) plot(biv_vario, pch=20)library(GeoModels) ################################################################ ### Example 1. Empirical semivariogram from a spatial Gaussian ### random field with Matérn correlation. ################################################################ set.seed(514) x = runif(200, 0, 1) y = runif(200, 0, 1) coords = cbind(x,y) corrmodel = "Matern" mean = 0 sill = 1 nugget = 0 scale = 0.3/3 smooth = 0.5 data = GeoSim(coordx=coords, corrmodel=corrmodel, param=list(mean=mean, smooth=smooth, sill=sill, nugget=nugget, scale=scale))$data vario = GeoVariogram(coordx=coords, data=data, maxdist=0.6) plot(vario, pch=20, ylim=c(0,1), ylab="Semivariogram", xlab="Distance") ################################################################ ### Example 2. Empirical semivariogram for a spatio-temporal ### Gaussian random field with Gneiting correlation. ################################################################ set.seed(331) x = runif(200, 0, 1) y = runif(200, 0, 1) coords = cbind(x,y) times = seq(1,10,1) data = GeoSim(coordx=coords, coordt=times, corrmodel="gneiting", param=list(mean=0, scale_s=0.08, scale_t=0.4, sill=1, nugget=0, power_s=1, power_t=1, sep=0.5))$data vario_st = GeoVariogram(data=data, coordx=coords, coordt=times, maxtime=7, maxdist=0.5) plot(vario_st, pch=20) ################################################################ ### Example 3. Empirical (cross-)semivariograms for a bivariate ### Gaussian random field with Bi-Matérn covariance. ################################################################ set.seed(293) x = runif(400, 0, 1) y = runif(400, 0, 1) coords = cbind(x,y) param = list(mean_1=0, mean_2=0, scale_1=0.1/3, scale_2=0.15/3, scale_12=0.15/3, sill_1=1, sill_2=1, nugget_1=0, nugget_2=0, smooth_1=0.5, smooth_12=0.5, smooth_2=0.5, pcol=0.3) data = GeoSim(coordx=coords, corrmodel="Bi_matern", param=param)$data biv_vario = GeoVariogram(data, coordx=coords, bivariate=TRUE, maxdist=0.5) plot(biv_vario, pch=20)
Computes empirical semivariograms in multiple directions (e.g., 0, 45, 90, 135 degrees) to assess spatial anisotropy.
GeoVariogramDir(data, coordx, coordy = NULL, coordz = NULL, directions = c(0, 45, 90, 135), tolerance = 22.5, numbins = 13, maxdist = NULL, neighb = NULL, distance = "Eucl", subsample = 1)GeoVariogramDir(data, coordx, coordy = NULL, coordz = NULL, directions = c(0, 45, 90, 135), tolerance = 22.5, numbins = 13, maxdist = NULL, neighb = NULL, distance = "Eucl", subsample = 1)
data |
A numeric vector containing the observed values at each location. |
coordx |
Spatial coordinates. Either a numeric vector giving the first coordinate, or a matrix with 2 (or 3) columns.
If a matrix is provided, |
coordy |
A numeric vector of the second coordinate. Optional; defaults to |
coordz |
A numeric vector of the third coordinate (if needed). Optional; defaults to |
directions |
Numeric vector giving the principal directions (in degrees) for which the semivariogram is computed
(default: |
tolerance |
Angular tolerance (in degrees) around each direction (default: 22.5). |
numbins |
Number of distance bins for the empirical semivariogram (default: 13). |
maxdist |
Maximum spatial distance to consider between pairs. If |
neighb |
Number of nearest neighbors to use for each location. If |
distance |
Type of distance metric to use (default: |
subsample |
Numeric in |
The function computes empirical semivariograms for several directions by:
Selecting pairs of points within maxdist and among the neighb nearest neighbors using
GeoNeighIndex.
Computing squared differences for each selected pair.
Assigning each pair to a directional class if the vector connecting the pair falls within the specified angular tolerance around a given direction.
Binning pairs by distance and computing the average squared difference (semivariogram) within each bin.
The direction is defined in the xy-plane even in 3D. For 2D data, set coordz = NULL.
The subsample argument can be used to reduce computational cost by randomly selecting a subset of
spatial locations prior to pair construction. This is particularly useful for large datasets.
A list of class "GeoVariogramDir" with one element for each direction. Each element is a list with components:
centers |
Centers of the distance bins. |
gamma |
Empirical semivariogram values for each bin. |
npairs |
Number of point pairs in each bin. |
require(GeoModels) set.seed(960) NN <- 2500 coords <- cbind(runif(NN), runif(NN)) scale <- 0.5/3 param <- list(mean = 0, sill = 1, nugget = 0, scale = scale, smooth = 0.5) corrmodel <- "Matern" set.seed(951) data <- GeoSim(coordx = coords, corrmodel = corrmodel, model = "Gaussian", param = param)$data vario_dir <- GeoVariogramDir(data = data, coordx = coords, maxdist = 0.4, subsample = 0.5) plot(vario_dir, ylim = c(0,1))require(GeoModels) set.seed(960) NN <- 2500 coords <- cbind(runif(NN), runif(NN)) scale <- 0.5/3 param <- list(mean = 0, sill = 1, nugget = 0, scale = scale, smooth = 0.5) corrmodel <- "Matern" set.seed(951) data <- GeoSim(coordx = coords, corrmodel = corrmodel, model = "Gaussian", param = param)$data vario_dir <- GeoVariogramDir(data = data, coordx = coords, maxdist = 0.4, subsample = 0.5) plot(vario_dir, ylim = c(0,1))
the function returns the parameters' estimates of a random field obtained by the weigthed least squares estimator.
GeoWLS(data, coordx, coordy=NULL,coordz=NULL, coordt=NULL, coordx_dyn=NULL, corrmodel, distance="Eucl", fixed=NULL, grid=FALSE, maxdist=NULL,neighb=NULL, maxtime=NULL, model='Gaussian', optimizer='Nelder-Mead', numbins=NULL, radius=1, start=NULL, weighted=FALSE,optimization=TRUE)GeoWLS(data, coordx, coordy=NULL,coordz=NULL, coordt=NULL, coordx_dyn=NULL, corrmodel, distance="Eucl", fixed=NULL, grid=FALSE, maxdist=NULL,neighb=NULL, maxtime=NULL, model='Gaussian', optimizer='Nelder-Mead', numbins=NULL, radius=1, start=NULL, weighted=FALSE,optimization=TRUE)
data |
A |
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordz |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordt |
A numeric vector giving 1-dimension of
temporal coordinates. Optional argument, the default is |
coordx_dyn |
A list of |
corrmodel |
String; the name of a correlation model, for the
description (see |
distance |
String; the name of the spatial distance. The default is |
fixed |
A named list giving the values of the parameters that
will be considered as known values. The listed parameters for a
given correlation function will be not estimated, i.e. if
|
grid |
Logical; if |
maxdist |
A numeric value denoting the maximum distance, see
Details in |
neighb |
Numeric; an optional positive integer indicating the
order of neighborhood. See Details and |
maxtime |
Numeric; an optional positive value indicating the maximum
temporal lag considered.See Details and |
model |
String; the type of random field. |
optimizer |
String; the optimization algorithm
(see |
numbins |
A numeric value denoting the numbers of bins, see the Section Details |
radius |
Numeric; a value indicating the radius of the sphere when using the great circle distance. Default value is 1. |
start |
A named list with the initial values of the
parameters that are used by the numerical routines in maximization
procedure. |
weighted |
Logical; if |
optimization |
Logical; if |
The numbins parameter indicates the number of adjacent
intervals to consider in order to grouped distances with which to
compute the (weighted) lest squares.
The maxdist parameter indicates the maximum distance below which
the shorter distances will be considered in the calculation of
the (weigthed) least squares.
Returns an object of class WLS.
An object of class WLS is a list containing
at most the following components:
bins |
Adjacent intervals of grouped distances; |
bint |
Adjacent intervals of grouped temporal separations |
centers |
The centers of the bins; |
coordx |
The vector or matrix of spatial coordinates; |
coordy |
The vector of spatial coordinates; |
coordt |
The vector of temporal coordinates; |
convergence |
A string that denotes if convergence is reached; |
corrmodel |
The correlation model; |
data |
The vector or matrix of data; |
distance |
The type of spatial distance; |
fixed |
The vector of fixed parameters; |
iterations |
The number of iteration used by the numerical routine; |
maxdist |
The maximum spatial distance used for the calculation of the variogram used in least square estimation. If no spatial distance is specified then it is NULL; |
maxtime |
The maximum temporal distance used for the calculation of the variogram used in least square estimation. If no temporal distance is specified then it is NULL; |
message |
Extra message passed from the numerical routines; |
model |
The type of random fields; |
numcoord |
The number of spatial coordinates; |
numtime |
The number the temporal realisations of the random field; |
param |
The vector of parameters' estimates; |
variograms |
The empirical spatial variogram; |
variogramt |
The empirical temporal variogram; |
variogramst |
The empirical spatial-temporal variogram; |
weighted |
A logical value indicating if its the weighted method; |
wls |
The value of the least squares at the minimum. |
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
Cressie, N. A. C. (1993) Statistics for Spatial Data. New York: Wiley.
Gaetan, C. and Guyon, X. (2010) Spatial Statistics and Modelling. Spring Verlang, New York.
library(GeoModels) # Set the coordinates of the sites: set.seed(211) x <- runif(200, 0, 1) set.seed(98) y <- runif(200, 0, 1) coords <- cbind(x,y) ################################################################ ### ### Example 1. Least square fitting of a Gaussian random field ### with exponential correlation. ### ############################################################### # Set the model's parameters: corrmodel <- "Exponential" mean <- 0 sill <- 1 nugget <- 0 scale <- 0.15/3 param <- list(mean=0,sill=sill, nugget=nugget, scale=scale) # Simulation of the Gaussian random field: set.seed(2) data <- GeoSim(coordx=coords, corrmodel=corrmodel, param=param)$data fixed=list(nugget=0,mean=mean) start=list(scale=scale,sill=sill) # Least square fitting of the random field: fit <- GeoWLS(data=data,coordx=coords, corrmodel=corrmodel, fixed=fixed,start=start,maxdist=0.5) # Results: print(fit)library(GeoModels) # Set the coordinates of the sites: set.seed(211) x <- runif(200, 0, 1) set.seed(98) y <- runif(200, 0, 1) coords <- cbind(x,y) ################################################################ ### ### Example 1. Least square fitting of a Gaussian random field ### with exponential correlation. ### ############################################################### # Set the model's parameters: corrmodel <- "Exponential" mean <- 0 sill <- 1 nugget <- 0 scale <- 0.15/3 param <- list(mean=0,sill=sill, nugget=nugget, scale=scale) # Simulation of the Gaussian random field: set.seed(2) data <- GeoSim(coordx=coords, corrmodel=corrmodel, param=param)$data fixed=list(nugget=0,mean=mean) start=list(scale=scale,sill=sill) # Least square fitting of the random field: fit <- GeoWLS(data=data,coordx=coords, corrmodel=corrmodel, fixed=fixed,start=start,maxdist=0.5) # Results: print(fit)
Utility function that computes
() where is a covariance matrix and
is the matrix of of covariances between the observed location and the locations to predict.
Optionally, the quadratic form
can be computed. Both dense and sparse matrix representations are supported.
getInvC(covmatrix, CC, mse = TRUE)getInvC(covmatrix, CC, mse = TRUE)
covmatrix |
A covariance matrix:
|
CC |
Numeric matrix to be multiplied by the inverse of the
covariance matrix (length must match the dimension of
|
mse |
Logical. If |
For dense matrices the function uses the Cholesky decomposition provided
by FastGP::rcppeigen_get_chol.
For sparse matrices (class spam) the factorisation is performed
with spam::chol.spam.
If the covariance matrix is not positive definite an error is thrown.
A list with components
aNumeric vector: the product
.
bNumeric scalar: the quadratic form
(only if
mse = TRUE).
Moreno Bevilacqua, [email protected]
Subroutine called by GeoFit. The procedure estimates the model parameters by maximization of the log-likelihood.
Lik(copula,bivariate,coordx,coordy,coordz,coordt, coordx_dyn,corrmodel,data,fixed,flagcor,flagnuis, grid,lower,mdecomp,model,namescorr, namesnuis,namesparam,numcoord, numpairs,numparamcor,numtime,optimizer, onlyvar,param,radius,setup, spacetime,sparse,varest,taper,type, upper,ns,X,neighb,MM,aniso,score)Lik(copula,bivariate,coordx,coordy,coordz,coordt, coordx_dyn,corrmodel,data,fixed,flagcor,flagnuis, grid,lower,mdecomp,model,namescorr, namesnuis,namesparam,numcoord, numpairs,numparamcor,numtime,optimizer, onlyvar,param,radius,setup, spacetime,sparse,varest,taper,type, upper,ns,X,neighb,MM,aniso,score)
copula |
String; the type of copula. It can be "Beta" or "Gaussian" |
bivariate |
Logical; if |
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordz |
A numeric vector giving 1-dimension of
spatial coordinates; Optional argument, the default is |
coordt |
A numeric vector assigning 1-dimension of
temporal coordinates. Optional argument, the default is |
coordx_dyn |
A list of |
corrmodel |
Numeric; the id of the correlation model. |
data |
A numeric vector or a ( |
flagcor |
A numeric vector of flags denoting which correlation parameters have to be estimated. |
flagnuis |
A numeric verctor of flags denoting which nuisance parameters have to estimated. |
fixed |
A numeric vector of parameters that will be considered as known values. |
grid |
Logical; if |
lower |
An optional named list giving the values for the lower bound of the space parameter
when the optimizer is |
model |
Numeric; the id value of the density associated to the likelihood objects. |
namescorr |
String; the names of the correlation parameters. |
namesnuis |
String; the names of the nuisance parameters. |
namesparam |
String; the names of the parameters to be maximised. |
numcoord |
Numeric; the number of coordinates. |
numpairs |
Numeric; the number of pairs. |
numparamcor |
Numeric; the number of the correlation parameters. |
numtime |
Numeric; the number of temporal observations. |
mdecomp |
String; the type of matrix decomposition used in the simulation. Default is cholesky.
The other possible choices is |
optimizer |
String; the optimization algorithm
(see |
onlyvar |
Logical; if |
param |
A numeric vector of parameters. |
sparse |
Logical; if |
radius |
Numeric; the radius of the sphere when considering data on a sphere. |
ns |
Numeric: vector of number of location sites for each temporal instants |
setup |
A List of useful components for the estimation based on the maximum tapered likelihood. |
spacetime |
Logical; if the random field is spatial
( |
varest |
Logical; if |
taper |
String; the name of the taper correlation function. |
type |
String; the type of the likelihood objects. If |
upper |
An optional named list giving the values for the upper bound
of the space parameter when the optimizer is or |
X |
Numeric; Matrix of spatio(temporal)covariates in the linear mean specification. |
neighb |
Numeric;parameter for vecchia approximation using GPvecchia package |
MM |
Numeric;a non constant fixed mean |
aniso |
Logical; should anisotropy be considered? |
score |
Logical; should score function be computed? |
Return a list from an optim call.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
A matrix containing UTM coordinates and July average temperatures at 2500 location sites in Madagascar, averaged over the period 1970–2000.\
Data obtained using the Geodata package with the function worldclim_country.
data(madagascartemp)data(madagascartemp)
A numerical matrix of dimension .
Fick, S.E. and Hijmans, R.J. (2017).\ WorldClim 2: new 1 km spatial resolution climate surfaces for global land areas.\ International Journal of Climatology, 37(12), 4302–4315.
The procedure returns a list with the nuisance parameters of a given random field model.
MargParam(model, bivariate=FALSE,num_betas=c(1,1),copula=NULL)MargParam(model, bivariate=FALSE,num_betas=c(1,1),copula=NULL)
model |
String; the name of a random field. |
bivariate |
Logical; if |
num_betas |
Numerical; the nunber of mean parameters in the linear specification (default is 1) |
copula |
The type of copula. |
The function returns a list with the nuisance parameters of a given random field model.
Return a vector string of nuisance parameters.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
library(GeoModels) MargParam("Gaussian") MargParam("Binomial") MargParam("Weibull",num_betas=2) MargParam("SkewGaussian", num_betas=3) MargParam("SinhAsinh") MargParam("Beta2",copula="Clayton") MargParam("StudentT") ## note that in the bivariate case sill_1 e sill_2 are considered as correlation parameteres MargParam("Gaussian", bivariate=TRUE)library(GeoModels) MargParam("Gaussian") MargParam("Binomial") MargParam("Weibull",num_betas=2) MargParam("SkewGaussian", num_betas=3) MargParam("SinhAsinh") MargParam("Beta2",copula="Clayton") MargParam("StudentT") ## note that in the bivariate case sill_1 e sill_2 are considered as correlation parameteres MargParam("Gaussian", bivariate=TRUE)
Matrix decomposition.
MatDecomp(mtx, method)MatDecomp(mtx, method)
mtx |
numeric; a square positive or semipositive definite matrix. |
method |
string; the type of matrix decomposition.
Two possible choices: |
Decomposition of a square positive or positive semidefinite matrix.
Return a matrix decomposition
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
Square root, inverse and log determinant of a (semi)positive definite matrix, given a matrix decomposition.
MatSqrt(mat.decomp,method) MatInv(mtx) MatLogDet(mat.decomp,method)MatSqrt(mat.decomp,method) MatInv(mtx) MatLogDet(mat.decomp,method)
mtx |
numeric; a squared symmetric positive definite matrix. |
mat.decomp |
numeric; a matrix decomposition. |
method |
string; the type of matrix decomposition. Two possible choices: |
The function returna a square root or inverse or log determinant of a (semi)positive definite matrix using the function in the FastGP package.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
library(GeoModels) ################################################################ ### ### Example 1. Inverse of Covariance matrix associated to ### a Matern correlation model ### ############################################################### # Define the spatial-coordinates of the points: x <- runif(15, 0, 1) y <- runif(15, 0, 1) coords <- cbind(x,y) # Matern Parameters param=list(smooth=0.5,sill=1,scale=0.2,nugget=0) a=matrix <- GeoCovmatrix(coordx=coords, corrmodel="Matern", param=param) ## decomposition with cholesky method b=MatDecomp(a$covmat,method="cholesky") ## inverse of covariance matrix inverse=MatInv(a$covmat)library(GeoModels) ################################################################ ### ### Example 1. Inverse of Covariance matrix associated to ### a Matern correlation model ### ############################################################### # Define the spatial-coordinates of the points: x <- runif(15, 0, 1) y <- runif(15, 0, 1) coords <- cbind(x,y) # Matern Parameters param=list(smooth=0.5,sill=1,scale=0.2,nugget=0) a=matrix <- GeoCovmatrix(coordx=coords, corrmodel="Matern", param=param) ## decomposition with cholesky method b=MatDecomp(a$covmat,method="cholesky") ## inverse of covariance matrix inverse=MatInv(a$covmat)
Internal function handling Nuisance Parameters of a Random Field.
NuisParam(model, bivariate=FALSE,num_betas=c(1,1),copula=NULL)NuisParam(model, bivariate=FALSE,num_betas=c(1,1),copula=NULL)
model |
String; the name of a random field. |
bivariate |
Logical; if |
num_betas |
Numerical; the nunber of mean parameters in the linear specification (default is 1) |
copula |
The type of copula. |
The function returns a list with the nuisance parameters of a given random field model.
Return a vector string of nuisance parameters.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
Internal function handling Nuisance Parameters of a Random Field.
NuisParam2(model, bivariate=FALSE,num_betas=c(1,1),copula=NULL)NuisParam2(model, bivariate=FALSE,num_betas=c(1,1),copula=NULL)
model |
String; the name of a random field. |
bivariate |
Logical; if |
num_betas |
Numerical; the nunber of mean parameters in the linear specification (default is 1) |
copula |
The type of copula. |
The function returns a list with the nuisance parameters of a given random field model.
Return a vector string of nuisance parameters.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
Plot Spatial and Spatio-temporal correlation or covariance of (non) Gaussian random fields
for a given set of spatial or spatiotemporal distances
GeoCorrFct.
## S3 method for class 'GeoCorrFct' plot(x,type="p", ...)## S3 method for class 'GeoCorrFct' plot(x,type="p", ...)
x |
an object of the class |
type |
The type of graphic. The possible options are "p" and "l". If "p" then a point type graphic is displayed. Otherwise a lines type graphic displayed. |
... |
Other graphical options arguments.
|
Plot Spatial and Spatio-temporal correlation or covariance of (non) Gaussian random fields
Produces a plot. No values are returned.
GeoCorrFct for examples.
Plot empirical spatial, spatio-temporal and spatial bivariate semi-Variogram using
on object GeoVariogram.
## S3 method for class 'GeoVariogram' plot(x, ...)## S3 method for class 'GeoVariogram' plot(x, ...)
x |
an object of the class |
... |
other arguments to be passed to the function
|
This function plots empirical semi variogram in the spatial, spatio-temporal and spatial bivariate case
Produces a plot. No values are returned.
GeoVariogram for variogram computation and examples.
Plots empirical directional semi-variograms for objects of class "GeoVariogramDir" as produced by GeoVariogramDir.
All directions are displayed in a single plot, each with a different color and a legend indicating the direction (e.g., "0°", "45°", etc.).
## S3 method for class 'GeoVariogramDir' plot(x, ..., main = "Directional Empirical Semivariograms", pch = 20, lwd = 1, col = 1:8, ylab = "Semivariogram", xlab = "Distance")## S3 method for class 'GeoVariogramDir' plot(x, ..., main = "Directional Empirical Semivariograms", pch = 20, lwd = 1, col = 1:8, ylab = "Semivariogram", xlab = "Distance")
x |
An object of class |
main |
A main title for the plot. |
pch |
Plotting character (point type) for the points (default: 20). |
lwd |
Line width for the lines connecting points (default: 1). |
col |
A vector of colors, one for each direction (default: 1:8). |
ylab |
Label for the y-axis (default: "Semivariogram"). |
xlab |
Label for the x-axis (default: "Lag"). |
... |
Additional graphical parameters passed to |
This function plots all empirical directional semi-variograms in a single graph, using different colors and a legend in the top left corner that indicates the direction (e.g., "0°", "45°", etc.). Each direction is represented by points connected by lines.
Produces a plot. No values are returned.
GeoVariogramDir for directional variogram computation and examples.
A numeric matrix containing gridded April total precipitation (in mm) over the Netherlands, together with projected coordinates (UTM, km) and a distance-to-coast covariate (km). The precipitation field is derived from the WorldClim v2.1 monthly climatology for April (i.e., long-term monthly averages rather than a specific year).
data(rainNLD)data(rainNLD)
A numeric matrix with 71,401 rows and 4 columns:
Easting coordinate (UTM zone 31N), in kilometers.
Northing coordinate (UTM zone 31N), in kilometers.
Distance to the coastline, in kilometers (computed from Natural Earth coastline geometry, transformed to UTM).
April total precipitation, in millimeters.
Coordinates were projected from longitude/latitude (WGS84) to UTM zone 31N and rescaled to kilometers. The distance-to-coast covariate was computed as the Euclidean distance (in UTM) from each grid cell to the nearest coastline.
Fick, S.E., Hijmans, R.J. (2017) WorldClim 2: new 1km spatial resolution climate surfaces for global land areas. International Journal of Climatology, 37, 4302–4315.
Subroutine called by GeoSimapprox. The procedure return a simulation on a regular grid from a standard spatial Gaussian random field with a specified correlation model
SimCE(M,N,x,y,z,corrmodel,param,mean.val, max.ext)SimCE(M,N,x,y,z,corrmodel,param,mean.val, max.ext)
M |
Numeric; the dimension of x |
N |
Numeric; the dimension of y |
x |
A numeric |
y |
A numeric |
z |
A numeric |
corrmodel |
String; the name of a correlation model. |
param |
A list of parameter values required in the simulation procedure. |
mean.val |
The mean of the random field. |
max.ext |
The maximum extension of the simulation window. |
Return a list from an optim call.
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
Extracting information from an sp or spacetime object
sp2Geo(spobj,spdata = NULL)sp2Geo(spobj,spdata = NULL)
spobj |
An object of class sp or spacetime |
spdata |
Character: The name of data in the sp or spacetime object |
The function accepts as input a sp or spacetime object and the name of the data of interest in the object and it returns a list with some useful informations for Geomodels functions.
A list with spatio-temporal informations
Moreno Bevilacqua, [email protected],https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian", Caamaño-Carrillo, [email protected],https://www.researchgate.net/profile/Christian-Caamano
# Define the spatial-coordinates of the points: set.seed(3) N <- 30 # number of location sites x <- runif(N, 0, 1) set.seed(6) y <- runif(N, 0, 1) coords <- cbind(x,y) # Define spatial matrix covariates and regression parameters X <- cbind(rep(1,N),runif(N)) # Define spatial matrix dependent variable Y <- rnorm(nrow(X)) obj1 <- sp::SpatialPoints(coords) obj2 <- sp::SpatialPointsDataFrame(coords,data = data.frame(X,Y)) # sp2Geo info extraction b <- sp2Geo(obj2,spdata = "Y") class(b) b# Define the spatial-coordinates of the points: set.seed(3) N <- 30 # number of location sites x <- runif(N, 0, 1) set.seed(6) y <- runif(N, 0, 1) coords <- cbind(x,y) # Define spatial matrix covariates and regression parameters X <- cbind(rep(1,N),runif(N)) # Define spatial matrix dependent variable Y <- rnorm(nrow(X)) obj1 <- sp::SpatialPoints(coords) obj2 <- sp::SpatialPointsDataFrame(coords,data = data.frame(X,Y)) # sp2Geo info extraction b <- sp2Geo(obj2,spdata = "Y") class(b) b
A ()-matrix containing lon/lat
and august monthly average wind speed (2 m above the ground, meter/second) registered at 6000 location sites in the Iberian peninsula.
Data obtained from WorldClim version 2.1
data(spanish_wind)data(spanish_wind)
A numerical matrix of dimension .
Fick, S.E., Hijmans, R.J. (2017) WorldClim 2: new 1km spatial resolution climate surfaces for global land areas. International Journal of Climatology, 37, 4302–4315.
Subroutine called by the fitting procedures. The procedure initializes the parameters for the fitting procedure.
StartParam(coordx, coordy, coordz, coordt, coordx_dyn, corrmodel, data, distance, fcall, fixed, grid, likelihood, maxdist, neighb, maxtime, model, n, param, parscale, paramrange, radius, start, taper, tapsep, type, typereal, weighted, copula, X, memdist, nosym, p_neighb, thin_method)StartParam(coordx, coordy, coordz, coordt, coordx_dyn, corrmodel, data, distance, fcall, fixed, grid, likelihood, maxdist, neighb, maxtime, model, n, param, parscale, paramrange, radius, start, taper, tapsep, type, typereal, weighted, copula, X, memdist, nosym, p_neighb, thin_method)
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of spatial coordinates; optional argument, default is |
coordz |
A numeric vector giving 1-dimension of spatial coordinates; optional argument, default is |
coordt |
A numeric vector assigning 1-dimension of temporal coordinates. |
coordx_dyn |
A list of |
corrmodel |
String; the name of a correlation model. |
data |
A numeric vector or a ( |
distance |
String; the name of the spatial distance. Default is |
fcall |
String; |
fixed |
A named list giving the values of the parameters that will be considered as known values. |
grid |
Logical; if |
likelihood |
String; the configuration of the composite likelihood. |
maxdist |
Numeric; an optional positive value indicating the maximum spatial distance considered in the composite-likelihood computation. |
neighb |
Numeric; an optional positive integer indicating the order of neighborhood in the composite likelihood computation. See the Section Details for more information. |
maxtime |
Numeric; an optional positive value indicating the maximum temporal lag considered in the composite-likelihood computation. |
model |
String; the density associated to the likelihood objects. |
n |
Numeric; number of trials for binomial random fields. |
param |
A numeric vector of parameter values required in the simulation procedure of random fields. |
parscale |
A numeric vector of scaling factors to improve the maximizing procedure; see |
paramrange |
A numeric vector of parameter ranges; see |
radius |
Numeric; the radius of the sphere in the case of lon-lat coordinates.
The default is |
start |
A named list with the initial values of the parameters that are used by the numerical routines in the maximization procedure. |
taper |
String; the name of the type of covariance matrix. It can be |
tapsep |
Numeric; an optional value indicating the separability parameter in the space-time adaptive taper (see Details). |
type |
String; the type of likelihood objects. Temporary value set to |
typereal |
String; the real type of likelihood objects. See |
weighted |
Logical; if |
copula |
String; the type of copula. |
X |
Numeric; matrix of space-time covariates. |
memdist |
Logical; if |
nosym |
Logical; if |
p_neighb |
Numeric; a value in |
thin_method |
String; thinning scheme used when |
Internal function called by WlsStart.
A list with a set of useful information in the estimation procedure.
Moreno Bevilacqua, [email protected], https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian Caamaño-Carrillo, [email protected], https://www.researchgate.net/profile/Christian-Caamano
A matrix containing daily wind speeds, in kilometers per hour, from 1961 to 1978 at 12 sites in Ireland
data(winds)data(winds)
A ()-matrix containing wind speed observations.
Haslett, J. and Raftery, A. E. (1989), Space-time modelling with long-memory dependence: assessing Ireland's wind-power resource (with discussion), Applied Statistics, 38, 1–50.
A data frame containing information about the weather stations where the data are recorded in Ireland.
data(winds.coords)data(winds.coords)
A data frame containing site - the name of the city (character), abbr - the abbrevation (character), elev - the elevation (numeric), lat - latitude (numeric) and lon - longitude.
Haslett, J. and Raftery, A. E. (1989), Space-time modelling with long-memory dependence: assessing Ireland's wind-power resource (with discussion), Applied Statistics, 38, 1–50.
Subroutine called by GeoFit.
The function returns appropriate starting values for the
composite-likelihood fitting procedure based on weighted least squares.
WlsStart(coordx, coordy, coordz, coordt, coordx_dyn, corrmodel, data, distance, fcall, fixed, grid, likelihood, maxdist, neighb, maxtime, model, n, param, parscale, paramrange, radius, start, taper, tapsep, type, varest, weighted, copula, X, memdist, nosym, p_neighb, thin_method)WlsStart(coordx, coordy, coordz, coordt, coordx_dyn, corrmodel, data, distance, fcall, fixed, grid, likelihood, maxdist, neighb, maxtime, model, n, param, parscale, paramrange, radius, start, taper, tapsep, type, varest, weighted, copula, X, memdist, nosym, p_neighb, thin_method)
coordx |
A numeric ( |
coordy |
A numeric vector giving 1-dimension of spatial coordinates; optional argument, default is |
coordz |
A numeric vector giving 1-dimension of spatial coordinates; optional argument, default is |
coordt |
A numeric vector assigning 1-dimension of temporal coordinates. |
coordx_dyn |
A list of |
corrmodel |
String; the name of a correlation model. |
data |
A numeric vector or a ( |
distance |
String; the name of the spatial distance. Default is |
fcall |
String; |
fixed |
A named list giving the values of the parameters that will be considered as known values. |
grid |
Logical; if |
likelihood |
String; the configuration of the composite likelihood. |
maxdist |
Numeric; an optional positive value indicating the maximum spatial distance considered in the composite-likelihood computation. |
neighb |
Numeric; an optional positive integer indicating the order of neighborhood in the composite likelihood computation. |
maxtime |
Numeric; an optional positive value indicating the maximum temporal separation considered in the composite-likelihood computation. |
model |
String; the name of the model. |
n |
Numeric; number of trials in a binomial random field. |
param |
A numeric vector of parameter values required in the simulation procedure of random fields. |
parscale |
A numeric vector with scaling values for improving the maximisation routine. |
paramrange |
A numeric vector with the range of the parameter space. |
radius |
Numeric; a value indicating the radius of the sphere when using great circle distance.
Default value is the radius of the earth in km (i.e., |
start |
A numeric vector (or list) with starting values. |
taper |
String; the name of the type of covariance matrix. It can be |
tapsep |
Numeric; an optional value indicating the separability parameter in the space-time quasi taper (see Details). |
type |
String; the type of estimation method. |
varest |
Logical; if |
weighted |
Logical; if |
copula |
String; the type of copula. It can be |
X |
Numeric; matrix of spatio(temporal) covariates in the linear mean specification. |
memdist |
Logical; if |
nosym |
Logical; if |
p_neighb |
Numeric; a value in |
thin_method |
String; thinning scheme used when |
Internal function called by GeoFit.
A list with a set of useful information in the estimation procedure.
Moreno Bevilacqua, [email protected], https://sites.google.com/view/moreno-bevilacqua/home, Víctor Morales Oñate, [email protected], https://sites.google.com/site/moralesonatevictor/, Christian Caamaño-Carrillo, [email protected], https://www.researchgate.net/profile/Christian-Caamano