Function to combine single CVNs. Handy, if CVNs are computed in parallel using foreach loop and n_cores = 1
Examples
data(grid)
#' Choice of the weight matrix W. Each of 2 covariates has 3 categories
#' (uniform random)
W_grid <- create_weight_matrix("grid", k = 3, l = 3)
fit1 <- CVN(data = grid, W = W_grid, lambda1 = 1, lambda2 = 0.5,
n_cores = 1, eps = 1e-2, maxiter = 200, minimal = TRUE)
#> Estimating a CVN with 9 graphs...
#>
#> Number of cores: 1
#> Uses a warmstart...
#>
#> -------------------------
#> iteration 1 | 2.180956
#> iteration 2 | 0.115992
#> iteration 3 | 0.085701
#> iteration 4 | 0.032432
#> iteration 5 | 0.027966
#> iteration 6 | 0.014144
#> iteration 7 | 0.011243
#> iteration 8 | 0.008368
fit2 <- CVN(data = grid, W = W_grid, lambda1 = 2, lambda2 = 0.75,
gamma_ebic = 0.75,
n_cores = 1, eps = 1e-2, maxiter = 200, minimal = TRUE)
#> Estimating a CVN with 9 graphs...
#>
#> Number of cores: 1
#> Uses a warmstart...
#>
#> -------------------------
#> iteration 1 | 1.771692
#> iteration 2 | 0.153946
#> iteration 3 | 0.092411
#> iteration 4 | 0.072031
#> iteration 5 | 0.057845
#> iteration 6 | 0.029927
#> iteration 7 | 0.018960
#> iteration 8 | 0.019064
#> iteration 9 | 0.013124
#> iteration 10 | 0.011946
#> -------------------------
#> iteration 11 | 0.009990
(fit <- combine_cvn(list(fit1, fit2)))
#> Warning: gamma for ebic NOT equal in all CVNs!
#> Covariate-varying Network (CVN)
#>
#> ✓ all converged
#>
#> Number of graphs (m) : 9
#> Number of variables (p) : 10
#> Number of lambda pairs : 2
#>
#> Weight matrix (W):
#> 9 x 9 sparse Matrix of class "dsCMatrix"
#>
#> [1,] . 1 . 1 . . . . .
#> [2,] 1 . 1 . 1 . . . .
#> [3,] . 1 . . . 1 . . .
#> [4,] 1 . . . 1 . 1 . .
#> [5,] . 1 . 1 . 1 . 1 .
#> [6,] . . 1 . 1 . . . 1
#> [7,] . . . 1 . . . 1 .
#> [8,] . . . . 1 . 1 . 1
#> [9,] . . . . . 1 . 1 .
#>
#> id lambda1 lambda2 gamma1 gamma2 converged value n_iterations
#> 2 1 2 0.75 0.004938272 0.000462963 TRUE 0.009989568 12
#> 1 2 1 0.50 0.002469136 0.000308642 TRUE 0.008368467 9
#> aic bic ebic edges_median edges_iqr gamma_ebic
#> 2 13891.32 15204.33 18685.83 28 2 0.75
#> 1 14408.49 15903.86 18547.23 32 0 0.50