pkern_corr_mat | R Documentation |
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
.
pkern_corr_mat(pars, n, gres = 1, i = seq(n), j = seq(n))
pars |
list of kernel parameters 'k' and 'kp' (see |
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 |
j |
vector, a subset of |
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).
the n x n correlation matrix, or its subset as specified in i
, j
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.