generate_sparse_cov_matrix {Glarmadillo} | R Documentation |
Generate Sparse Covariance Matrix
Description
Generates a sparse covariance matrix with specified dimension and rank. The generated matrix can be scaled or standardized, and further sparsified based on a given threshold.
Usage
generate_sparse_cov_matrix(
n,
p,
standardize = TRUE,
sparse_rho = 0,
scale_power = 0
)
Arguments
n |
The dimension of the covariance matrix (number of rows and columns). |
p |
The rank of the covariance matrix (number of non-zero eigenvalues).
Must be less than or equal to |
standardize |
Logical indicating whether to standardize the matrix, setting this to TRUE overrides scale_power and sparse_rho. |
sparse_rho |
Numeric threshold for enforcing sparsity.
Elements with absolute values below |
scale_power |
The exponent used to scale the matrix elements.
Only used if |
Value
A n
by n
covariance matrix with rank p
.
If sparse_rho
is greater than zero and standardize
is FALSE,
elements with absolute values below sparse_rho
are set to zero to increase sparsity,
while ensuring that the matrix is at least semi-definite.
Examples
# Generate a 10x10 sparse covariance matrix with rank 5
sparse_cov_matrix <- generate_sparse_cov_matrix(n = 10, p = 5)
# Generate a sparser matrix with elements below 0.3 set to zero
sparser_cov_matrix <- generate_sparse_cov_matrix(n = 100, p = 50,
sparse_rho = 0.3,
standardize = FALSE)
# Generate a standardized matrix
standardized_cov_matrix <- generate_sparse_cov_matrix(n = 100, p = 50, standardize = TRUE)