Title: | Fast Gaussian Process Computation Using Vecchia's Approximation |
---|---|
Description: | Functions for fitting and doing predictions with Gaussian process models using Vecchia's (1988) approximation. Package also includes functions for reordering input locations, finding ordered nearest neighbors (with help from 'FNN' package), grouping operations, and conditional simulations. Covariance functions for spatial and spatial-temporal data on Euclidean domains and spheres are provided. The original approximation is due to Vecchia (1988) <http://www.jstor.org/stable/2345768>, and the reordering and grouping methods are from Guinness (2018) <doi:10.1080/00401706.2018.1437476>. Model fitting employs a Fisher scoring algorithm described in Guinness (2019) <doi:10.48550/arXiv.1905.08374>. |
Authors: | Joseph Guinness [aut, cre], Matthias Katzfuss [aut], Youssef Fahmy [aut] |
Maintainer: | Joseph Guinness <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.5.1 |
Built: | 2024-11-16 06:23:24 UTC |
Source: | CRAN |
A dataset containing ocean temperature measurements from three pressure levels (depths), measured by profiling floats from the Argo program. Data collected in Jan, Feb, and March of 2016.
argo2016
argo2016
A data frame with 32436 rows and 6 columns
longitude in degrees between 0 and 360
latitude in degrees between -90 and 90
time in days
Temperature at 100 dbars (roughly 100 meters)
Temperature at 150 dbars (roughly 150 meters)
Temperature at 200 dbars (roughly 200 meters)
Mikael Kuusela. Argo program: https://argo.ucsd.edu/
With the prediction locations ordered after the observation locations, an approximation for the inverse Cholesky of the covariance matrix is computed, and standard formulas are applied to obtain a conditional simulation.
cond_sim( fit = NULL, locs_pred, X_pred, y_obs = fit$y, locs_obs = fit$locs, X_obs = fit$X, beta = fit$betahat, covparms = fit$covparms, covfun_name = fit$covfun_name, m = 60, reorder = TRUE, st_scale = NULL, nsims = 1 )
cond_sim( fit = NULL, locs_pred, X_pred, y_obs = fit$y, locs_obs = fit$locs, X_obs = fit$X, beta = fit$betahat, covparms = fit$covparms, covfun_name = fit$covfun_name, m = 60, reorder = TRUE, st_scale = NULL, nsims = 1 )
fit |
GpGp_fit object, the result of |
locs_pred |
prediction locations |
X_pred |
Design matrix for predictions |
y_obs |
Observations associated with locs_obs |
locs_obs |
observation locations |
X_obs |
Design matrix for observations |
beta |
Linear mean parameters |
covparms |
Covariance parameters |
covfun_name |
Name of covariance function |
m |
Number of nearest neighbors to use. Larger |
reorder |
TRUE/FALSE for whether reordering should be done. This should generally be kept at TRUE, unless testing out the effect of reordering. |
st_scale |
amount by which to scale the spatial and temporal
dimensions for the purpose of selecting neighbors. We recommend setting
this manually when using a spatial-temporal covariance function. When
|
nsims |
Number of conditional simulations to return. |
We can specify either a GpGp_fit object (the result of
fit_model
), OR manually enter the covariance function and
parameters, the observations, observation locations, and design matrix. We
must specify the prediction locations and the prediction design matrix.
compute condition number of matrix
condition_number(info)
condition_number(info)
info |
matrix |
expit function and integral of expit function
expit(x) intexpit(x)
expit(x) intexpit(x)
x |
argument to expit or intexpit function |
From a matrix of locations and covariance parameters of the form (variance, L11, L21, L22, nugget), return the square matrix of all pairwise covariances.
exponential_anisotropic2D(covparms, locs) d_exponential_anisotropic2D(covparms, locs)
exponential_anisotropic2D(covparms, locs) d_exponential_anisotropic2D(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, L11, L21, L22, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_exponential_anisotropic2D()
: Derivatives of anisotropic exponential covariance
The covariance parameter vector is (variance, L11, L21, L22, nugget) where L11, L21, L22, are the three non-zero entries of a lower-triangular matrix L. The covariances are
This means that L11 is interpreted as an inverse range parameter in the
first dimension.
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, L11, L21, L22, L31, L32, L33, nugget), return the square matrix of all pairwise covariances.
exponential_anisotropic3D(covparms, locs) d_exponential_anisotropic3D(covparms, locs)
exponential_anisotropic3D(covparms, locs) d_exponential_anisotropic3D(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, L11, L21, L22, L31, L32, L33, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_exponential_anisotropic3D()
: Derivatives of anisotropic exponential covariance
The covariance parameter vector is (variance, L11, L21, L22, L31, L32, L33, nugget) where L11, L21, L22, L31, L32, L33 are the six non-zero entries of a lower-triangular matrix L. The covariances are
This means that L11 is interpreted as an inverse range parameter in the
first dimension.
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, B11, B12, B13, B22, B23, B33, smoothness, nugget), return the square matrix of all pairwise covariances.
exponential_anisotropic3D_alt(covparms, locs) d_exponential_anisotropic3D_alt(covparms, locs)
exponential_anisotropic3D_alt(covparms, locs) d_exponential_anisotropic3D_alt(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, B11, B12, B13, B22, B23, B33, smoothness, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_exponential_anisotropic3D_alt()
: Derivatives of anisotropic Matern covariance
The covariance parameter vector is (variance, B11, B12, B13, B22, B23, B33, smoothness, nugget) where B11, B12, B13, B22, B23, B33, transform the three coordinates as
(B13,B23) can be interpreted as a drift vector in space over time if first two dimensions are space and third is time. Assuming x is transformed to u and y transformed to v, the covariances are
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, range, nugget), return the square matrix of all pairwise covariances.
exponential_isotropic(covparms, locs) d_exponential_isotropic(covparms, locs) d_matern15_isotropic(covparms, locs) d_matern25_isotropic(covparms, locs)
exponential_isotropic(covparms, locs) d_exponential_isotropic(covparms, locs) d_matern15_isotropic(covparms, locs) d_matern25_isotropic(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, range, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_exponential_isotropic()
: Derivatives of isotropic exponential covariance
d_matern15_isotropic()
: Derivatives of isotropic
matern covariance with smoothness 1.5
d_matern25_isotropic()
: Derivatives of isotropic
matern covariance function with smoothness 2.5
The covariance parameter vector is (variance, range, nugget)
= , and the covariance function is parameterized
as
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, range, nugget, <nonstat variance parameters>), return the square matrix of all pairwise covariances.
exponential_nonstat_var(covparms, Z) d_exponential_nonstat_var(covparms, Z)
exponential_nonstat_var(covparms, Z) d_exponential_nonstat_var(covparms, Z)
covparms |
A vector with covariance parameters
in the form (variance, range, nugget, <nonstat variance parameters>).
The number of nonstationary variance parameters should equal |
Z |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_exponential_nonstat_var()
: Derivatives with respect to parameters
This covariance function multiplies the isotropic exponential covariance by a nonstationary variance function. The form of the covariance is
where M(x,y) is the isotropic exponential covariance, and
where are the spatial basis functions
contained in the last
p
columns of Z
, and
are the nonstationary variance parameters.
From a matrix of locations and covariance parameters of the form (variance, range_1, ..., range_d, nugget), return the square matrix of all pairwise covariances.
exponential_scaledim(covparms, locs) d_exponential_scaledim(covparms, locs)
exponential_scaledim(covparms, locs) d_exponential_scaledim(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, range_1, ..., range_d, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_exponential_scaledim()
: Derivatives with respect to parameters
The covariance parameter vector is (variance, range_1, ..., range_d, nugget). The covariance function is parameterized as
where D is a diagonal matrix with (range_1, ..., range_d) on the diagonals.
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, range_1, range_2, nugget), return the square matrix of all pairwise covariances.
exponential_spacetime(covparms, locs) d_exponential_spacetime(covparms, locs)
exponential_spacetime(covparms, locs) d_exponential_spacetime(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, range_1, range_2, nugget). range_1 is the spatial range, and range_2 is the temporal range. |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_exponential_spacetime()
: Derivatives with respect to parameters
The covariance parameter vector is (variance, range_1, range_2, nugget). The covariance function is parameterized as
where D is a diagonal matrix with (range_1, ..., range_1, range_2) on the diagonals.
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
From a matrix of longitudes and latitudes and a vector covariance parameters of the form (variance, range, nugget), return the square matrix of all pairwise covariances.
exponential_sphere(covparms, lonlat) d_exponential_sphere(covparms, lonlat)
exponential_sphere(covparms, lonlat) d_exponential_sphere(covparms, lonlat)
covparms |
A vector with covariance parameters in the form (variance, range, nugget). Range parameter assumes that the sphere has radius 1 (units are radians). |
lonlat |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at lonlat[i,]
and
lonlat[j,]
.
d_exponential_sphere()
: Derivatives with respect to parameters
The function first calculates the (x,y,z) 3D coordinates, and then inputs
the resulting locations into exponential_isotropic
. This means that we construct
covariances on the sphere by embedding the sphere in a 3D space. There has been some
concern expressed in the literature that such embeddings may produce distortions.
The source and nature of such distortions has never been articulated,
and to date, no such distortions have been documented. Guinness and
Fuentes (2016) argue that 3D embeddings produce reasonable models for data on spheres.
From a matrix of longitudes and latitudes and a vector covariance parameters of the form (variance, range, nugget, <5 warping parameters>), return the square matrix of all pairwise covariances.
exponential_sphere_warp(covparms, lonlat) d_exponential_sphere_warp(covparms, lonlat)
exponential_sphere_warp(covparms, lonlat) d_exponential_sphere_warp(covparms, lonlat)
covparms |
A vector with covariance parameters in the form (variance, range, nugget, <5 warping parameters>). Range parameter assumes that the sphere has radius 1 (units are radians). |
lonlat |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at lonlat[i,]
and
lonlat[j,]
.
d_exponential_sphere_warp()
: Derivatives with respect to parameters
The function first calculates the (x,y,z) 3D coordinates, and then "warps"
the locations to , where
is a warping
function composed of gradients of spherical harmonic functions of degree 2.
See Guinness (2019, "Gaussian Process Learning via Fisher Scoring of
Vecchia's Approximation") for details.
The warped locations are input into
exponential_isotropic
.
From a matrix of longitudes, latitudes, and times, and a vector covariance parameters of the form (variance, range_1, range_2, nugget), return the square matrix of all pairwise covariances.
exponential_spheretime(covparms, lonlattime) d_exponential_spheretime(covparms, lonlattime)
exponential_spheretime(covparms, lonlattime) d_exponential_spheretime(covparms, lonlattime)
covparms |
A vector with covariance parameters in the form (variance, range_1, range_2, nugget), where range_1 is a spatial range (assuming sphere of radius 1), and range_2 is a temporal range. |
lonlattime |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at lonlattime[i,]
and
lonlattime[j,]
.
d_exponential_spheretime()
: Derivatives with respect to parameters.
The function first calculates the (x,y,z) 3D coordinates, and then inputs
the resulting locations into exponential_spacetime
. This means that we construct
covariances on the sphere by embedding the sphere in a 3D space. There has been some
concern expressed in the literature that such embeddings may produce distortions.
The source and nature of such distortions has never been articulated,
and to date, no such distortions have been documented. Guinness and
Fuentes (2016) argue that 3D embeddings produce reasonable models for data on spheres.
From a matrix of longitudes, latitudes, times, and a vector covariance parameters of the form (variance, range_1, range_2, nugget, <5 warping parameters>), return the square matrix of all pairwise covariances.
exponential_spheretime_warp(covparms, lonlattime) d_exponential_spheretime_warp(covparms, lonlattime)
exponential_spheretime_warp(covparms, lonlattime) d_exponential_spheretime_warp(covparms, lonlattime)
covparms |
A vector with covariance parameters in the form (variance, range_1, range_2, nugget, <5 warping parameters>). range_1 is a spatial range parameter that assumes that the sphere has radius 1 (units are radians). range_2 is a temporal range parameter. |
lonlattime |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at lonlat[i,]
and
lonlat[j,]
.
d_exponential_spheretime_warp()
: Derivatives with respect to parameters
The function first calculates the (x,y,z) 3D coordinates, and then "warps"
the locations to , where
is a warping
function composed of gradients of spherical harmonic functions of degree 2.
See Guinness (2019, "Gaussian Process Learning via Fisher Scoring of
Vecchia's Approximation") for details.
The warped locations are input into
exponential_spacetime
. The function
does not do temporal warping.
Calculates an approximation to the inverse Cholesky factor of the covariance matrix using Vecchia's approximation, then the simulation is produced by solving a linear system with a vector of uncorrelated standard normals
fast_Gp_sim(covparms, covfun_name = "matern_isotropic", locs, m = 30)
fast_Gp_sim(covparms, covfun_name = "matern_isotropic", locs, m = 30)
covparms |
A vector of covariance parameters appropriate for the specified covariance function |
covfun_name |
See |
locs |
matrix of locations. Row |
m |
Number of nearest neighbors to use in approximation |
vector of simulated values
locs <- as.matrix( expand.grid( (1:50)/50, (1:50)/50 ) ) y <- fast_Gp_sim(c(4,0.2,0.5,0), "matern_isotropic", locs, 30 ) fields::image.plot( matrix(y,50,50) )
locs <- as.matrix( expand.grid( (1:50)/50, (1:50)/50 ) ) y <- fast_Gp_sim(c(4,0.2,0.5,0), "matern_isotropic", locs, 30 ) fields::image.plot( matrix(y,50,50) )
In situations where we want to do many gaussian process
simulations from the same model, we can compute Linverse
once and reuse it, rather than recomputing for each identical simulation.
This function also allows the user to input the vector of standard normals z
.
fast_Gp_sim_Linv(Linv, NNarray, z = NULL)
fast_Gp_sim_Linv(Linv, NNarray, z = NULL)
Linv |
Matrix containing the entries of Linverse, usually the output from
|
NNarray |
Matrix of nearest neighbor indices, usually the output from |
z |
Optional vector of standard normals. If not specified, these are computed within the function. |
vector of simulated values
locs <- as.matrix( expand.grid( (1:50)/50, (1:50)/50 ) ) ord <- order_maxmin(locs) locsord <- locs[ord,] m <- 10 NNarray <- find_ordered_nn(locsord,m) covparms <- c(2, 0.2, 1, 0) Linv <- vecchia_Linv( covparms, "matern_isotropic", locsord, NNarray ) y <- fast_Gp_sim_Linv(Linv,NNarray) y[ord] <- y fields::image.plot( matrix(y,50,50) )
locs <- as.matrix( expand.grid( (1:50)/50, (1:50)/50 ) ) ord <- order_maxmin(locs) locsord <- locs[ord,] m <- 10 NNarray <- find_ordered_nn(locsord,m) covparms <- c(2, 0.2, 1, 0) Linv <- vecchia_Linv( covparms, "matern_isotropic", locsord, NNarray ) y <- fast_Gp_sim_Linv(Linv,NNarray) y[ord] <- y fields::image.plot( matrix(y,50,50) )
Given a matrix of locations, find the m
nearest neighbors
to each location, subject to the neighbors coming
previously in the ordering. The algorithm uses the kdtree
algorithm in the FNN package, adapted to the setting
where the nearest neighbors must come from previous
in the ordering.
find_ordered_nn(locs, m, lonlat = FALSE, st_scale = NULL)
find_ordered_nn(locs, m, lonlat = FALSE, st_scale = NULL)
locs |
A matrix of locations. Each row of |
m |
Number of neighbors to return |
lonlat |
TRUE/FALSE whether locations are longitudes and latitudes. |
st_scale |
factor by which to scale the spatial and temporal coordinates
for distance calculations. The function assumes that the last column of
the locations is the temporal dimension, and the rest of the columns
are spatial dimensions. The spatial dimensions are divided by |
An matrix containing the indices of the neighbors. Row i
of the
returned matrix contains the indices of the nearest m
locations to the i
'th location. Indices are ordered within a
row to be increasing in distance. By convention, we consider a location
to neighbor itself, so the first entry of row i
is i
, the
second entry is the index of the nearest location, and so on. Because each
location neighbors itself, the returned matrix has m+1
columns.
locs <- as.matrix( expand.grid( (1:40)/40, (1:40)/40 ) ) ord <- order_maxmin(locs) # calculate an ordering locsord <- locs[ord,] # reorder locations m <- 20 NNarray <- find_ordered_nn(locsord,20) # find ordered nearest 20 neighbors ind <- 100 # plot all locations in gray, first ind locations in black, # ind location with magenta circle, m neighhbors with blue circle plot( locs[,1], locs[,2], pch = 16, col = "gray" ) points( locsord[1:ind,1], locsord[1:ind,2], pch = 16 ) points( locsord[ind,1], locsord[ind,2], col = "magenta", cex = 1.5 ) points( locsord[NNarray[ind,2:(m+1)],1], locsord[NNarray[ind,2:(m+1)],2], col = "blue", cex = 1.5 )
locs <- as.matrix( expand.grid( (1:40)/40, (1:40)/40 ) ) ord <- order_maxmin(locs) # calculate an ordering locsord <- locs[ord,] # reorder locations m <- 20 NNarray <- find_ordered_nn(locsord,20) # find ordered nearest 20 neighbors ind <- 100 # plot all locations in gray, first ind locations in black, # ind location with magenta circle, m neighhbors with blue circle plot( locs[,1], locs[,2], pch = 16, col = "gray" ) points( locsord[1:ind,1], locsord[1:ind,2], pch = 16 ) points( locsord[ind,1], locsord[ind,2], col = "magenta", cex = 1.5 ) points( locsord[NNarray[ind,2:(m+1)],1], locsord[NNarray[ind,2:(m+1)],2], col = "blue", cex = 1.5 )
Naive brute force nearest neighbor finder
find_ordered_nn_brute(locs, m)
find_ordered_nn_brute(locs, m)
locs |
matrix of locations |
m |
number of neighbors |
An matrix containing the indices of the neighbors. Row i
of the
returned matrix contains the indices of the nearest m
locations to the i
'th location. Indices are ordered within a
row to be increasing in distance. By convention, we consider a location
to neighbor itself, so the first entry of row i
is i
, the
second entry is the index of the nearest location, and so on. Because each
location neighbors itself, the returned matrix has m+1
columns.
Fisher scoring algorithm
fisher_scoring( likfun, start_parms, link, silent = FALSE, convtol = 1e-04, max_iter = 40 )
fisher_scoring( likfun, start_parms, link, silent = FALSE, convtol = 1e-04, max_iter = 40 )
likfun |
likelihood function, returns likelihood, gradient, and hessian |
start_parms |
starting values of parameters |
link |
link function for parameters (used for printing) |
silent |
TRUE/FALSE for suppressing output |
convtol |
convergence tolerance on step dot grad |
max_iter |
maximum number of Fisher scoring iterations |
Given a response, set of locations, (optionally) a design matrix, and a specified covariance function, return the maximum Vecchia likelihood estimates, obtained with a Fisher scoring algorithm.
fit_model( y, locs, X = NULL, covfun_name = "matern_isotropic", NNarray = NULL, start_parms = NULL, reorder = TRUE, group = TRUE, m_seq = c(10, 30), max_iter = 40, fixed_parms = NULL, silent = FALSE, st_scale = NULL, convtol = 1e-04 )
fit_model( y, locs, X = NULL, covfun_name = "matern_isotropic", NNarray = NULL, start_parms = NULL, reorder = TRUE, group = TRUE, m_seq = c(10, 30), max_iter = 40, fixed_parms = NULL, silent = FALSE, st_scale = NULL, convtol = 1e-04 )
y |
response vector |
locs |
matrix of locations. Each row is a single spatial or spatial-temporal location. If using one of the covariance functions for data on a sphere, the first column should be longitudes (-180,180) and the second column should be latitudes (-90,90). If using a spatial-temporal covariance function, the last column should contain the times. |
X |
design matrix. Each row contains covariates for the corresponding
observation in |
covfun_name |
string name of a covariance function.
See |
NNarray |
Optionally specified array of nearest neighbor indices,
usually from the output of |
start_parms |
Optionally specified starting values for parameters.
If |
reorder |
TRUE/FALSE indicating whether maxmin ordering should be used
(TRUE) or whether no reordering should be done before fitting (FALSE).
If you want
to use a customized reordering, then manually reorder |
group |
TRUE/FALSE for whether to use the grouped version of the approximation (Guinness, 2018) or not. The grouped version is used by default and is always recommended. |
m_seq |
Sequence of values for number of neighbors. By default,
a 10-neighbor
approximation is maximized, then a 30-neighbor approximation is
maximized using the
10 neighbor estimates as starting values.
However, one can specify any sequence
of numbers of neighbors, e.g. |
max_iter |
maximum number of Fisher scoring iterations |
fixed_parms |
Indices of covariance parameters you would like to fix
at specific values. If you decide to fix any parameters, you must specify
their values in |
silent |
TRUE/FALSE for whether to print some information during fitting. |
st_scale |
Scaling for spatial and temporal ranges. Only applicable for
spatial-temporal models, where it is used in distance
calculations when selecting neighbors. |
convtol |
Tolerance for exiting the optimization.
Fisher scoring is stopped
when the dot product between the step and the gradient
is less than |
fit_model
is a user-friendly model fitting function
that automatically performs many of the auxiliary tasks needed for
using Vecchia's approximation, including reordering, computing
nearest neighbors, grouping, and optimization. The likelihoods use a small
penalty on small nuggets, large spatial variances,
and small smoothness parameter.
The Jason-3 windspeed vignette and the Argo temperature
vignette are useful sources for a
use-cases of the fit_model
function for data on sphere.
The example below shows a very small example with a simulated dataset in 2d.
An object of class GpGp_fit
, which is a list containing
covariance parameter estimates, regression coefficients,
covariance matrix for mean parameter estimates, as well as some other
information relevant to the model fit.
n1 <- 20 n2 <- 20 n <- n1*n2 locs <- as.matrix( expand.grid( (1:n1)/n1, (1:n2)/n2 ) ) covparms <- c(2,0.1,1/2,0) y <- 7 + fast_Gp_sim(covparms, "matern_isotropic", locs) X <- as.matrix( rep(1,n) ) ## not run # fit <- fit_model(y, locs, X, "matern_isotropic") # fit
n1 <- 20 n2 <- 20 n <- n1*n2 locs <- as.matrix( expand.grid( (1:n1)/n1, (1:n2)/n2 ) ) covparms <- c(2,0.1,1/2,0) y <- 7 + fast_Gp_sim(covparms, "matern_isotropic", locs) X <- as.matrix( rep(1,n) ) ## not run # fit <- fit_model(y, locs, X, "matern_isotropic") # fit
get link function, whether locations are lonlat and space time
get_linkfun(covfun_name)
get_linkfun(covfun_name)
covfun_name |
string name of covariance function |
get penalty function
get_penalty(y, X, locs, covfun_name)
get_penalty(y, X, locs, covfun_name)
y |
response |
X |
design matrix |
locs |
locations |
covfun_name |
string name of covariance function |
get default starting values of covariance parameters
get_start_parms(y, X, locs, covfun_name)
get_start_parms(y, X, locs, covfun_name)
y |
response |
X |
design matrix |
locs |
locations |
covfun_name |
string name of covariance function |
Vecchia's (1988) Gaussian process approximation has emerged among its competitors as a leader in computational scalability and accuracy. This package includes implementations of the original approximation, as well as several updates to it, including the reordered and grouped versions of the approximation outlined in Guinness (2018) and the Fisher scoring algorithm described in Guinness (2019). The package supports spatial models, spatial-temporal models, models on spheres, and some nonstationary models.
The main functions of the package are fit_model
,
and predictions
.
fit_model
returns estimates of covariance parameters
and linear mean parameters. The user is expected to select a covariance function
and specify it with a string. Currently supported covariance functions are
If there are
covariates, they can be expressed via a design matrix X
, each row containing
the covariates corresponding to the same row in locs
.
For predictions
, the user should specify prediction locations
locs_pred
and a prediction design matrix X_pred
.
The vignettes are intended to be helpful for getting a sense of how these functions work.
For Gaussian process researchers, the package also provides access to functions for computing the likelihood, gradient, and Fisher information with respect to covariance parameters; reordering functions, nearest neighbor-finding functions, grouping (partitioning) functions, and approximate simulation functions.
Maintainer: Joseph Guinness [email protected]
Authors:
Matthias Katzfuss [email protected]
Youssef Fahmy [email protected]
Take in an array of nearest neighbors, and automatically partition the array into groups that share neighbors. This is helpful to speed the computations and improve their accuracy. The function returns a list, with each list element containing one or several rows of NNarray. The algorithm attempts to find groupings such that observations within a group share many common neighbors.
group_obs(NNarray, exponent = 2)
group_obs(NNarray, exponent = 2)
NNarray |
Matrix of nearest neighbor indices, usually the result of |
exponent |
Within the algorithm, two groups are merged if the number of unique
neighbors raised to the |
A list with elements defining the grouping. The list entries are:
all_inds
: vector of all indices of all blocks.
last_ind_of_block
: The i
th entry tells us the
location in all_inds
of the last index of the i
th block. Thus the length
of last_ind_of_block
is the number of blocks, and last_ind_of_block
can
be used to chop all_inds
up into blocks.
global_resp_inds
: The i
th entry tells us the
index of the i
th response, as ordered in all_inds
.
local_resp_inds
: The i
th entry tells us the location within
the block of the response index.
last_resp_of_block
: The i
th entry tells us the
location within local_resp_inds
and global_resp_inds
of the last
index of the i
th block. last_resp_of_block
is to
global_resp_inds
and local_resp_inds
as last_ind_of_block
is to all_inds
.
locs <- matrix( runif(200), 100, 2 ) # generate random locations ord <- order_maxmin(locs) # calculate an ordering locsord <- locs[ord,] # reorder locations m <- 10 NNarray <- find_ordered_nn(locsord,m) # m nearest neighbor indices NNlist2 <- group_obs(NNarray) # join blocks if joining reduces squares NNlist3 <- group_obs(NNarray,3) # join blocks if joining reduces cubes object.size(NNarray) object.size(NNlist2) object.size(NNlist3) mean( NNlist2[["local_resp_inds"]] - 1 ) # average number of neighbors (exponent 2) mean( NNlist3[["local_resp_inds"]] - 1 ) # average number of neighbors (exponent 3) all_inds <- NNlist2$all_inds last_ind_of_block <- NNlist2$last_ind_of_block inds_of_block_2 <- all_inds[ (last_ind_of_block[1] + 1):last_ind_of_block[2] ] local_resp_inds <- NNlist2$local_resp_inds global_resp_inds <- NNlist2$global_resp_inds last_resp_of_block <- NNlist2$last_resp_of_block local_resp_of_block_2 <- local_resp_inds[(last_resp_of_block[1]+1):last_resp_of_block[2]] global_resp_of_block_2 <- global_resp_inds[(last_resp_of_block[1]+1):last_resp_of_block[2]] inds_of_block_2[local_resp_of_block_2] # these last two should be the same
locs <- matrix( runif(200), 100, 2 ) # generate random locations ord <- order_maxmin(locs) # calculate an ordering locsord <- locs[ord,] # reorder locations m <- 10 NNarray <- find_ordered_nn(locsord,m) # m nearest neighbor indices NNlist2 <- group_obs(NNarray) # join blocks if joining reduces squares NNlist3 <- group_obs(NNarray,3) # join blocks if joining reduces cubes object.size(NNarray) object.size(NNlist2) object.size(NNlist3) mean( NNlist2[["local_resp_inds"]] - 1 ) # average number of neighbors (exponent 2) mean( NNlist3[["local_resp_inds"]] - 1 ) # average number of neighbors (exponent 3) all_inds <- NNlist2$all_inds last_ind_of_block <- NNlist2$last_ind_of_block inds_of_block_2 <- all_inds[ (last_ind_of_block[1] + 1):last_ind_of_block[2] ] local_resp_inds <- NNlist2$local_resp_inds global_resp_inds <- NNlist2$global_resp_inds last_resp_of_block <- NNlist2$last_resp_of_block local_resp_of_block_2 <- local_resp_inds[(last_resp_of_block[1]+1):last_resp_of_block[2]] global_resp_of_block_2 <- global_resp_inds[(last_resp_of_block[1]+1):last_resp_of_block[2]] inds_of_block_2[local_resp_of_block_2] # these last two should be the same
A dataset containing lightly preprocessed windspeed values from the Jason-3 satellite. Observations near clouds and ice have been removed, and the data have been aggregated (averaged) over 10 second intervals. Jason-3 reports windspeeds over the ocean only. The data are from a six day period between August 4 and 9 of 2016.
jason3
jason3
A data frame with 18973 rows and 4 columns
wind speed, in maters per second
longitude in degrees between 0 and 360
latitude in degrees between -90 and 90
time in seconds from midnight August 4
https://www.ncei.noaa.gov/products/jason-satellite-products
Vecchia's approximation implies a sparse approximation to the inverse Cholesky factor of the covariance matrix. This function returns the result of multiplying the inverse of that matrix by a vector (i.e. an approximation to the Cholesky factor).
L_mult(Linv, z, NNarray)
L_mult(Linv, z, NNarray)
Linv |
Entries of the sparse inverse Cholesky factor,
usually the output from |
z |
the vector to be multiplied |
NNarray |
A matrix of indices, usually the output from |
the product of the Cholesky factor with a vector
n <- 2000 locs <- matrix( runif(2*n), n, 2 ) covparms <- c(2, 0.2, 0.75, 0.1) ord <- order_maxmin(locs) NNarray <- find_ordered_nn(locs,20) Linv <- vecchia_Linv( covparms, "matern_isotropic", locs, NNarray ) z <- rnorm(n) y1 <- fast_Gp_sim_Linv(Linv,NNarray,z) y2 <- L_mult(Linv, z, NNarray) print( sum( (y1-y2)^2 ) )
n <- 2000 locs <- matrix( runif(2*n), n, 2 ) covparms <- c(2, 0.2, 0.75, 0.1) ord <- order_maxmin(locs) NNarray <- find_ordered_nn(locs,20) Linv <- vecchia_Linv( covparms, "matern_isotropic", locs, NNarray ) z <- rnorm(n) y1 <- fast_Gp_sim_Linv(Linv,NNarray,z) y2 <- L_mult(Linv, z, NNarray) print( sum( (y1-y2)^2 ) )
Vecchia's approximation implies a sparse approximation to the inverse Cholesky factor of the covariance matrix. This function returns the result of multiplying the transpose of the inverse of that matrix by a vector (i.e. an approximation to the transpose of the Cholesky factor).
L_t_mult(Linv, z, NNarray)
L_t_mult(Linv, z, NNarray)
Linv |
Entries of the sparse inverse Cholesky factor,
usually the output from |
z |
the vector to be multiplied |
NNarray |
A matrix of indices, usually the output from |
the product of the transpose of the Cholesky factor with a vector
n <- 2000 locs <- matrix( runif(2*n), n, 2 ) covparms <- c(2, 0.2, 0.75, 0.1) NNarray <- find_ordered_nn(locs,20) Linv <- vecchia_Linv( covparms, "matern_isotropic", locs, NNarray ) z1 <- rnorm(n) z2 <- L_t_mult(Linv, z1, NNarray)
n <- 2000 locs <- matrix( runif(2*n), n, 2 ) covparms <- c(2, 0.2, 0.75, 0.1) NNarray <- find_ordered_nn(locs,20) Linv <- vecchia_Linv( covparms, "matern_isotropic", locs, NNarray ) z1 <- rnorm(n) z2 <- L_t_mult(Linv, z1, NNarray)
Vecchia's approximation implies a sparse approximation to the inverse Cholesky factor of the covariance matrix. This function returns the result of multiplying that matrix by a vector.
Linv_mult(Linv, z, NNarray)
Linv_mult(Linv, z, NNarray)
Linv |
Entries of the sparse inverse Cholesky factor,
usually the output from |
z |
the vector to be multiplied |
NNarray |
A matrix of indices, usually the output from |
the product of the sparse inverse Cholesky factor with a vector
n <- 2000 locs <- matrix( runif(2*n), n, 2 ) covparms <- c(2, 0.2, 0.75, 0.1) ord <- order_maxmin(locs) NNarray <- find_ordered_nn(locs,20) Linv <- vecchia_Linv( covparms, "matern_isotropic", locs, NNarray ) z1 <- rnorm(n) y <- fast_Gp_sim_Linv(Linv,NNarray,z1) z2 <- Linv_mult(Linv, y, NNarray) print( sum( (z1-z2)^2 ) )
n <- 2000 locs <- matrix( runif(2*n), n, 2 ) covparms <- c(2, 0.2, 0.75, 0.1) ord <- order_maxmin(locs) NNarray <- find_ordered_nn(locs,20) Linv <- vecchia_Linv( covparms, "matern_isotropic", locs, NNarray ) z1 <- rnorm(n) y <- fast_Gp_sim_Linv(Linv,NNarray,z1) z2 <- Linv_mult(Linv, y, NNarray) print( sum( (z1-z2)^2 ) )
Vecchia's approximation implies a sparse approximation to the inverse Cholesky factor of the covariance matrix. This function returns the result of multiplying the transpose of that matrix by a vector.
Linv_t_mult(Linv, z, NNarray)
Linv_t_mult(Linv, z, NNarray)
Linv |
Entries of the sparse inverse Cholesky factor,
usually the output from |
z |
the vector to be multiplied |
NNarray |
A matrix of indices, usually the output from |
the product of the transpose of the sparse inverse Cholesky factor with a vector
n <- 2000 locs <- matrix( runif(2*n), n, 2 ) covparms <- c(2, 0.2, 0.75, 0.1) NNarray <- find_ordered_nn(locs,20) Linv <- vecchia_Linv( covparms, "matern_isotropic", locs, NNarray ) z1 <- rnorm(n) z2 <- Linv_t_mult(Linv, z1, NNarray)
n <- 2000 locs <- matrix( runif(2*n), n, 2 ) covparms <- c(2, 0.2, 0.75, 0.1) NNarray <- find_ordered_nn(locs,20) Linv <- vecchia_Linv( covparms, "matern_isotropic", locs, NNarray ) z1 <- rnorm(n) z2 <- Linv_t_mult(Linv, z1, NNarray)
From a matrix of locations and covariance parameters of the form (variance, L11, L21, L22, smoothness, nugget), return the square matrix of all pairwise covariances.
matern_anisotropic2D(covparms, locs) d_matern_anisotropic2D(covparms, locs)
matern_anisotropic2D(covparms, locs) d_matern_anisotropic2D(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, L11, L21, L22, smoothness, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_matern_anisotropic2D()
: Derivatives of anisotropic Matern covariance
The covariance parameter vector is (variance, L11, L21, L22, smoothness, nugget) where L11, L21, L22, are the three non-zero entries of a lower-triangular matrix L. The covariances are
This means that L11 is interpreted as an inverse range parameter in the
first dimension.
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, L11, L21, L22, L31, L32, L33, smoothness, nugget), return the square matrix of all pairwise covariances.
matern_anisotropic3D(covparms, locs) d_matern_anisotropic3D(covparms, locs) d_matern_anisotropic3D_alt(covparms, locs)
matern_anisotropic3D(covparms, locs) d_matern_anisotropic3D(covparms, locs) d_matern_anisotropic3D_alt(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, L11, L21, L22, L31, L32, L33, smoothness, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_matern_anisotropic3D()
: Derivatives of anisotropic Matern covariance
d_matern_anisotropic3D_alt()
: Derivatives of anisotropic Matern covariance
The covariance parameter vector is (variance, L11, L21, L22, L31, L32, L33, smoothness, nugget) where L11, L21, L22, L31, L32, L33 are the six non-zero entries of a lower-triangular matrix L. The covariances are
This means that L11 is interpreted as an inverse range parameter in the
first dimension.
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, B11, B12, B13, B22, B23, B33, smoothness, nugget), return the square matrix of all pairwise covariances.
matern_anisotropic3D_alt(covparms, locs)
matern_anisotropic3D_alt(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, B11, B12, B13, B22, B23, B33, smoothness, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
The covariance parameter vector is (variance, B11, B12, B13, B22, B23, B33, smoothness, nugget) where B11, B12, B13, B22, B23, B33, transform the three coordinates as
NOTE: the u_1 transformation is different from previous versions of this function. NOTE: now (B13,B23) can be interpreted as a drift vector in space over time. Assuming x is transformed to u and y transformed to v, the covariances are
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, range, smoothness, category variance, nugget), return the square matrix of all pairwise covariances.
matern_categorical(covparms, locs) d_matern_categorical(covparms, locs)
matern_categorical(covparms, locs) d_matern_categorical(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, range, smoothness, category variance, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_matern_categorical()
: Derivatives of isotropic Matern covariance
The covariance parameter vector is (variance, range, smoothness, category variance, nugget)
= , and the covariance function is parameterized
as
The nugget value is added to the diagonal of the covariance matrix.
The category variance
is added if two observation from same category
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, range, smoothness, nugget), return the square matrix of all pairwise covariances.
matern_isotropic(covparms, locs) d_matern_isotropic(covparms, locs)
matern_isotropic(covparms, locs) d_matern_isotropic(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, range, smoothness, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_matern_isotropic()
: Derivatives of isotropic Matern covariance
The covariance parameter vector is (variance, range, smoothness, nugget)
= , and the covariance function is parameterized
as
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, range, smoothness, nugget, <nonstat variance parameters>), return the square matrix of all pairwise covariances.
matern_nonstat_var(covparms, Z) d_matern_nonstat_var(covparms, Z)
matern_nonstat_var(covparms, Z) d_matern_nonstat_var(covparms, Z)
covparms |
A vector with covariance parameters
in the form (variance, range, smoothness, nugget, <nonstat variance parameters>).
The number of nonstationary variance parameters should equal |
Z |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_matern_nonstat_var()
: Derivatives with respect to parameters
This covariance function multiplies the isotropic Matern covariance by a nonstationary variance function. The form of the covariance is
where M(x,y) is the isotropic Matern covariance, and
where are the spatial basis functions
contained in the last
p
columns of Z
, and
are the nonstationary variance parameters.
From a matrix of locations and covariance parameters of the form (variance, range_1, ..., range_d, smoothness, nugget), return the square matrix of all pairwise covariances.
matern_scaledim(covparms, locs) d_matern_scaledim(covparms, locs)
matern_scaledim(covparms, locs) d_matern_scaledim(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, range_1, ..., range_d, smoothness, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_matern_scaledim()
: Derivatives with respect to parameters
The covariance parameter vector is (variance, range_1, ..., range_d, smoothness, nugget). The covariance function is parameterized as
where D is a diagonal matrix with (range_1, ..., range_d) on the diagonals.
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, range_1, range_2, smoothness, nugget), return the square matrix of all pairwise covariances.
matern_spacetime(covparms, locs) d_matern_spacetime(covparms, locs)
matern_spacetime(covparms, locs) d_matern_spacetime(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, range_1, range_2, smoothness, nugget). range_1 is the spatial range, and range_2 is the temporal range. |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_matern_spacetime()
: Derivatives with respect to parameters
The covariance parameter vector is (variance, range_1, range_2, smoothness, nugget). The covariance function is parameterized as
where D is a diagonal matrix with (range_1, ..., range_1, range_2) on the diagonals.
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, spatial range, temporal range, smoothness, category, nugget), return the square matrix of all pairwise covariances.
matern_spacetime_categorical(covparms, locs) d_matern_spacetime_categorical(covparms, locs)
matern_spacetime_categorical(covparms, locs) d_matern_spacetime_categorical(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, spatial range, temporal range, smoothness, category, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_matern_spacetime_categorical()
: Derivatives of isotropic Matern covariance
The covariance parameter vector is (variance, range, smoothness, category, nugget)
= , and the covariance function is parameterized
as
(x,s) and (y,t) are the space-time locations of a pair of observations.
The nugget value is added to the diagonal of the covariance matrix.
The category variance
is added if two observation from same category
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, spatial range, temporal range, smoothness, cat variance, cat spatial range, cat temporal range, cat smoothness, nugget), return the square matrix of all pairwise covariances. This is the covariance for the following model for data from cateogory k
where Z_0 is Matern with parameters (variance,spatial range,temporal range,smoothness) and Z_1,...,Z_K are independent Materns with parameters (cat variance, cat spatial range, cat temporal range, cat smoothness), and e_1, ..., e_n are independent normals with variance (variance * nugget)
matern_spacetime_categorical_local(covparms, locs) d_matern_spacetime_categorical_local(covparms, locs)
matern_spacetime_categorical_local(covparms, locs) d_matern_spacetime_categorical_local(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, spatial range, temporal range, smoothness, category, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_matern_spacetime_categorical_local()
: Derivatives of isotropic Matern covariance
The covariance parameter vector is (variance, range, smoothness, category, nugget)
= , and the covariance function is parameterized
as
(x,s) and (y,t) are the space-time locations of a pair of observations.
The nugget value is added to the diagonal of the covariance matrix.
The category variance
is added if two observation from same category
NOTE: the nugget is
, not
.
From a matrix of longitudes and latitudes and a vector covariance parameters of the form (variance, range, smoothness, nugget), return the square matrix of all pairwise covariances.
matern_sphere(covparms, lonlat) d_matern_sphere(covparms, lonlat)
matern_sphere(covparms, lonlat) d_matern_sphere(covparms, lonlat)
covparms |
A vector with covariance parameters in the form (variance, range, smoothness, nugget). Range parameter assumes that the sphere has radius 1 (units are radians). |
lonlat |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at lonlat[i,]
and
lonlat[j,]
.
d_matern_sphere()
: Derivatives with respect to parameters
The function first calculates the (x,y,z) 3D coordinates, and then inputs
the resulting locations into matern_isotropic
. This means that we construct
covariances on the sphere by embedding the sphere in a 3D space. There has been some
concern expressed in the literature that such embeddings may produce distortions.
The source and nature of such distortions has never been articulated,
and to date, no such distortions have been documented. Guinness and
Fuentes (2016) argue that 3D embeddings produce reasonable models for data on spheres.
From a matrix of longitudes and latitudes and a vector covariance parameters of the form (variance, range, smoothness, nugget, <5 warping parameters>), return the square matrix of all pairwise covariances.
matern_sphere_warp(covparms, lonlat) d_matern_sphere_warp(covparms, lonlat)
matern_sphere_warp(covparms, lonlat) d_matern_sphere_warp(covparms, lonlat)
covparms |
A vector with covariance parameters in the form (variance, range, smoothness, nugget, <5 warping parameters>). Range parameter assumes that the sphere has radius 1 (units are radians). |
lonlat |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at lonlat[i,]
and
lonlat[j,]
.
d_matern_sphere_warp()
: Derivatives with respect to parameters.
The function first calculates the (x,y,z) 3D coordinates, and then "warps"
the locations to , where
is a warping
function composed of gradients of spherical harmonic functions of degree 2.
See Guinness (2019, "Gaussian Process Learning via Fisher Scoring of
Vecchia's Approximation") for details.
The warped locations are input into
matern_isotropic
.
From a matrix of longitudes, latitudes, and times, and a vector covariance parameters of the form (variance, range_1, range_2, smoothness, nugget), return the square matrix of all pairwise covariances.
matern_spheretime(covparms, lonlattime) d_matern_spheretime(covparms, lonlattime)
matern_spheretime(covparms, lonlattime) d_matern_spheretime(covparms, lonlattime)
covparms |
A vector with covariance parameters in the form (variance, range_1, range_2, smoothness, nugget), where range_1 is a spatial range (assuming sphere of radius 1), and range_2 is a temporal range. |
lonlattime |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at lonlattime[i,]
and
lonlattime[j,]
.
d_matern_spheretime()
: Derivatives with respect to parameters
The function first calculates the (x,y,z) 3D coordinates, and then inputs
the resulting locations into matern_spacetime
. This means that we construct
covariances on the sphere by embedding the sphere in a 3D space. There has been some
concern expressed in the literature that such embeddings may produce distortions.
The source and nature of such distortions has never been articulated,
and to date, no such distortions have been documented. Guinness and
Fuentes (2016) argue that 3D embeddings produce reasonable models for data on spheres.
From a matrix of longitudes, latitudes, times, and a vector covariance parameters of the form (variance, range_1, range_2, smoothness, nugget, <5 warping parameters>), return the square matrix of all pairwise covariances.
matern_spheretime_warp(covparms, lonlattime) d_matern_spheretime_warp(covparms, lonlattime)
matern_spheretime_warp(covparms, lonlattime) d_matern_spheretime_warp(covparms, lonlattime)
covparms |
A vector with covariance parameters in the form (variance, range_1, range_2, smoothness, nugget, <5 warping parameters>). range_1 is a spatial range parameter that assumes that the sphere has radius 1 (units are radians). range_2 is a temporal range parameter. |
lonlattime |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at lonlat[i,]
and
lonlat[j,]
.
d_matern_spheretime_warp()
: Derivatives with respect to parameters
The function first calculates the (x,y,z) 3D coordinates, and then "warps"
the locations to , where
is a warping
function composed of gradients of spherical harmonic functions of degree 2.
See Guinness (2019, "Gaussian Process Learning via Fisher Scoring of
Vecchia's Approximation") for details.
The warped locations are input into
matern_spacetime
. The function
does not do temporal warping.
From a matrix of locations and covariance parameters of the form (variance, range, nugget), return the square matrix of all pairwise covariances.
matern15_isotropic(covparms, locs)
matern15_isotropic(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, range, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
The covariance parameter vector is (variance, range, nugget)
= , and the covariance function is parameterized
as
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, range_1, ..., range_d, nugget), return the square matrix of all pairwise covariances.
matern15_scaledim(covparms, locs) d_matern15_scaledim(covparms, locs)
matern15_scaledim(covparms, locs) d_matern15_scaledim(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, range_1, ..., range_d, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_matern15_scaledim()
: Derivatives with respect to parameters
The covariance parameter vector is (variance, range_1, ..., range_d, nugget). The covariance function is parameterized as
where D is a diagonal matrix with (range_1, ..., range_d) on the diagonals.
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, range, nugget), return the square matrix of all pairwise covariances.
matern25_isotropic(covparms, locs)
matern25_isotropic(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, range, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
The covariance parameter vector is (variance, range, nugget)
= , and the covariance function is parameterized
as
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, range_1, ..., range_d, nugget), return the square matrix of all pairwise covariances.
matern25_scaledim(covparms, locs) d_matern25_scaledim(covparms, locs)
matern25_scaledim(covparms, locs) d_matern25_scaledim(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, range_1, ..., range_d, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_matern25_scaledim()
: Derivatives with respect to parameters
The covariance parameter vector is (variance, range_1, ..., range_d, nugget). The covariance function is parameterized as
where D is a diagonal matrix with (range_1, ..., range_d) on the diagonals.
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, range, nugget), return the square matrix of all pairwise covariances.
matern35_isotropic(covparms, locs) d_matern35_isotropic(covparms, locs) d_matern45_isotropic(covparms, locs)
matern35_isotropic(covparms, locs) d_matern35_isotropic(covparms, locs) d_matern45_isotropic(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, range, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_matern35_isotropic()
: Derivatives of isotropic
matern covariance function with smoothness 3.5
d_matern45_isotropic()
: Derivatives of isotropic
matern covariance function with smoothness 3.5
The covariance parameter vector is (variance, range, nugget)
= , and the covariance function is parameterized
as
where c_0 = 1, c_1 = 1, c_2 = 2/5, c_3 = 1/15.
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, range_1, ..., range_d, nugget), return the square matrix of all pairwise covariances.
matern35_scaledim(covparms, locs) d_matern35_scaledim(covparms, locs) d_matern45_scaledim(covparms, locs)
matern35_scaledim(covparms, locs) d_matern35_scaledim(covparms, locs) d_matern45_scaledim(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, range_1, ..., range_d, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
d_matern35_scaledim()
: Derivatives with respect to parameters
d_matern45_scaledim()
: Derivatives with respect to parameters
The covariance parameter vector is (variance, range_1, ..., range_d, nugget). The covariance function is parameterized as
where c_0 = 1, c_1 = 1, c_2 = 2/5, c_3 = 1/15.
where D is a diagonal matrix with (range_1, ..., range_d) on the diagonals.
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, range, nugget), return the square matrix of all pairwise covariances.
matern45_isotropic(covparms, locs)
matern45_isotropic(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, range, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
The covariance parameter vector is (variance, range, nugget)
= , and the covariance function is parameterized
as
where c_0 = 1, c_1 = 1, c_2 = 3/7, c_3 = 2/21, c_4 = 1/105.
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
From a matrix of locations and covariance parameters of the form (variance, range_1, ..., range_d, nugget), return the square matrix of all pairwise covariances.
matern45_scaledim(covparms, locs)
matern45_scaledim(covparms, locs)
covparms |
A vector with covariance parameters in the form (variance, range_1, ..., range_d, nugget) |
locs |
A matrix with |
A matrix with n
rows and n
columns, with the i,j entry
containing the covariance between observations at locs[i,]
and
locs[j,]
.
The covariance parameter vector is (variance, range_1, ..., range_d, nugget). The covariance function is parameterized as
where c_0 = 1, c_1 = 1, c_2 = 3/7, c_3 = 2/21, c_4 = 1/105.
where D is a diagonal matrix with (range_1, ..., range_d) on the diagonals.
The nugget value is added to the diagonal of the covariance matrix.
NOTE: the nugget is
, not
.
Return the ordering of locations sorted along one of the coordinates or the sum of multiple coordinates
order_coordinate(locs, coordinate)
order_coordinate(locs, coordinate)
locs |
A matrix of locations. Each row of |
coordinate |
integer or vector of integers in (1,...,d). If a single integer,
coordinates are ordered along that coordinate. If multiple integers,
coordinates are ordered according to the sum of specified coordinate values. For example,
when |
A vector of indices giving the ordering, i.e. the first element of this vector is the index of the first location.
n <- 100 # Number of locations d <- 2 # dimension of domain locs <- matrix( runif(n*d), n, d ) ord1 <- order_coordinate(locs, 1 ) ord12 <- order_coordinate(locs, c(1,2) )
n <- 100 # Number of locations d <- 2 # dimension of domain locs <- matrix( runif(n*d), n, d ) ord1 <- order_coordinate(locs, 1 ) ord12 <- order_coordinate(locs, c(1,2) )
Return the ordering of locations increasing in their distance to some specified location
order_dist_to_point(locs, loc0, lonlat = FALSE)
order_dist_to_point(locs, loc0, lonlat = FALSE)
locs |
A matrix of locations. Each row of |
loc0 |
A vector containing a single location in R^d. |
lonlat |
TRUE/FALSE whether locations are longitudes and latitudes. |
A vector of indices giving the ordering, i.e.
the first element of this vector is the index of the location nearest to loc0
.
n <- 100 # Number of locations d <- 2 # dimension of domain locs <- matrix( runif(n*d), n, d ) loc0 <- c(1/2,1/2) ord <- order_dist_to_point(locs,loc0)
n <- 100 # Number of locations d <- 2 # dimension of domain locs <- matrix( runif(n*d), n, d ) loc0 <- c(1/2,1/2) ord <- order_dist_to_point(locs,loc0)
Return the indices of an approximation to the maximum minimum distance ordering. A point in the center is chosen first, and then each successive point is chosen to maximize the minimum distance to previously selected points
order_maxmin(locs, lonlat = FALSE, space_time = FALSE, st_scale = NULL)
order_maxmin(locs, lonlat = FALSE, space_time = FALSE, st_scale = NULL)
locs |
A matrix of locations. Each row of |
lonlat |
TRUE/FALSE whether locations are longitudes and latitudes. |
space_time |
TRUE if locations are euclidean space-time locations, FALSE otherwise. If set to TRUE, temporal dimension is ignored. |
st_scale |
two-vector giving the amount by which the spatial
and temporal coordinates are scaled. If |
A vector of indices giving the ordering, i.e. the first element of this vector is the index of the first location.
# planar coordinates nvec <- c(50,50) locs <- as.matrix( expand.grid( 1:nvec[1]/nvec[1], 1:nvec[2]/nvec[2] ) ) ord <- order_maxmin(locs) par(mfrow=c(1,3)) plot( locs[ord[1:100],1], locs[ord[1:100],2], xlim = c(0,1), ylim = c(0,1) ) plot( locs[ord[1:300],1], locs[ord[1:300],2], xlim = c(0,1), ylim = c(0,1) ) plot( locs[ord[1:900],1], locs[ord[1:900],2], xlim = c(0,1), ylim = c(0,1) ) # longitude/latitude coordinates (sphere) latvals <- seq(-80, 80, length.out = 40 ) lonvals <- seq( 0, 360, length.out = 81 )[1:80] locs <- as.matrix( expand.grid( lonvals, latvals ) ) ord <- order_maxmin(locs, lonlat = TRUE) par(mfrow=c(1,3)) plot( locs[ord[1:100],1], locs[ord[1:100],2], xlim = c(0,360), ylim = c(-90,90) ) plot( locs[ord[1:300],1], locs[ord[1:300],2], xlim = c(0,360), ylim = c(-90,90) ) plot( locs[ord[1:900],1], locs[ord[1:900],2], xlim = c(0,360), ylim = c(-90,90) )
# planar coordinates nvec <- c(50,50) locs <- as.matrix( expand.grid( 1:nvec[1]/nvec[1], 1:nvec[2]/nvec[2] ) ) ord <- order_maxmin(locs) par(mfrow=c(1,3)) plot( locs[ord[1:100],1], locs[ord[1:100],2], xlim = c(0,1), ylim = c(0,1) ) plot( locs[ord[1:300],1], locs[ord[1:300],2], xlim = c(0,1), ylim = c(0,1) ) plot( locs[ord[1:900],1], locs[ord[1:900],2], xlim = c(0,1), ylim = c(0,1) ) # longitude/latitude coordinates (sphere) latvals <- seq(-80, 80, length.out = 40 ) lonvals <- seq( 0, 360, length.out = 81 )[1:80] locs <- as.matrix( expand.grid( lonvals, latvals ) ) ord <- order_maxmin(locs, lonlat = TRUE) par(mfrow=c(1,3)) plot( locs[ord[1:100],1], locs[ord[1:100],2], xlim = c(0,360), ylim = c(-90,90) ) plot( locs[ord[1:300],1], locs[ord[1:300],2], xlim = c(0,360), ylim = c(-90,90) ) plot( locs[ord[1:900],1], locs[ord[1:900],2], xlim = c(0,360), ylim = c(-90,90) )
Return the ordering of locations increasing in their distance to the average location
order_middleout(locs, lonlat = FALSE)
order_middleout(locs, lonlat = FALSE)
locs |
A matrix of locations. Each row of |
lonlat |
TRUE/FALSE whether locations are longitudes and latitudes. |
A vector of indices giving the ordering, i.e. the first element of this vector is the index of the location nearest the center.
n <- 100 # Number of locations d <- 2 # dimension of domain locs <- matrix( runif(n*d), n, d ) ord <- order_middleout(locs)
n <- 100 # Number of locations d <- 2 # dimension of domain locs <- matrix( runif(n*d), n, d ) ord <- order_middleout(locs)
penalize large values of parameter: penalty, 1st deriative, 2nd derivative
pen_hi(x, tt, aa) dpen_hi(x, tt, aa) ddpen_hi(x, tt, aa)
pen_hi(x, tt, aa) dpen_hi(x, tt, aa) ddpen_hi(x, tt, aa)
x |
argument to penalty |
tt |
scale parameter of penalty |
aa |
location parameter of penalty |
penalize small values of parameter: penalty, 1st deriative, 2nd derivative
pen_lo(x, tt, aa) dpen_lo(x, tt, aa) ddpen_lo(x, tt, aa)
pen_lo(x, tt, aa) dpen_lo(x, tt, aa) ddpen_lo(x, tt, aa)
x |
argument to penalty |
tt |
scale parameter of penalty |
aa |
location parameter of penalty |
penalize small values of log parameter: penalty, 1st deriative, 2nd derivative
pen_loglo(x, tt, aa) dpen_loglo(x, tt, aa) ddpen_loglo(x, tt, aa)
pen_loglo(x, tt, aa) dpen_loglo(x, tt, aa) ddpen_loglo(x, tt, aa)
x |
argument to penalty |
tt |
scale parameter of penalty |
aa |
location parameter of penalty |
With the prediction locations ordered after the observation locations, an approximation for the inverse Cholesky of the covariance matrix is computed, and standard formulas are applied to obtain the conditional expectation.
predictions( fit = NULL, locs_pred, X_pred, y_obs = fit$y, locs_obs = fit$locs, X_obs = fit$X, beta = fit$betahat, covparms = fit$covparms, covfun_name = fit$covfun_name, m = 60, reorder = TRUE, st_scale = NULL )
predictions( fit = NULL, locs_pred, X_pred, y_obs = fit$y, locs_obs = fit$locs, X_obs = fit$X, beta = fit$betahat, covparms = fit$covparms, covfun_name = fit$covfun_name, m = 60, reorder = TRUE, st_scale = NULL )
fit |
GpGp_fit object, the result of |
locs_pred |
prediction locations |
X_pred |
Design matrix for predictions |
y_obs |
Observations associated with locs_obs |
locs_obs |
observation locations |
X_obs |
Design matrix for observations |
beta |
Linear mean parameters |
covparms |
Covariance parameters |
covfun_name |
Name of covariance function |
m |
Number of nearest neighbors to use |
reorder |
TRUE/FALSE for whether reordering should be done. This should generally be kept at TRUE, unless testing out the effect of reordering. |
st_scale |
amount by which to scale the spatial and temporal
dimensions for the purpose of selecting neighbors. We recommend setting
this manually when using a spatial-temporal covariance function. When
|
We can specify either a GpGp_fit object (the result of
fit_model
), OR manually enter the covariance function and
parameters, the observations, observation locations, and design matrix. We
must specify the prediction locations and the prediction design matrix.
compute gradient of spherical harmonics functions
sph_grad_xyz(xyz, Lmax)
sph_grad_xyz(xyz, Lmax)
xyz |
xyz coordinates of locations on sphere |
Lmax |
largest degree of spherical harmonics. Current only Lmax=2 supported |
Print summary of GpGp fit
## S3 method for class 'GpGp_fit' summary(object, ...)
## S3 method for class 'GpGp_fit' summary(object, ...)
object |
Object of class "GpGp_fit", usually the return value from
|
... |
additional arguments, for compatability with S3 generic 'summary' |
test likelihood object for NA or Inf values
test_likelihood_object(likobj)
test_likelihood_object(likobj)
likobj |
likelihood object |
This function returns a grouped version (Guinness, 2018) of Vecchia's (1988) approximation to the Gaussian loglikelihood. The approximation modifies the ordered conditional specification of the joint density; rather than each term in the product conditioning on all previous observations, each term conditions on a small subset of previous observations.
vecchia_grouped_meanzero_loglik(covparms, covfun_name, y, locs, NNlist)
vecchia_grouped_meanzero_loglik(covparms, covfun_name, y, locs, NNlist)
covparms |
A vector of covariance parameters appropriate for the specified covariance function |
covfun_name |
See |
y |
vector of response values |
locs |
matrix of locations. Row |
NNlist |
A neighbor list object, the output from |
a list containing
loglik
: the loglikelihood
n1 <- 20 n2 <- 20 n <- n1*n2 locs <- as.matrix( expand.grid( (1:n1)/n1, (1:n2)/n2 ) ) covparms <- c(2, 0.2, 0.75, 0) y <- fast_Gp_sim(covparms, "matern_isotropic", locs, 50 ) ord <- order_maxmin(locs) NNarray <- find_ordered_nn(locs,20) NNlist <- group_obs(NNarray) #loglik <- vecchia_grouped_meanzero_loglik( covparms, "matern_isotropic", y, locs, NNlist )
n1 <- 20 n2 <- 20 n <- n1*n2 locs <- as.matrix( expand.grid( (1:n1)/n1, (1:n2)/n2 ) ) covparms <- c(2, 0.2, 0.75, 0) y <- fast_Gp_sim(covparms, "matern_isotropic", locs, 50 ) ord <- order_maxmin(locs) NNarray <- find_ordered_nn(locs,20) NNlist <- group_obs(NNarray) #loglik <- vecchia_grouped_meanzero_loglik( covparms, "matern_isotropic", y, locs, NNlist )
This function returns a grouped version (Guinness, 2018) of Vecchia's (1988) approximation to the Gaussian loglikelihood and the profile likelihood estimate of the regression coefficients. The approximation modifies the ordered conditional specification of the joint density; rather than each term in the product conditioning on all previous observations, each term conditions on a small subset of previous observations.
vecchia_grouped_profbeta_loglik(covparms, covfun_name, y, X, locs, NNlist)
vecchia_grouped_profbeta_loglik(covparms, covfun_name, y, X, locs, NNlist)
covparms |
A vector of covariance parameters appropriate for the specified covariance function |
covfun_name |
See |
y |
vector of response values |
X |
Design matrix of covariates. Row |
locs |
matrix of locations. Row |
NNlist |
A neighbor list object, the output from |
a list containing
loglik
: the loglikelihood
betahat
: profile likelihood estimate of regression coefficients
betainfo
: information matrix for betahat
.
The covariance
matrix for $betahat
is the inverse of $betainfo
.
n1 <- 20 n2 <- 20 n <- n1*n2 locs <- as.matrix( expand.grid( (1:n1)/n1, (1:n2)/n2 ) ) X <- cbind(rep(1,n),locs[,2]) covparms <- c(2, 0.2, 0.75, 0) y <- fast_Gp_sim(covparms, "matern_isotropic", locs, 50 ) ord <- order_maxmin(locs) NNarray <- find_ordered_nn(locs,20) NNlist <- group_obs(NNarray) #loglik <- vecchia_grouped_profbeta_loglik( # covparms, "matern_isotropic", y, X, locs, NNlist )
n1 <- 20 n2 <- 20 n <- n1*n2 locs <- as.matrix( expand.grid( (1:n1)/n1, (1:n2)/n2 ) ) X <- cbind(rep(1,n),locs[,2]) covparms <- c(2, 0.2, 0.75, 0) y <- fast_Gp_sim(covparms, "matern_isotropic", locs, 50 ) ord <- order_maxmin(locs) NNarray <- find_ordered_nn(locs,20) NNlist <- group_obs(NNarray) #loglik <- vecchia_grouped_profbeta_loglik( # covparms, "matern_isotropic", y, X, locs, NNlist )
This function returns a grouped version (Guinness, 2018) of Vecchia's (1988) approximation to the Gaussian loglikelihood, the gradient, and Fisher information, and the profile likelihood estimate of the regression coefficients. The approximation modifies the ordered conditional specification of the joint density; rather than each term in the product conditioning on all previous observations, each term conditions on a small subset of previous observations.
vecchia_grouped_profbeta_loglik_grad_info( covparms, covfun_name, y, X, locs, NNlist )
vecchia_grouped_profbeta_loglik_grad_info( covparms, covfun_name, y, X, locs, NNlist )
covparms |
A vector of covariance parameters appropriate for the specified covariance function |
covfun_name |
See |
y |
vector of response values |
X |
Design matrix of covariates. Row |
locs |
matrix of locations. Row |
NNlist |
A neighbor list object, the output from |
a list containing
loglik
: the loglikelihood
grad
: gradient with respect to covariance parameters
info
: Fisher information for covariance parameters
betahat
: profile likelihood estimate of regression coefs
betainfo
: information matrix for betahat
.
The covariance
matrix for $betahat
is the inverse of $betainfo
.
n1 <- 20 n2 <- 20 n <- n1*n2 locs <- as.matrix( expand.grid( (1:n1)/n1, (1:n2)/n2 ) ) X <- cbind(rep(1,n),locs[,2]) covparms <- c(2, 0.2, 0.75, 0) y <- fast_Gp_sim(covparms, "matern_isotropic", locs, 50 ) ord <- order_maxmin(locs) NNarray <- find_ordered_nn(locs,20) NNlist <- group_obs(NNarray) #loglik <- vecchia_grouped_profbeta_loglik_grad_info( # covparms, "matern_isotropic", y, X, locs, NNlist )
n1 <- 20 n2 <- 20 n <- n1*n2 locs <- as.matrix( expand.grid( (1:n1)/n1, (1:n2)/n2 ) ) X <- cbind(rep(1,n),locs[,2]) covparms <- c(2, 0.2, 0.75, 0) y <- fast_Gp_sim(covparms, "matern_isotropic", locs, 50 ) ord <- order_maxmin(locs) NNarray <- find_ordered_nn(locs,20) NNlist <- group_obs(NNarray) #loglik <- vecchia_grouped_profbeta_loglik_grad_info( # covparms, "matern_isotropic", y, X, locs, NNlist )
This function returns the entries of the inverse Cholesky
factor of the covariance matrix implied by Vecchia's approximation.
For return matrix Linv
, Linv[i,]
contains
the non-zero entries of row i
of
the inverse Cholesky matrix. The columns of the non-zero entries
are specified in NNarray[i,]
.
vecchia_Linv(covparms, covfun_name, locs, NNarray, start_ind = 1L)
vecchia_Linv(covparms, covfun_name, locs, NNarray, start_ind = 1L)
covparms |
A vector of covariance parameters appropriate for the specified covariance function |
covfun_name |
See |
locs |
matrix of locations. Row |
NNarray |
A matrix of indices, usually the output from |
start_ind |
Compute entries of Linv only for rows |
matrix containing entries of inverse Cholesky
n1 <- 40 n2 <- 40 n <- n1*n2 locs <- as.matrix( expand.grid( (1:n1)/n1, (1:n2)/n2 ) ) covparms <- c(2, 0.2, 0.75, 0) NNarray <- find_ordered_nn(locs,20) Linv <- vecchia_Linv(covparms, "matern_isotropic", locs, NNarray)
n1 <- 40 n2 <- 40 n <- n1*n2 locs <- as.matrix( expand.grid( (1:n1)/n1, (1:n2)/n2 ) ) covparms <- c(2, 0.2, 0.75, 0) NNarray <- find_ordered_nn(locs,20) Linv <- vecchia_Linv(covparms, "matern_isotropic", locs, NNarray)
This function returns Vecchia's (1988) approximation to the Gaussian loglikelihood. The approximation modifies the ordered conditional specification of the joint density; rather than each term in the product conditioning on all previous observations, each term conditions on a small subset of previous observations.
vecchia_meanzero_loglik(covparms, covfun_name, y, locs, NNarray)
vecchia_meanzero_loglik(covparms, covfun_name, y, locs, NNarray)
covparms |
A vector of covariance parameters appropriate for the specified covariance function |
covfun_name |
See |
y |
vector of response values |
locs |
matrix of locations. Row |
NNarray |
A matrix of indices, usually the output from |
a list containing
loglik
: the loglikelihood
n1 <- 20 n2 <- 20 n <- n1*n2 locs <- as.matrix( expand.grid( (1:n1)/n1, (1:n2)/n2 ) ) covparms <- c(2, 0.2, 0.75, 0) y <- fast_Gp_sim(covparms, "matern_isotropic", locs, 50 ) ord <- order_maxmin(locs) NNarray <- find_ordered_nn(locs,20) #loglik <- vecchia_meanzero_loglik( covparms, "matern_isotropic", y, locs, NNarray )
n1 <- 20 n2 <- 20 n <- n1*n2 locs <- as.matrix( expand.grid( (1:n1)/n1, (1:n2)/n2 ) ) covparms <- c(2, 0.2, 0.75, 0) y <- fast_Gp_sim(covparms, "matern_isotropic", locs, 50 ) ord <- order_maxmin(locs) NNarray <- find_ordered_nn(locs,20) #loglik <- vecchia_meanzero_loglik( covparms, "matern_isotropic", y, locs, NNarray )
This function returns Vecchia's (1988) approximation to the Gaussian loglikelihood, profiling out the regression coefficients. The approximation modifies the ordered conditional specification of the joint density; rather than each term in the product conditioning on all previous observations, each term conditions on a small subset of previous observations.
vecchia_profbeta_loglik(covparms, covfun_name, y, X, locs, NNarray)
vecchia_profbeta_loglik(covparms, covfun_name, y, X, locs, NNarray)
covparms |
A vector of covariance parameters appropriate for the specified covariance function |
covfun_name |
See |
y |
vector of response values |
X |
Design matrix of covariates. Row |
locs |
matrix of locations. Row |
NNarray |
A matrix of indices, usually the output from |
a list containing
loglik
: the loglikelihood
betahat
: profile likelihood estimate of regression coefficients
betainfo
: information matrix for betahat
.
The covariance
matrix for $betahat
is the inverse of $betainfo
.
n1 <- 20 n2 <- 20 n <- n1*n2 locs <- as.matrix( expand.grid( (1:n1)/n1, (1:n2)/n2 ) ) X <- cbind(rep(1,n),locs[,2]) covparms <- c(2, 0.2, 0.75, 0) y <- X %*% c(1,2) + fast_Gp_sim(covparms, "matern_isotropic", locs, 50 ) ord <- order_maxmin(locs) NNarray <- find_ordered_nn(locs,20) #loglik <- vecchia_profbeta_loglik( covparms, "matern_isotropic", y, X, locs, NNarray )
n1 <- 20 n2 <- 20 n <- n1*n2 locs <- as.matrix( expand.grid( (1:n1)/n1, (1:n2)/n2 ) ) X <- cbind(rep(1,n),locs[,2]) covparms <- c(2, 0.2, 0.75, 0) y <- X %*% c(1,2) + fast_Gp_sim(covparms, "matern_isotropic", locs, 50 ) ord <- order_maxmin(locs) NNarray <- find_ordered_nn(locs,20) #loglik <- vecchia_profbeta_loglik( covparms, "matern_isotropic", y, X, locs, NNarray )
This function returns Vecchia's (1988) approximation to the Gaussian loglikelihood, profiling out the regression coefficients, and returning the gradient and Fisher information. Vecchia's approximation modifies the ordered conditional specification of the joint density; rather than each term in the product conditioning on all previous observations, each term conditions on a small subset of previous observations.
vecchia_profbeta_loglik_grad_info(covparms, covfun_name, y, X, locs, NNarray)
vecchia_profbeta_loglik_grad_info(covparms, covfun_name, y, X, locs, NNarray)
covparms |
A vector of covariance parameters appropriate for the specified covariance function |
covfun_name |
See |
y |
vector of response values |
X |
Design matrix of covariates. Row |
locs |
matrix of locations. Row |
NNarray |
A matrix of indices, usually the output from |
A list containing
loglik
: the loglikelihood
grad
: gradient with respect to covariance parameters
info
: Fisher information for covariance parameters
betahat
: profile likelihood estimate of regression coefs
betainfo
: information matrix for betahat
.
The covariance matrix for $betahat
is the inverse of $betainfo
.
n1 <- 20 n2 <- 20 n <- n1*n2 locs <- as.matrix( expand.grid( (1:n1)/n1, (1:n2)/n2 ) ) X <- cbind(rep(1,n),locs[,2]) covparms <- c(2, 0.2, 0.75, 0) y <- X %*% c(1,2) + fast_Gp_sim(covparms, "matern_isotropic", locs, 50 ) ord <- order_maxmin(locs) NNarray <- find_ordered_nn(locs,20) #loglik <- vecchia_profbeta_loglik_grad_info( covparms, "matern_isotropic", # y, X, locs, NNarray )
n1 <- 20 n2 <- 20 n <- n1*n2 locs <- as.matrix( expand.grid( (1:n1)/n1, (1:n2)/n2 ) ) X <- cbind(rep(1,n),locs[,2]) covparms <- c(2, 0.2, 0.75, 0) y <- X %*% c(1,2) + fast_Gp_sim(covparms, "matern_isotropic", locs, 50 ) ord <- order_maxmin(locs) NNarray <- find_ordered_nn(locs,20) #loglik <- vecchia_profbeta_loglik_grad_info( covparms, "matern_isotropic", # y, X, locs, NNarray )