| Type: | Package |
| Title: | Fast Gaussian Process Computation Using Vecchia's Approximation |
| Version: | 0.5.1 |
| Date: | 2024-10-15 |
| Maintainer: | Joseph Guinness <joeguinness@gmail.com> |
| 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>. |
| Depends: | R (≥ 2.10) |
| License: | MIT + file LICENSE |
| Imports: | Rcpp (≥ 0.12.13), FNN |
| Suggests: | fields, knitr, rmarkdown, testthat, maps |
| LinkingTo: | Rcpp, RcppArmadillo, BH |
| RoxygenNote: | 7.3.2 |
| LazyData: | true |
| NeedsCompilation: | yes |
| Packaged: | 2024-10-15 18:54:52 UTC; joe |
| Author: | Joseph Guinness [aut, cre], Matthias Katzfuss [aut], Youssef Fahmy [aut] |
| Repository: | CRAN |
| Date/Publication: | 2024-10-16 04:30:14 UTC |
GpGp: Fast Gaussian Process Computing.
Description
Vecchia's (1988)Gaussian process approximation has emerged among its competitorsas a leader in computational scalability and accuracy. This package includesimplementations of the original approximation, as well as severalupdates to it, including the reordered and grouped versions of the approximation outlined in Guinness (2018) and the Fisher scoring algorithmdescribed in Guinness (2019). The package supports spatialmodels, spatial-temporal models, models on spheres, and some nonstationary models.
Details
The main functions of the package arefit_model, andpredictions.fit_model returns estimates of covariance parametersand linear mean parameters. The user is expected to select a covariance functionand specify it with a string. Currently supported covariance functions are
If there are covariates, they can be expressed via a design matrixX, each row containingthe covariates corresponding to the same row inlocs.
Forpredictions, the user should specify prediction locationslocs_pred and a prediction design matrixX_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 forcomputing the likelihood, gradient, and Fisher information with respectto covariance parameters; reordering functions, nearest neighbor-finding functions, grouping (partitioning) functions, and approximate simulation functions.
Author(s)
Maintainer: Joseph Guinnessjoeguinness@gmail.com
Authors:
Matthias Katzfusskatzfuss@gmail.com
Youssef Fahmyyf297@cornell.edu
Multiply approximate Cholesky by a vector
Description
Vecchia's approximation implies a sparse approximation to theinverse Cholesky factor of the covariance matrix. This functionreturns the result of multiplying the inverse of that matrix by a vector(i.e. an approximation to the Cholesky factor).
Usage
L_mult(Linv, z, NNarray)Arguments
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 |
Value
the product of the Cholesky factor with a vector
Examples
n <- 2000locs <- 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 ) )Multiply transpose of approximate Cholesky by a vector
Description
Vecchia's approximation implies a sparse approximation to theinverse Cholesky factor of the covariance matrix. This functionreturns the result of multiplying the transpose of theinverse of that matrix by a vector(i.e. an approximation to the transpose of the Cholesky factor).
Usage
L_t_mult(Linv, z, NNarray)Arguments
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 |
Value
the product of the transpose of the Cholesky factor with a vector
Examples
n <- 2000locs <- 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)Multiply approximate inverse Cholesky by a vector
Description
Vecchia's approximation implies a sparse approximation to theinverse Cholesky factor of the covariance matrix. This functionreturns the result of multiplying that matrix by a vector.
Usage
Linv_mult(Linv, z, NNarray)Arguments
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 |
Value
the product of the sparse inverse Cholesky factor with a vector
Examples
n <- 2000locs <- 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 ) )Multiply transpose of approximate inverse Cholesky by a vector
Description
Vecchia's approximation implies a sparse approximation to theinverse Cholesky factor of the covariance matrix. This functionreturns the result of multiplying the transpose of that matrix by a vector.
Usage
Linv_t_mult(Linv, z, NNarray)Arguments
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 |
Value
the product of the transpose of the sparse inverse Cholesky factor with a vector
Examples
n <- 2000locs <- 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)Ocean temperatures from Argo profiling floats
Description
A dataset containing ocean temperature measurements fromthree pressure levels (depths), measured by profilingfloats from the Argo program. Data collected in Jan, Feb,and March of 2016.
Usage
argo2016Format
A data frame with 32436 rows and 6 columns
- lon
longitude in degrees between 0 and 360
- lat
latitude in degrees between -90 and 90
- day
time in days
- temp100
Temperature at 100 dbars (roughly 100 meters)
- temp150
Temperature at 150 dbars (roughly 150 meters)
- temp200
Temperature at 200 dbars (roughly 200 meters)
Source
Mikael Kuusela. Argo program:https://argo.ucsd.edu/
Conditional Simulation using Vecchia's approximation
Description
With the prediction locations ordered after the observation locations,an approximation for the inverse Cholesky of the covariance matrixis computed, and standard formulas are applied to obtaina conditional simulation.
Usage
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)Arguments
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 shouldgenerally be kept at TRUE, unless testing out the effect ofreordering. |
st_scale | amount by which to scale the spatial and temporaldimensions for the purpose of selecting neighbors. We recommend settingthis manually when using a spatial-temporal covariance function. When |
nsims | Number of conditional simulations to return. |
Details
We can specify either a GpGp_fit object (the result offit_model), OR manually enter the covariance function andparameters, the observations, observation locations, and design matrix. We must specify the prediction locations and the prediction design matrix.
compute condition number of matrix
Description
compute condition number of matrix
Usage
condition_number(info)Arguments
info | matrix |
expit function and integral of expit function
Description
expit function and integral of expit function
Usage
expit(x)intexpit(x)Arguments
x | argument to expit or intexpit function |
Geometrically anisotropic exponential covariance function (two dimensions)
Description
From a matrix of locations and covariance parameters of the form(variance, L11, L21, L22, nugget), return the square matrix ofall pairwise covariances.
Usage
exponential_anisotropic2D(covparms, locs)d_exponential_anisotropic2D(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, L11, L21, L22, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_exponential_anisotropic2D(): Derivatives of anisotropic exponential covariance
Parameterization
The covariance parameter vector is (variance, L11, L21, L22, nugget)where L11, L21, L22, are the three non-zero entries of a lower-triangularmatrix L. The covariances are
M(x,y) = \sigma^2 exp(-|| L x - L y || )
This means that L11 is interpreted as an inverse range parameter in thefirst dimension.The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Geometrically anisotropic exponential covariance function (three dimensions)
Description
From a matrix of locations and covariance parameters of the form(variance, L11, L21, L22, L31, L32, L33, nugget), return the square matrix ofall pairwise covariances.
Usage
exponential_anisotropic3D(covparms, locs)d_exponential_anisotropic3D(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, L11, L21, L22, L31, L32, L33, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_exponential_anisotropic3D(): Derivatives of anisotropic exponential covariance
Parameterization
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-triangularmatrix L. The covariances are
M(x,y) = \sigma^2 exp(-|| L x - L y || )
This means that L11 is interpreted as an inverse range parameter in thefirst dimension.The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Geometrically anisotropic exponential covariance function (three dimensions, alternate parameterization)
Description
From a matrix of locations and covariance parameters of the form(variance, B11, B12, B13, B22, B23, B33, smoothness, nugget), return the square matrix ofall pairwise covariances.
Usage
exponential_anisotropic3D_alt(covparms, locs)d_exponential_anisotropic3D_alt(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, B11, B12, B13, B22, B23, B33, smoothness, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_exponential_anisotropic3D_alt(): Derivatives of anisotropic Matern covariance
Parameterization
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
u_1 = B11[ x_1 + B12 x_2 + (B13 + B12 B23) x_3]
u_2 = B22[ x_2 + B23 x_3]
u_3 = B33[ x_3 ]
(B13,B23) can be interpreted as a drift vector in space over timeif first two dimensions are space and third is time.Assuming x is transformed to u and y transformed to v, the covariances are
M(x,y) = \sigma^2 exp( - || u - v || )
The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Isotropic exponential covariance function
Description
From a matrix of locations and covariance parameters of the form(variance, range, nugget), return the square matrix ofall pairwise covariances.
Usage
exponential_isotropic(covparms, locs)d_exponential_isotropic(covparms, locs)d_matern15_isotropic(covparms, locs)d_matern25_isotropic(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, range, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_exponential_isotropic(): Derivatives of isotropic exponential covarianced_matern15_isotropic(): Derivatives of isotropic matern covariance with smoothness 1.5d_matern25_isotropic(): Derivatives of isotropicmatern covariance function with smoothness 2.5
Parameterization
The covariance parameter vector is (variance, range, nugget)=(\sigma^2,\alpha,\tau^2), and the covariance function is parameterizedas
M(x,y) = \sigma^2 exp( - || x - y ||/ \alpha )
The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Isotropic exponential covariance function, nonstationary variances
Description
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.
Usage
exponential_nonstat_var(covparms, Z)d_exponential_nonstat_var(covparms, Z)Arguments
covparms | A vector with covariance parametersin the form (variance, range, nugget, <nonstat variance parameters>).The number of nonstationary variance parameters should equal |
Z | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_exponential_nonstat_var(): Derivatives with respect to parameters
Parameterization
This covariance function multiplies the isotropic exponential covarianceby a nonstationary variance function. The form of the covariance is
C(x,y) = exp( \phi(x) + \phi(y) ) M(x,y)
where M(x,y) is the isotropic exponential covariance, and
\phi(x) = c_1 \phi_1(x) + ... + c_p \phi_p(x)
where\phi_1,...,\phi_p are the spatial basis functionscontained in the lastp columns ofZ, andc_1,...,c_p are the nonstationary variance parameters.
Exponential covariance function, different range parameter for each dimension
Description
From a matrix of locations and covariance parameters of the form(variance, range_1, ..., range_d, nugget), return the square matrix ofall pairwise covariances.
Usage
exponential_scaledim(covparms, locs)d_exponential_scaledim(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, range_1, ..., range_d, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_exponential_scaledim(): Derivatives with respect to parameters
Parameterization
The covariance parameter vector is (variance, range_1, ..., range_d, nugget).The covariance function is parameterized as
M(x,y) = \sigma^2 exp( - || D^{-1}(x - y) || )
where D is a diagonal matrix with (range_1, ..., range_d) on the diagonals.The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Spatial-Temporal exponential covariance function
Description
From a matrix of locations and covariance parameters of the form(variance, range_1, range_2, nugget), return the square matrix ofall pairwise covariances.
Usage
exponential_spacetime(covparms, locs)d_exponential_spacetime(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, range_1, range_2, nugget). range_1 is thespatial range, and range_2 is the temporal range. |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_exponential_spacetime(): Derivatives with respect to parameters
Parameterization
The covariance parameter vector is (variance, range_1, range_2, nugget).The covariance function is parameterized as
M(x,y) = \sigma^2 exp( - || D^{-1}(x - y) || )
where D is a diagonal matrix with (range_1, ..., range_1, range_2) on the diagonals.The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Isotropic exponential covariance function on sphere
Description
From a matrix of longitudes and latitudes and a vector covariance parameters of the form(variance, range, nugget), return the square matrix ofall pairwise covariances.
Usage
exponential_sphere(covparms, lonlat)d_exponential_sphere(covparms, lonlat)Arguments
covparms | A vector with covariance parametersin the form (variance, range, nugget). Range parameter assumes thatthe sphere has radius 1 (units are radians). |
lonlat | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlonlat[i,] andlonlat[j,].
Functions
d_exponential_sphere(): Derivatives with respect to parameters
Covariances on spheres
The function first calculates the (x,y,z) 3D coordinates, and then inputsthe resulting locations intoexponential_isotropic. This means that we constructcovariances on the sphere by embedding the sphere in a 3D space. There has been someconcern 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 andFuentes (2016) argue that 3D embeddings produce reasonable models for data on spheres.
Deformed exponential covariance function on sphere
Description
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 ofall pairwise covariances.
Usage
exponential_sphere_warp(covparms, lonlat)d_exponential_sphere_warp(covparms, lonlat)Arguments
covparms | A vector with covariance parametersin the form (variance, range, nugget, <5 warping parameters>). Range parameter assumes that the sphere has radius 1 (units are radians). |
lonlat | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlonlat[i,] andlonlat[j,].
Functions
d_exponential_sphere_warp(): Derivatives with respect to parameters
Warpings
The function first calculates the (x,y,z) 3D coordinates, and then "warps"the locations to(x,y,z) + \Phi(x,y,z), where\Phi is a warpingfunction 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 intoexponential_isotropic.
Exponential covariance function on sphere x time
Description
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 ofall pairwise covariances.
Usage
exponential_spheretime(covparms, lonlattime)d_exponential_spheretime(covparms, lonlattime)Arguments
covparms | A vector with covariance parametersin 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 |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlonlattime[i,] andlonlattime[j,].
Functions
d_exponential_spheretime(): Derivatives with respect to parameters.
Covariances on spheres
The function first calculates the (x,y,z) 3D coordinates, and then inputsthe resulting locations intoexponential_spacetime. This means that we constructcovariances on the sphere by embedding the sphere in a 3D space. There has been someconcern 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 andFuentes (2016) argue that 3D embeddings produce reasonable models for data on spheres.
Deformed exponential covariance function on sphere
Description
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 ofall pairwise covariances.
Usage
exponential_spheretime_warp(covparms, lonlattime)d_exponential_spheretime_warp(covparms, lonlattime)Arguments
covparms | A vector with covariance parametersin 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 |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlonlat[i,] andlonlat[j,].
Functions
d_exponential_spheretime_warp(): Derivatives with respect to parameters
Warpings
The function first calculates the (x,y,z) 3D coordinates, and then "warps"the locations to(x,y,z) + \Phi(x,y,z), where\Phi is a warpingfunction 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 intoexponential_spacetime. The functiondoes not do temporal warping.
Approximate GP simulation
Description
Calculates an approximation to the inverse Choleskyfactor of the covariance matrix using Vecchia's approximation,then the simulation is produced by solving a linear systemwith a vector of uncorrelated standard normals
Usage
fast_Gp_sim(covparms, covfun_name = "matern_isotropic", locs, m = 30)Arguments
covparms | A vector of covariance parameters appropriatefor the specified covariance function |
covfun_name | See |
locs | matrix of locations. Row |
m | Number of nearest neighbors to use in approximation |
Value
vector of simulated values
Examples
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) )Approximate GP simulation with specified Linverse
Description
In situations where we want to do many gaussian processsimulations from the same model, we can compute Linverseonce and reuse it, rather than recomputing for each identical simulation.This function also allows the user to input the vector of standard normalsz.
Usage
fast_Gp_sim_Linv(Linv, NNarray, z = NULL)Arguments
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. |
Value
vector of simulated values
Examples
locs <- as.matrix( expand.grid( (1:50)/50, (1:50)/50 ) )ord <- order_maxmin(locs)locsord <- locs[ord,]m <- 10NNarray <- 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] <- yfields::image.plot( matrix(y,50,50) )Find ordered nearest neighbors.
Description
Given a matrix of locations, find them nearest neighborsto each location, subject to the neighbors comingpreviously in the ordering. The algorithm uses the kdtreealgorithm in the FNN package, adapted to the settingwhere the nearest neighbors must come from previousin the ordering.
Usage
find_ordered_nn(locs, m, lonlat = FALSE, st_scale = NULL)Arguments
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 coordinatesfor distance calculations. The function assumes that the last column ofthe locations is the temporal dimension, and the rest of the columnsare spatial dimensions. The spatial dimensions are divided by |
Value
An matrix containing the indices of the neighbors. Rowi of thereturned matrix contains the indices of the nearestmlocations to thei'th location. Indices are ordered within arow to be increasing in distance. By convention, we consider a locationto neighbor itself, so the first entry of rowi isi, thesecond entry is the index of the nearest location, and so on. Because eachlocation neighbors itself, the returned matrix hasm+1 columns.
Examples
locs <- as.matrix( expand.grid( (1:40)/40, (1:40)/40 ) ) ord <- order_maxmin(locs) # calculate an orderinglocsord <- locs[ord,] # reorder locationsm <- 20NNarray <- find_ordered_nn(locsord,20) # find ordered nearest 20 neighborsind <- 100# plot all locations in gray, first ind locations in black,# ind location with magenta circle, m neighhbors with blue circleplot( 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
Description
Naive brute force nearest neighbor finder
Usage
find_ordered_nn_brute(locs, m)Arguments
locs | matrix of locations |
m | number of neighbors |
Value
An matrix containing the indices of the neighbors. Rowi of thereturned matrix contains the indices of the nearestmlocations to thei'th location. Indices are ordered within arow to be increasing in distance. By convention, we consider a locationto neighbor itself, so the first entry of rowi isi, thesecond entry is the index of the nearest location, and so on. Because eachlocation neighbors itself, the returned matrix hasm+1 columns.
Fisher scoring algorithm
Description
Fisher scoring algorithm
Usage
fisher_scoring( likfun, start_parms, link, silent = FALSE, convtol = 1e-04, max_iter = 40)Arguments
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 |
Estimate mean and covariance parameters
Description
Given a response, set of locations, (optionally) a design matrix,and a specified covariance function, return the maximumVecchia likelihood estimates, obtained with a Fisher scoring algorithm.
Usage
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)Arguments
y | response vector |
locs | matrix of locations. Each row is a single spatial or spatial-temporallocation. If using one of the covariance functions for data on a sphere,the first column should be longitudes (-180,180) and the second columnshould 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 correspondingobservation 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 wantto use a customized reordering, then manually reorder |
group | TRUE/FALSE for whether to use the grouped version ofthe approximation (Guinness, 2018) or not. The grouped versionis used by default and is always recommended. |
m_seq | Sequence of values for number of neighbors. By default, a 10-neighborapproximation is maximized, then a 30-neighbor approximation is maximized using the10 neighbor estimates as starting values. However, one can specify any sequenceof numbers of neighbors, e.g. |
max_iter | maximum number of Fisher scoring iterations |
fixed_parms | Indices of covariance parameters you would like to fixat specific values. If you decide to fix any parameters, you must specifytheir values in |
silent | TRUE/FALSE for whether to print some information during fitting. |
st_scale | Scaling for spatial and temporal ranges. Only applicable forspatial-temporal models, where it is used in distancecalculations when selecting neighbors. |
convtol | Tolerance for exiting the optimization. Fisher scoring is stoppedwhen the dot product between the step and the gradient is less than |
Details
fit_model is a user-friendly model fitting functionthat automatically performs many of the auxiliary tasks needed forusing Vecchia's approximation, including reordering, computingnearest neighbors, grouping, and optimization. The likelihoods use a smallpenalty on small nuggets, large spatial variances, and small smoothness parameter.
The Jason-3 windspeed vignette and the Argo temperature vignette are useful sources for ause-cases of thefit_model function for data on sphere. The example below shows a very small example with a simulated dataset in 2d.
Value
An object of classGpGp_fit, which is a list containingcovariance parameter estimates, regression coefficients,covariance matrix for mean parameter estimates, as well as some otherinformation relevant to the model fit.
Examples
n1 <- 20n2 <- 20n <- n1*n2locs <- 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")# fitget link function, whether locations are lonlat and space time
Description
get link function, whether locations are lonlat and space time
Usage
get_linkfun(covfun_name)Arguments
covfun_name | string name of covariance function |
get penalty function
Description
get penalty function
Usage
get_penalty(y, X, locs, covfun_name)Arguments
y | response |
X | design matrix |
locs | locations |
covfun_name | string name of covariance function |
get default starting values of covariance parameters
Description
get default starting values of covariance parameters
Usage
get_start_parms(y, X, locs, covfun_name)Arguments
y | response |
X | design matrix |
locs | locations |
covfun_name | string name of covariance function |
Automatic grouping (partitioning) of locations
Description
Take in an array of nearest neighbors, and automatically partitionthe 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 orseveral rows of NNarray. The algorithm attempts to find groupings such thatobservations within a group share many common neighbors.
Usage
group_obs(NNarray, exponent = 2)Arguments
NNarray | Matrix of nearest neighbor indices, usually the result of |
exponent | Within the algorithm, two groups are merged if the number of uniqueneighbors raised to the |
Value
A list with elements defining the grouping. The list entries are:
all_inds: vector of all indices of all blocks.last_ind_of_block: Theith entry tells us thelocation inall_indsof the last index of theith block. Thus the lengthoflast_ind_of_blockis the number of blocks, andlast_ind_of_blockcanbe used to chopall_indsup into blocks.global_resp_inds: Theith entry tells us theindex of theith response, as ordered inall_inds.local_resp_inds: Theith entry tells us the location within the block of the response index.last_resp_of_block: Theith entry tells us thelocation withinlocal_resp_indsandglobal_resp_indsof the lastindex of theith block.last_resp_of_blockis toglobal_resp_indsandlocal_resp_indsaslast_ind_of_blockis toall_inds.
Examples
locs <- matrix( runif(200), 100, 2 ) # generate random locationsord <- order_maxmin(locs) # calculate an orderinglocsord <- locs[ord,] # reorder locationsm <- 10NNarray <- find_ordered_nn(locsord,m) # m nearest neighbor indicesNNlist2 <- group_obs(NNarray) # join blocks if joining reduces squaresNNlist3 <- group_obs(NNarray,3) # join blocks if joining reduces cubesobject.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_indslast_ind_of_block <- NNlist2$last_ind_of_blockinds_of_block_2 <- all_inds[ (last_ind_of_block[1] + 1):last_ind_of_block[2] ]local_resp_inds <- NNlist2$local_resp_indsglobal_resp_inds <- NNlist2$global_resp_indslast_resp_of_block <- NNlist2$last_resp_of_blocklocal_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 sameWindspeed measurements from Jason-3 Satellite
Description
A dataset containing lightly preprocessed windspeed valuesfrom the Jason-3 satellite. Observations near clouds and icehave been removed, and the data have been aggregated (averaged) over 10 second intervals. Jason-3 reportswindspeeds over the ocean only. The data are from a sixday period between August 4 and 9 of 2016.
Usage
jason3Format
A data frame with 18973 rows and 4 columns
- windspeed
wind speed, in maters per second
- lon
longitude in degrees between 0 and 360
- lat
latitude in degrees between -90 and 90
- time
time in seconds from midnight August 4
Source
https://www.ncei.noaa.gov/products/jason-satellite-products
Isotropic Matern covariance function, smoothness = 1.5
Description
From a matrix of locations and covariance parameters of the form(variance, range, nugget), return the square matrix ofall pairwise covariances.
Usage
matern15_isotropic(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, range, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Parameterization
The covariance parameter vector is (variance, range, nugget)=(\sigma^2,\alpha,\tau^2), and the covariance function is parameterizedas
M(x,y) = \sigma^2 (1 + || x - y || ) exp( - || x - y ||/ \alpha )
The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Matern covariance function, smoothess = 1.5, different range parameter for each dimension
Description
From a matrix of locations and covariance parameters of the form(variance, range_1, ..., range_d, nugget), return the square matrix ofall pairwise covariances.
Usage
matern15_scaledim(covparms, locs)d_matern15_scaledim(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, range_1, ..., range_d, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_matern15_scaledim(): Derivatives with respect to parameters
Parameterization
The covariance parameter vector is (variance, range_1, ..., range_d, nugget).The covariance function is parameterized as
M(x,y) = \sigma^2 (1 + || D^{-1}(x - y) || ) exp( - || D^{-1}(x - y) || )
where D is a diagonal matrix with (range_1, ..., range_d) on the diagonals.The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Isotropic Matern covariance function, smoothness = 2.5
Description
From a matrix of locations and covariance parameters of the form(variance, range, nugget), return the square matrix ofall pairwise covariances.
Usage
matern25_isotropic(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, range, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Parameterization
The covariance parameter vector is (variance, range, nugget)=(\sigma^2,\alpha,\tau^2), and the covariance function is parameterizedas
M(x,y) = \sigma^2 (1 + || x - y ||/ \alpha + || x - y ||^2/3\alpha^2 ) exp( - || x - y ||/ \alpha )
The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Matern covariance function, smoothess = 2.5, different range parameter for each dimension
Description
From a matrix of locations and covariance parameters of the form(variance, range_1, ..., range_d, nugget), return the square matrix ofall pairwise covariances.
Usage
matern25_scaledim(covparms, locs)d_matern25_scaledim(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, range_1, ..., range_d, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_matern25_scaledim(): Derivatives with respect to parameters
Parameterization
The covariance parameter vector is (variance, range_1, ..., range_d, nugget).The covariance function is parameterized as
M(x,y) = \sigma^2 (1 + || D^{-1}(x - y) || + || D^{-1}(x - y) ||^2/3.0) exp( - || D^{-1}(x - y) || )
where D is a diagonal matrix with (range_1, ..., range_d) on the diagonals.The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Isotropic Matern covariance function, smoothness = 3.5
Description
From a matrix of locations and covariance parameters of the form(variance, range, nugget), return the square matrix ofall pairwise covariances.
Usage
matern35_isotropic(covparms, locs)d_matern35_isotropic(covparms, locs)d_matern45_isotropic(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, range, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_matern35_isotropic(): Derivatives of isotropicmatern covariance function with smoothness 3.5d_matern45_isotropic(): Derivatives of isotropicmatern covariance function with smoothness 3.5
Parameterization
The covariance parameter vector is (variance, range, nugget)=(\sigma^2,\alpha,\tau^2), and the covariance function is parameterizedas
M(x,y) = \sigma^2 ( \sum_{j=0}^3 c_j || x - y ||^j/ \alpha^j ) exp( - || x - y ||/ \alpha )
where c_0 = 1, c_1 = 1, c_2 = 2/5, c_3 = 1/15. The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Matern covariance function, smoothess = 3.5, different range parameter for each dimension
Description
From a matrix of locations and covariance parameters of the form(variance, range_1, ..., range_d, nugget), return the square matrix ofall pairwise covariances.
Usage
matern35_scaledim(covparms, locs)d_matern35_scaledim(covparms, locs)d_matern45_scaledim(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, range_1, ..., range_d, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_matern35_scaledim(): Derivatives with respect to parametersd_matern45_scaledim(): Derivatives with respect to parameters
Parameterization
The covariance parameter vector is (variance, range_1, ..., range_d, nugget).The covariance function is parameterized as
M(x,y) = \sigma^2 ( \sum_{j=0}^3 c_j || D^{-1}(x - y) ||^j ) exp( - || D^{-1}(x - y) || )
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 \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Isotropic Matern covariance function, smoothness = 4.5
Description
From a matrix of locations and covariance parameters of the form(variance, range, nugget), return the square matrix ofall pairwise covariances.
Usage
matern45_isotropic(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, range, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Parameterization
The covariance parameter vector is (variance, range, nugget)=(\sigma^2,\alpha,\tau^2), and the covariance function is parameterizedas
M(x,y) = \sigma^2 ( \sum_{j=0}^4 c_j || x - y ||^j/ \alpha^j ) exp( - || x - y ||/ \alpha )
where c_0 = 1, c_1 = 1, c_2 = 3/7, c_3 = 2/21, c_4 = 1/105. The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Matern covariance function, smoothess = 3.5, different range parameter for each dimension
Description
From a matrix of locations and covariance parameters of the form(variance, range_1, ..., range_d, nugget), return the square matrix ofall pairwise covariances.
Usage
matern45_scaledim(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, range_1, ..., range_d, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Parameterization
The covariance parameter vector is (variance, range_1, ..., range_d, nugget).The covariance function is parameterized as
M(x,y) = \sigma^2 ( \sum_{j=0}^4 c_j || D^{-1}(x - y) ||^j ) exp( - || D^{-1}(x - y) || )
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 \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Geometrically anisotropic Matern covariance function (two dimensions)
Description
From a matrix of locations and covariance parameters of the form(variance, L11, L21, L22, smoothness, nugget), return the square matrix ofall pairwise covariances.
Usage
matern_anisotropic2D(covparms, locs)d_matern_anisotropic2D(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, L11, L21, L22, smoothness, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_matern_anisotropic2D(): Derivatives of anisotropic Matern covariance
Parameterization
The covariance parameter vector is (variance, L11, L21, L22, smoothness, nugget)where L11, L21, L22, are the three non-zero entries of a lower-triangularmatrix L. The covariances are
M(x,y) = \sigma^2 2^{1-\nu}/\Gamma(\nu) (|| L x - L y || )^\nu K_\nu(|| L x - L y ||)
This means that L11 is interpreted as an inverse range parameter in thefirst dimension.The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Geometrically anisotropic Matern covariance function (three dimensions)
Description
From a matrix of locations and covariance parameters of the form(variance, L11, L21, L22, L31, L32, L33, smoothness, nugget), return the square matrix ofall pairwise covariances.
Usage
matern_anisotropic3D(covparms, locs)d_matern_anisotropic3D(covparms, locs)d_matern_anisotropic3D_alt(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, L11, L21, L22, L31, L32, L33, smoothness, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_matern_anisotropic3D(): Derivatives of anisotropic Matern covarianced_matern_anisotropic3D_alt(): Derivatives of anisotropic Matern covariance
Parameterization
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-triangularmatrix L. The covariances are
M(x,y) = \sigma^2 2^{1-\nu}/\Gamma(\nu) (|| L x - L y || )^\nu K_\nu(|| L x - L y ||)
This means that L11 is interpreted as an inverse range parameter in thefirst dimension.The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Geometrically anisotropic Matern covariance function (three dimensions, alternate parameterization)
Description
From a matrix of locations and covariance parameters of the form(variance, B11, B12, B13, B22, B23, B33, smoothness, nugget), return the square matrix ofall pairwise covariances.
Usage
matern_anisotropic3D_alt(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, B11, B12, B13, B22, B23, B33, smoothness, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Parameterization
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
u_1 = B11[ x_1 + B12 x_2 + (B13 + B12 B23) x_3]
u_2 = B22[ x_2 + B23 x_3]
u_3 = B33[ x_3 ]
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
M(x,y) = \sigma^2 2^{1-\nu}/\Gamma(\nu) (|| u - v || )^\nu K_\nu(|| u - v ||)
The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Isotropic Matern covariance function with random effects for categories
Description
From a matrix of locations and covariance parameters of the form(variance, range, smoothness, category variance, nugget), return the square matrix ofall pairwise covariances.
Usage
matern_categorical(covparms, locs)d_matern_categorical(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, range, smoothness, category variance, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_matern_categorical(): Derivatives of isotropic Matern covariance
Parameterization
The covariance parameter vector is (variance, range, smoothness, category variance, nugget)=(\sigma^2,\alpha,\nu,c^2,\tau^2), and the covariance function is parameterizedas
M(x,y) = \sigma^2 2^{1-\nu}/\Gamma(\nu) (|| x - y ||/\alpha )^\nu K_\nu(|| x - y ||/\alpha )
The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.The category variancec^2 is added if two observation from same categoryNOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Isotropic Matern covariance function
Description
From a matrix of locations and covariance parameters of the form(variance, range, smoothness, nugget), return the square matrix ofall pairwise covariances.
Usage
matern_isotropic(covparms, locs)d_matern_isotropic(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, range, smoothness, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_matern_isotropic(): Derivatives of isotropic Matern covariance
Parameterization
The covariance parameter vector is (variance, range, smoothness, nugget)=(\sigma^2,\alpha,\nu,\tau^2), and the covariance function is parameterizedas
M(x,y) = \sigma^2 2^{1-\nu}/\Gamma(\nu) (|| x - y ||/\alpha )^\nu K_\nu(|| x - y ||/\alpha )
The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Isotropic Matern covariance function, nonstationary variances
Description
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.
Usage
matern_nonstat_var(covparms, Z)d_matern_nonstat_var(covparms, Z)Arguments
covparms | A vector with covariance parametersin the form (variance, range, smoothness, nugget, <nonstat variance parameters>).The number of nonstationary variance parameters should equal |
Z | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_matern_nonstat_var(): Derivatives with respect to parameters
Parameterization
This covariance function multiplies the isotropic Matern covarianceby a nonstationary variance function. The form of the covariance is
C(x,y) = exp( \phi(x) + \phi(y) ) M(x,y)
where M(x,y) is the isotropic Matern covariance, and
\phi(x) = c_1 \phi_1(x) + ... + c_p \phi_p(x)
where\phi_1,...,\phi_p are the spatial basis functionscontained in the lastp columns ofZ, andc_1,...,c_p are the nonstationary variance parameters.
Matern covariance function, different range parameter for each dimension
Description
From a matrix of locations and covariance parameters of the form(variance, range_1, ..., range_d, smoothness, nugget), return the square matrix ofall pairwise covariances.
Usage
matern_scaledim(covparms, locs)d_matern_scaledim(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, range_1, ..., range_d, smoothness, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_matern_scaledim(): Derivatives with respect to parameters
Parameterization
The covariance parameter vector is (variance, range_1, ..., range_d, smoothness, nugget).The covariance function is parameterized as
M(x,y) = \sigma^2 2^{1-\nu}/\Gamma(\nu) (|| D^{-1}(x - y) || )^\nu K_\nu(|| D^{-1}(x - y) || )
where D is a diagonal matrix with (range_1, ..., range_d) on the diagonals.The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Spatial-Temporal Matern covariance function
Description
From a matrix of locations and covariance parameters of the form(variance, range_1, range_2, smoothness, nugget), return the square matrix ofall pairwise covariances.
Usage
matern_spacetime(covparms, locs)d_matern_spacetime(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, range_1, range_2, smoothness, nugget). range_1 is thespatial range, and range_2 is the temporal range. |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_matern_spacetime(): Derivatives with respect to parameters
Parameterization
The covariance parameter vector is (variance, range_1, range_2, smoothness, nugget).The covariance function is parameterized as
M(x,y) = \sigma^2 2^{1-\nu}/\Gamma(\nu) (|| D^{-1}(x - y) || )^\nu K_\nu(|| D^{-1}(x - y) || )
where D is a diagonal matrix with (range_1, ..., range_1, range_2) on the diagonals.The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.NOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Space-Time Matern covariance function with random effects for categories
Description
From a matrix of locations and covariance parameters of the form(variance, spatial range, temporal range, smoothness, category, nugget), return the square matrix ofall pairwise covariances.
Usage
matern_spacetime_categorical(covparms, locs)d_matern_spacetime_categorical(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, spatial range, temporal range, smoothness, category, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_matern_spacetime_categorical(): Derivatives of isotropic Matern covariance
Parameterization
The covariance parameter vector is (variance, range, smoothness, category, nugget)=(\sigma^2,\alpha_1,\alpha_2,\nu,c^2,\tau^2), and the covariance function is parameterizedas
d = ( || x - y ||^2/\alpha_1 + |s-t|^2/\alpha_2^2 )^{1/2}
M(x,y) = \sigma^2 2^{1-\nu}/\Gamma(\nu) (d)^\nu K_\nu(d)
(x,s) and (y,t) are the space-time locations of a pair of observations.The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.The category variancec^2 is added if two observation from same categoryNOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Space-Time Matern covariance function with local random effects for categories
Description
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 ofall pairwise covariances.This is the covariance for the following model for data from cateogory k
Y_k(x_i,t_i) = Z_0(x_i,t_i) + Z_k(x_i,t_i) + e_i
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)
Usage
matern_spacetime_categorical_local(covparms, locs)d_matern_spacetime_categorical_local(covparms, locs)Arguments
covparms | A vector with covariance parametersin the form (variance, spatial range, temporal range, smoothness, category, nugget) |
locs | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlocs[i,] andlocs[j,].
Functions
d_matern_spacetime_categorical_local(): Derivatives of isotropic Matern covariance
Parameterization
The covariance parameter vector is (variance, range, smoothness, category, nugget)=(\sigma^2,\alpha_1,\alpha_2,\nu,c^2,\tau^2), and the covariance function is parameterizedas
d = ( || x - y ||^2/\alpha_1 + |s-t|^2/\alpha_2^2 )^{1/2}
M(x,y) = \sigma^2 2^{1-\nu}/\Gamma(\nu) (d)^\nu K_\nu(d)
(x,s) and (y,t) are the space-time locations of a pair of observations.The nugget value \sigma^2 \tau^2 is added to the diagonal of the covariance matrix.The category variancec^2 is added if two observation from same categoryNOTE: the nugget is \sigma^2 \tau^2, not \tau^2.
Isotropic Matern covariance function on sphere
Description
From a matrix of longitudes and latitudes and a vector covariance parameters of the form(variance, range, smoothness, nugget), return the square matrix ofall pairwise covariances.
Usage
matern_sphere(covparms, lonlat)d_matern_sphere(covparms, lonlat)Arguments
covparms | A vector with covariance parametersin the form (variance, range, smoothness, nugget). Range parameter assumes thatthe sphere has radius 1 (units are radians). |
lonlat | A matrix with |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlonlat[i,] andlonlat[j,].
Functions
d_matern_sphere(): Derivatives with respect to parameters
Matern on Sphere Domain
The function first calculates the (x,y,z) 3D coordinates, and then inputsthe resulting locations intomatern_isotropic. This means that we constructcovariances on the sphere by embedding the sphere in a 3D space. There has been someconcern 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 andFuentes (2016) argue that 3D embeddings produce reasonable models for data on spheres.
Deformed Matern covariance function on sphere
Description
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 ofall pairwise covariances.
Usage
matern_sphere_warp(covparms, lonlat)d_matern_sphere_warp(covparms, lonlat)Arguments
covparms | A vector with covariance parametersin 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 |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlonlat[i,] andlonlat[j,].
Functions
d_matern_sphere_warp(): Derivatives with respect to parameters.
Warpings
The function first calculates the (x,y,z) 3D coordinates, and then "warps"the locations to(x,y,z) + \Phi(x,y,z), where\Phi is a warpingfunction 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 intomatern_isotropic.
Matern covariance function on sphere x time
Description
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 ofall pairwise covariances.
Usage
matern_spheretime(covparms, lonlattime)d_matern_spheretime(covparms, lonlattime)Arguments
covparms | A vector with covariance parametersin 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 |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlonlattime[i,] andlonlattime[j,].
Functions
d_matern_spheretime(): Derivatives with respect to parameters
Covariances on spheres
The function first calculates the (x,y,z) 3D coordinates, and then inputsthe resulting locations intomatern_spacetime. This means that we constructcovariances on the sphere by embedding the sphere in a 3D space. There has been someconcern 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 andFuentes (2016) argue that 3D embeddings produce reasonable models for data on spheres.
Deformed Matern covariance function on sphere
Description
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 ofall pairwise covariances.
Usage
matern_spheretime_warp(covparms, lonlattime)d_matern_spheretime_warp(covparms, lonlattime)Arguments
covparms | A vector with covariance parametersin 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 |
Value
A matrix withn rows andn columns, with the i,j entrycontaining the covariance between observations atlonlat[i,] andlonlat[j,].
Functions
d_matern_spheretime_warp(): Derivatives with respect to parameters
Warpings
The function first calculates the (x,y,z) 3D coordinates, and then "warps"the locations to(x,y,z) + \Phi(x,y,z), where\Phi is a warpingfunction 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 intomatern_spacetime. The functiondoes not do temporal warping.
Sorted coordinate ordering
Description
Return the ordering of locations sorted along one of thecoordinates or the sum of multiple coordinates
Usage
order_coordinate(locs, coordinate)Arguments
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 |
Value
A vector of indices giving the ordering, i.e. the first element of this vector is the index of the first location.
Examples
n <- 100 # Number of locationsd <- 2 # dimension of domainlocs <- matrix( runif(n*d), n, d )ord1 <- order_coordinate(locs, 1 )ord12 <- order_coordinate(locs, c(1,2) )Distance to specified point ordering
Description
Return the ordering of locations increasing in theirdistance to some specified location
Usage
order_dist_to_point(locs, loc0, lonlat = FALSE)Arguments
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. |
Value
A vector of indices giving the ordering, i.e. the first element of this vector is the index of the location nearest toloc0.
Examples
n <- 100 # Number of locationsd <- 2 # dimension of domainlocs <- matrix( runif(n*d), n, d )loc0 <- c(1/2,1/2)ord <- order_dist_to_point(locs,loc0)Maximum minimum distance ordering
Description
Return the indices of an approximation to the maximum minimum distance ordering.A point in the center is chosen first, and then each successive pointis chosen to maximize the minimum distance to previously selected points
Usage
order_maxmin(locs, lonlat = FALSE, space_time = FALSE, st_scale = NULL)Arguments
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 spatialand temporal coordinates are scaled. If |
Value
A vector of indices giving the ordering, i.e. the first element of this vector is the index of the first location.
Examples
# planar coordinatesnvec <- 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) )Middle-out ordering
Description
Return the ordering of locations increasing in theirdistance to the average location
Usage
order_middleout(locs, lonlat = FALSE)Arguments
locs | A matrix of locations. Each row of |
lonlat | TRUE/FALSE whether locations are longitudes and latitudes. |
Value
A vector of indices giving the ordering, i.e. the first element of this vector is the index of the location nearest the center.
Examples
n <- 100 # Number of locationsd <- 2 # dimension of domainlocs <- matrix( runif(n*d), n, d )ord <- order_middleout(locs)penalize large values of parameter: penalty, 1st deriative, 2nd derivative
Description
penalize large values of parameter: penalty, 1st deriative, 2nd derivative
Usage
pen_hi(x, tt, aa)dpen_hi(x, tt, aa)ddpen_hi(x, tt, aa)Arguments
x | argument to penalty |
tt | scale parameter of penalty |
aa | location parameter of penalty |
penalize small values of parameter: penalty, 1st deriative, 2nd derivative
Description
penalize small values of parameter: penalty, 1st deriative, 2nd derivative
Usage
pen_lo(x, tt, aa)dpen_lo(x, tt, aa)ddpen_lo(x, tt, aa)Arguments
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
Description
penalize small values of log parameter: penalty, 1st deriative, 2nd derivative
Usage
pen_loglo(x, tt, aa)dpen_loglo(x, tt, aa)ddpen_loglo(x, tt, aa)Arguments
x | argument to penalty |
tt | scale parameter of penalty |
aa | location parameter of penalty |
Compute Gaussian process predictions using Vecchia's approximations
Description
With the prediction locations ordered after the observation locations,an approximation for the inverse Cholesky of the covariance matrixis computed, and standard formulas are applied to obtainthe conditional expectation.
Usage
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)Arguments
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 shouldgenerally be kept at TRUE, unless testing out the effect ofreordering. |
st_scale | amount by which to scale the spatial and temporaldimensions for the purpose of selecting neighbors. We recommend settingthis manually when using a spatial-temporal covariance function. When |
Details
We can specify either a GpGp_fit object (the result offit_model), OR manually enter the covariance function andparameters, the observations, observation locations, and design matrix. We must specify the prediction locations and the prediction design matrix.
compute gradient of spherical harmonics functions
Description
compute gradient of spherical harmonics functions
Usage
sph_grad_xyz(xyz, Lmax)Arguments
xyz | xyz coordinates of locations on sphere |
Lmax | largest degree of spherical harmonics. Current only Lmax=2 supported |
Print summary of GpGp fit
Description
Print summary of GpGp fit
Usage
## S3 method for class 'GpGp_fit'summary(object, ...)Arguments
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
Description
test likelihood object for NA or Inf values
Usage
test_likelihood_object(likobj)Arguments
likobj | likelihood object |
Entries of inverse Cholesky approximation
Description
This function returns the entries of the inverse Choleskyfactor of the covariance matrix implied by Vecchia's approximation.For return matrixLinv,Linv[i,] contains the non-zero entries of rowi ofthe inverse Cholesky matrix. The columns of the non-zero entriesare specified inNNarray[i,].
Usage
vecchia_Linv(covparms, covfun_name, locs, NNarray, start_ind = 1L)Arguments
covparms | A vector of covariance parameters appropriatefor 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 |
Value
matrix containing entries of inverse Cholesky
Examples
n1 <- 40n2 <- 40n <- n1*n2locs <- 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)Grouped Vecchia approximation to the Gaussian loglikelihood, zero mean
Description
This function returns a grouped version (Guinness, 2018) of Vecchia's (1988) approximation to the Gaussianloglikelihood. The approximation modifies the ordered conditionalspecification of the joint density; rather than each term in the productconditioning on all previous observations, each term conditions ona small subset of previous observations.
Usage
vecchia_grouped_meanzero_loglik(covparms, covfun_name, y, locs, NNlist)Arguments
covparms | A vector of covariance parameters appropriatefor 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 |
Value
a list containing
loglik: the loglikelihood
Examples
n1 <- 20n2 <- 20n <- n1*n2locs <- 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 )Grouped Vecchia approximation, profiled regression coefficients
Description
This function returns a grouped version (Guinness, 2018) of Vecchia's (1988) approximation to the Gaussianloglikelihood and the profile likelihood estimate of the regressioncoefficients. The approximation modifies the ordered conditionalspecification of the joint density; rather than each term in the productconditioning on all previous observations, each term conditions ona small subset of previous observations.
Usage
vecchia_grouped_profbeta_loglik(covparms, covfun_name, y, X, locs, NNlist)Arguments
covparms | A vector of covariance parameters appropriatefor 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 |
Value
a list containing
loglik: the loglikelihoodbetahat: profile likelihood estimate of regression coefficientsbetainfo: information matrix forbetahat.
The covariancematrix for$betahat is the inverse of$betainfo.
Examples
n1 <- 20n2 <- 20n <- n1*n2locs <- 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 )Grouped Vecchia loglikelihood, gradient, Fisher information
Description
This function returns a grouped version (Guinness, 2018) of Vecchia's (1988) approximation to the Gaussianloglikelihood, the gradient, and Fisher information, and the profile likelihood estimate of the regressioncoefficients. The approximation modifies the ordered conditionalspecification of the joint density; rather than each term in the productconditioning on all previous observations, each term conditions ona small subset of previous observations.
Usage
vecchia_grouped_profbeta_loglik_grad_info( covparms, covfun_name, y, X, locs, NNlist)Arguments
covparms | A vector of covariance parameters appropriatefor 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 |
Value
a list containing
loglik: the loglikelihoodgrad: gradient with respect to covariance parametersinfo: Fisher information for covariance parametersbetahat: profile likelihood estimate of regression coefsbetainfo: information matrix forbetahat.
The covariancematrix for$betahat is the inverse of$betainfo.
Examples
n1 <- 20n2 <- 20n <- n1*n2locs <- 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 )Vecchia's approximation to the Gaussian loglikelihood, zero mean
Description
This function returns Vecchia's (1988) approximation to the Gaussianloglikelihood. The approximation modifies the ordered conditionalspecification of the joint density; rather than each term in the productconditioning on all previous observations, each term conditions ona small subset of previous observations.
Usage
vecchia_meanzero_loglik(covparms, covfun_name, y, locs, NNarray)Arguments
covparms | A vector of covariance parameters appropriatefor 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 |
Value
a list containing
loglik: the loglikelihood
Examples
n1 <- 20n2 <- 20n <- n1*n2locs <- 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 )Vecchia's approximation to the Gaussian loglikelihood, with profiled regression coefficients.
Description
This function returns Vecchia's (1988) approximation to the Gaussianloglikelihood, profiling out the regression coefficients. The approximation modifies the ordered conditionalspecification of the joint density; rather than each term in the productconditioning on all previous observations, each term conditions ona small subset of previous observations.
Usage
vecchia_profbeta_loglik(covparms, covfun_name, y, X, locs, NNarray)Arguments
covparms | A vector of covariance parameters appropriatefor 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 |
Value
a list containing
loglik: the loglikelihoodbetahat: profile likelihood estimate of regression coefficientsbetainfo: information matrix forbetahat.
The covariancematrix for$betahat is the inverse of$betainfo.
Examples
n1 <- 20n2 <- 20n <- n1*n2locs <- 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 )Vecchia's loglikelihood, gradient, and Fisher information
Description
This function returns Vecchia's (1988) approximation to the Gaussianloglikelihood, profiling out the regression coefficients, and returningthe gradient and Fisher information. Vecchia's approximation modifies the ordered conditionalspecification of the joint density; rather than each term in the productconditioning on all previous observations, each term conditions ona small subset of previous observations.
Usage
vecchia_profbeta_loglik_grad_info(covparms, covfun_name, y, X, locs, NNarray)Arguments
covparms | A vector of covariance parameters appropriatefor 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 |
Value
A list containing
loglik: the loglikelihoodgrad: gradient with respect to covariance parametersinfo: Fisher information for covariance parametersbetahat: profile likelihood estimate of regression coefsbetainfo: information matrix forbetahat.
The covariance matrix for$betahat is the inverse of$betainfo.
Examples
n1 <- 20n2 <- 20n <- n1*n2locs <- 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 )