Package 'sparseCov'

Title: Sparse covariance estimation based on thresholding
Description: A sparse covariance estimator based on different thresholding operators.
Authors: Chenxin Jiang [aut, cre]
Maintainer: Chenxin Jiang <[email protected]>
License: MIT + file LICENSE
Version: 0.0.0.9000
Built: 2024-11-07 04:42:11 UTC
Source: https://github.com/chexjiang/sparsecov

Help Index


This function construct a covariance matrix with a block diagonal structure.

Description

This function construct a covariance matrix with a block diagonal structure.

Usage

block.true.cov(p, block.size = 3)

Arguments

p

The number of variants.

block.size

The block size.

Value

A covariance matrix with a block diagonal structure.

Examples

data.true.cov <- block.true.cov(30)
data.true.cov[1:9,1:9]

This function select the optimal thresholding level delta

Description

This function select the optimal thresholding level delta

Usage

est_delta(
  data,
  method = c("cv", "qiu"),
  operator = c("hard", "soft", "scad", "al")
)

Arguments

data

The data matrix.

method

The choice of method to select the optimal threshold level.

operator

The choice of thresholding operator.

Value

The optimal threshold level.

Examples

## generate data from a block diagonal covariance matrix structure
n <- 50
p <- 30
data.true.cov <- block.true.cov(p)
data <- sampleMVN(n, data.true.cov, sparse=TRUE)
## select the optimal thresholding level delta
delta <- est_delta(data, method='cv', operator='scad')
delta

This function computes the thresholding sparse covariance/correlation estimator with the optimal threshold level.

Description

This function computes the thresholding sparse covariance/correlation estimator with the optimal threshold level.

Usage

est_sparseCov(
  data,
  method = c("cv", "qiu"),
  operator = c("hard", "soft", "scad", "al"),
  corr = TRUE
)

Arguments

data

The data matrix.

method

The choice of method to select the optimal threshold level.

operator

The choice of the thresholding operator.

corr

The indicator of computing correlation or covariance matrix.

Value

The thresholding sparse covariance/correlation estimator.

Examples

## generate data from a block diagonal covariance matrix structure
n <- 50
p <- 30
data.true.cov <- block.true.cov(p)
data <- sampleMVN(n, data.true.cov, sparse=TRUE)
## compute the thresholding sparse covariance/correlation estimator
s <- est_sparseCov(data, method='cv', operator='scad', corr=FALSE)
s[1:9, 1:9]

This function samples MVN based on a given covariance matrix

Description

This function samples MVN based on a given covariance matrix

Usage

sampleMVN(n, Sigma, sparse = TRUE, n_cores = 1, fastmvn = FALSE)

Arguments

n

The sample size.

Sigma

The covariance matrix.

sparse

The indicator of sparse sampling or not.

n_cores

The number of cores used.

fastmvn

The indicator of fast sampling or not.

Value

The data matrix sampled from the covariance matrix.

Examples

## generate data from a block diagonal covariance matrix structure
n <- 50
p <- 30
data.true.cov <- block.true.cov(p)
data <- sampleMVN(n, data.true.cov, sparse=TRUE)
data[1:10, 1:10]

This function computes the thresholding sparse covariance estimator for a given threshold level.

Description

This function computes the thresholding sparse covariance estimator for a given threshold level.

Usage

thresh_op(z, operator, delta, n)

Arguments

z

The sample covariance matrix.

operator

The choice of the thresholding operator.

delta

The thresholding level.

n

The sample size of data matrix.

Value

The thresholding sparse covariance estimator for a given threshold level.

Examples

## generate data from a block diagonal covariance matrix structure
n <- 50
p <- 30
data.true.cov <- block.true.cov(p)
data <- sampleMVN(n, data.true.cov, sparse=TRUE)
## compute the sample covariance
z <- Rfast::cova(data) *(n-1)/n
## get the sparse covariance matrix estimator for a given threshold level
s <- thresh_op(z, operator='soft', delta=1, n=n)
s[1:9,1:9]