pkern_corr_mat: Construct 1D stationary correlation matrices for regularly...

View source: R/pkern_var.R

pkern_corr_matR Documentation

Construct 1D stationary correlation matrices for regularly spaced data

Description

The i,jth value of the returned correlation matrix is the marginal correlation between the ith and jth points in a regularly spaced sequence of n (1D) points, given the correlation model with parameters defined in list pars.

Usage

pkern_corr_mat(pars, n, gres = 1, i = seq(n), j = seq(n))

Arguments

pars

list of kernel parameters 'k' and 'kp' (see pkern_corr)

n

positive integer, the number of points on the 1D line

gres

positive numeric, the distance between adjacent grid lines

i

vector, a subset of seq(n) indicating rows to return

j

vector, a subset of seq(n) indicating columns to return

Details

This matrix is symmetric and Toeplitz as a result of the assumption of stationarity of the random field and regularity of the grid.

The distance between adjacent points is specified by gres. Subsets of the correlation matrix can be requested by specifying i and/or j (default behaviour is to include all).

Like pkern_corr, this function is for computing 1D components of a 2D process. The product of two matrices returned by pkern_corr_mat is the correlation matrix for a spatially separable process (see examples).

Value

the n x n correlation matrix, or its subset as specified in i, j

Examples


# define test distances, grid, and example kernel
n_test = 10
g_example = pkern_grid(n_test)
pars = pkern_pars(g_example, c('mat', 'gau'))

# compute the correlation matrices and their kronecker product
cx = pkern_corr_mat(pars[['x']], n=n_test)
cy = pkern_corr_mat(pars[['y']], n=n_test)
cxy = kronecker(cx, cy)

# pkern_var returns these two matrices in a list...
max(abs( pkern_var(g_example, pars)[['y']] - cy ))
max(abs( pkern_var(g_example, pars)[['x']] - cx ))

# ... or it can compute the full covariance matrix for model pars
var_matrix = pkern_var(g_example, pars, sep=FALSE)
var_matrix_compare = (pars$psill*cxy) + diag(pars$eps, n_test^2)
max(abs( var_matrix - var_matrix_compare ))

# extract a subgrid without computing the whole thing
cx_sub = pkern_corr_mat(pars_x, n=n_test, i=2:4, j=2:4)
cx_sub - cx[2:4, 2:4]

# gres scales distances. Increasing gres causes correlations to decrease
cx_long = pkern_corr_mat(pars_x, n=n_test, gres=2*g_example$gres)
cx_long < cx


deankoch/pkern documentation built on Oct. 26, 2023, 8:54 p.m.