chol_s2Dp {sim2Dpredictr} | R Documentation |
Build and Take the Cholesky Decomposition of a Covariance Matrix
Description
The function first builds a correlation matrix with correlation.builder,
converts that matrix to a covariance matrix if necessary, and then takes
the Cholesky decomposition of the matrix using either base R or the R
package spam
. Note that spam
is particularly effective when
the matrix is sparse.
Usage
chol_s2Dp(
matrix.type = "cov",
im.res,
use.spam = FALSE,
corr.structure = "ar1",
rho = NULL,
phi = NULL,
tau = 1,
alpha = 0.75,
corr.min = NULL,
neighborhood = "none",
w = NULL,
h = NULL,
r = NULL,
print.R = FALSE,
print.S = FALSE,
print.Q = FALSE,
sigma = 1,
triangle = "upper",
print.all = FALSE,
round.d = FALSE,
return.cov = TRUE,
return.prec = TRUE
)
Arguments
matrix.type |
Determines whether to build a covariance matrix,
|
im.res |
A vector defining the dimension of spatial data. The first entry is the number of rows and the second entry is the number of columns. |
use.spam |
If |
corr.structure |
One of |
rho |
This is the maximum possible correlation between locations i
and j. For all i,j |
phi |
A scalar value greater than 0 that determines the decay rate of
correlation. This argument is only utilized when |
tau |
A vector containing precision parameters. If of length 1, then
all precisions are assumed equal. Otherwise the length of |
alpha |
A scalar value between 0 and 1 that defines the strength of
correlations. Note that when |
corr.min |
Scalar value to specify the minimum non-zero correlation.
Any correlations below |
neighborhood |
Defines the neighborhood within which marginal
correlations are non-zero. The default is |
w , h |
If |
r |
If |
print.R , print.S , print.Q |
Logical. When |
sigma |
Specify the desired standard deviations; the default is 1, in
which case the Cholesky decomposition is of a correlation matrix. If
|
triangle |
Determine whether to output an upper
( |
print.all |
If |
round.d |
If |
return.cov , return.prec |
Logical. When |
Value
Matrix of dimension (n.row x n.col) x (n.row x n.col). If either
return.cov
or return.prec
is TRUE
, then returns a
list where the first element is the covariance or precision matrix, and the
second element is the Cholesky factor.
References
Banerjee S, Carlin BP, Gelfand AE (2015). Hierarchical Modeling and Analysis for Spatial Data, Second edition. Chapman & Hall/CRC, Boca Raton, Florida.
Ripley BD (1987). Stochastic Simulation. John Wiley & Sons. doi:10.1002/9780470316726.
Rue H (2001). “Fast Sampling of Gaussian Markov Random Fields.” Journal of the Royal Statistical Society B, 63, 325-338. doi:10.1111/1467-9868.00288.
Furrer R, Sain SR (2010). “spam: A Sparse Matrix R Package with Emphasis on MCMC Methods for Gaussian Markov Random Fields.” Journal of Statistical Software, 36(10), 1-25. https://www.jstatsoft.org/v36/i10/.
Examples
## Use R package spam for Cholesky decomposition
R_spam <- chol_s2Dp(im.res = c(3, 3), matrix.type = "prec",
use.spam = TRUE, neighborhood = "ar1",
triangle = "upper")
## Use base R for Cholesky decomposition
R_base <- chol_s2Dp(corr.structure = "ar1",
im.res = c(3, 3), rho = 0.15,
neighborhood = "round",
r = 3, use.spam = FALSE)
## Specify standard deviations instead of default of sigma = 1.
R_sd <- chol_s2Dp(corr.structure = "ar1",
im.res = c(3, 3), rho = 0.15,
neighborhood = "round", r = 3,
sigma = runif(9, 1.1, 4))
## Not run:
## Print options ON
R_pr_on <- chol_s2Dp(corr.structure = "ar1",
im.res = c(3, 3), rho = 0.15,
sigma = 1:9, neighborhood = "round",
r = 3, print.R = TRUE, print.S = TRUE)
## End(Not run)