constrained: Constrained Precision Matrix

Description Usage Arguments Value Note References Examples

View source: R/constrained.R

Description

Compute the maximum likelihood estimate, given certain elements are constrained to zero (e.g., an adjacency matrix). This approach is described in \insertCitehastie2009elements;textualIRCcheck.

Usage

1
constrained(Sigma, adj)

Arguments

Sigma

Covariance matrix

adj

Matrix with constraints. A zero indicates that element should be constrained to zero.

Value

A list containing the inverse covariance matrix and the covariance matrix.

Note

The algorithm is written in c++.

References

\insertAllCited

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# random adj 
# 90 % sparsity (roughly)
p <- 20
adj <- matrix(sample(0:1, size = p^2, replace = TRUE, 
              prob = c(0.9, 0.1) ), 
              nrow = p, ncol = p)

adj <-  symm_mat(adj)

diag(adj) <- 1

# random correlation matrix
set.seed(1)
cors <- cov2cor(
  solve(
  rWishart(1, p + 2, diag(p))[,,1])
)

# constrain to zero
net <- constrained(cors, adj = adj)

donaldRwilliams/IRCcheck documentation built on Dec. 20, 2021, 12:12 a.m.