Simulate a Partial Correlation Matrix

gen_net(p = 20, edge_prob = 0.3, lb = 0.05, ub = 0.3)

Arguments

p

number of variables (nodes)

edge_prob

connectivity

lb

lower bound for the partial correlations

ub

upper bound for the partial correlations

Value

A list containing the following:

  • pcor: Partial correlation matrix, encoding the conditional (in)dependence structure.

  • cors: Correlation matrix.

  • adj: Adjacency matrix.

  • trys: Number of attempts to obtain a positive definite matrix.

Note

The function checks for a valid matrix (positive definite), but sometimes this will still fail. For example, for larger p, to have large partial correlations this requires a sparse GGM (accomplished by setting edge_prob to a small value).

Examples

# \donttest{
p <- 20
n <- 500

true_net <- gen_net(p = p, edge_prob = 0.25)

y <- MASS::mvrnorm(n = n,
                   mu = rep(0, p),
                   Sigma = true_net$cors)

# default
fit_atan <- ggmncv(R = cor(y),
                   n = nrow(y),
                   penalty = "atan",
                   progress = FALSE)

# lasso
fit_l1 <- ggmncv(R = cor(y),
                 n = nrow(y),
                 penalty = "lasso",
                 progress = FALSE)

# atan
score_binary(estimate = true_net$adj,
             true = fit_atan$adj,
             model_name = "atan")
#>       measure     score model_name
#> 1 specificity 0.9281046       atan
#> 2 sensitivity 0.9729730       atan
#> 3   precision 0.7659574       atan
#> 4      recall 0.9729730       atan
#> 5    f1_score 0.8571429       atan
#> 6         mcc 0.8269739       atan

# lasso
score_binary(estimate = fit_l1$adj,
             true = true_net$adj,
             model_name = "lasso")
#>       measure     score model_name
#> 1 specificity 0.6013986      lasso
#> 2 sensitivity 0.9574468      lasso
#> 3   precision 0.4411765      lasso
#> 4      recall 0.9574468      lasso
#> 5    f1_score 0.6040268      lasso
#> 6         mcc 0.4835788      lasso
# }