Getting started with prCGGM

prCGGM estimates prior-informed conditional Gaussian graphical models (Mapelli et al., 2026), in which the conditional dependencies among \(p\) features are allowed to change with sample-level covariates, and prior knowledge on the network guides its estimation.

The model

Consider, for example, the expression levels of \(p\) proteins \(Y = (Y_1, \ldots, Y_p)^T\), \(q\) covariates \(X = (X_1, \ldots, X_q)^T\) that may influence them, and prior knowledge on the protein interactions, such as ‘STRING’ confidence scores, collected in a weight matrix \(W \in [0, 1]^{p \times p}\). The model assumes that the expression data follow a multivariate Gaussian distribution given the covariates, with a mean and a precision matrix that both depend linearly on \(X\): \[ Y \mid X \sim N_p\big(B (1, X^T)^T,\, \Omega(X)^{-1}\big), \qquad \Omega(X) = \Delta_0 + \sum_{h=1}^q X_h \Delta_h , \] where \(B\) is the \(p \times (q + 1)\) matrix of covariate effects on the means, \(\Delta_0\) is the \(p \times p\) baseline network and \(\Delta_h\), \(h = 1, \ldots, q\), are the \(p \times p\) covariate-specific components, which describe how covariate \(h\) modulates the edges.

A zero entry \(\Omega_{jk}(X) = 0\) means that features \(j\) and \(k\) are conditionally independent given all the others. The network of an individual is therefore given by the non-zero entries of \(\Omega(X)\), which combines the baseline network with the covariate-specific components according to the individual’s covariates.

Note. Numeric covariates are standardised and factors are dummy coded with the first level as the reference, so \(\Delta_0\) is the network of the reference group at the mean of the numeric covariates. Use factor() or relevel() to choose the reference level.

Estimation

The model is estimated by node-wise penalised regressions, in two steps:

  1. Mean. Each feature is regressed on the covariates with a lasso penalty to estimate \(B\); the residuals are kept for the next step.
  2. Network. For each node \(j\), the residuals of node \(j\) are regressed on the residuals of the other nodes and on their interactions with the covariates, using the sparse-group lasso penalty \[ \alpha\lambda \|(1 - W_{j,-j}) \odot d_j^0\|_1 + \vartheta\alpha\lambda \|d_j^{-0}\|_1 + (1 - \alpha)\lambda \sum_{h=1}^q \|d_j^h\|_2 , \] where \(d_j^0\) and \(d_j^h\) are the coefficients from which \(\Delta_0\) and \(\Delta_h\) are respectively estimated.

The prior weights \(W\) enter only the first term, so edges with strong prior support (\(W_{jk} \approx 1\)) are penalised less in the baseline network, while the covariate-specific changes are learnt from the data alone. The penalty depends on three hyperparameters: \(\lambda\) sets the overall sparsity, \(\alpha\) balances element-wise and group sparsity, and \(\vartheta\) sets the penalty on covariate-specific effects relative to the baseline (see Hyperparameters). By default the predictors selected for each node are then refitted by least squares, which removes the shrinkage of the edge weights without changing the selected edges. The node-wise estimates are finally combined into symmetric networks. The full estimation procedure is described in Mapelli et al. (2026).

library(prCGGM)

Example data

The package ships a small simulated data set with 1000 subjects, 10 proteins, one binary covariate and a prior weight matrix.

data(prcggm_example)
x <- prcggm_example$x
covariates <- prcggm_example$covariates
prior <- prcggm_example$prior
dim(x)
#> [1] 1000   10
table(covariates$x1)
#> 
#>   0   1 
#> 531 469
prior[1:5, 1:5]
#>       Prot1 Prot2 Prot3 Prot4 Prot5
#> Prot1     0     1     1     0     0
#> Prot2     1     0     0     0     0
#> Prot3     1     0     0     1     1
#> Prot4     0     0     1     0     0
#> Prot5     0     0     1     0     0

One function, four models

prcggm() fits the model that matches the inputs you provide:

Inputs Model
x only neighbourhood-selection GGM (lasso)
x, prior prior-weighted GGM
x, covariates conditional GGM
x, covariates, prior prior-informed conditional GGM
set.seed(1)
fit_ggm <- prcggm(x)
fit_ggm
#> Prior-informed conditional Gaussian graphical model
#>   Subjects: 1000  Features: 10  Covariates: 0 
#>   Prior knowledge: no  Symmetrisation: AND 
#>   Selection: bic_relaxed, OLS refit 
#>   Network components: Baseline
fit_full <- prcggm(x, covariates = covariates, prior = prior, tune = FALSE)
fit_full
#> Prior-informed conditional Gaussian graphical model
#>   Subjects: 1000  Features: 10  Covariates: 1 
#>   Prior knowledge: yes  Symmetrisation: AND 
#>   Selection: bic_relaxed, OLS refit 
#>   Network components: Baseline, x1_1

Both fits return a "prcggm" object. Its main elements are:

See the Value section of ?prcggm for all the elements.

Note. Call set.seed() before prcggm() to make the results reproducible.

Hyperparameters

For each node, the overall penalty \(\lambda\), the balance \(\alpha\) between element-wise and group sparsity and the relative penalty \(\vartheta\) on covariate-specific effects (over alpha_grid and theta_grid) are selected with the rule given by selection. With tune = FALSE the first value of each grid is used and only \(\lambda\) is selected.

selection \(\lambda\) \(\alpha\), \(\vartheta\) Cost
"bic_relaxed" (default) minimum BIC of the least-squares refit along the \(\lambda\) path jointly with \(\lambda\) \(\lambda\) paths only
"ebic_relaxed" minimum extended BIC of the least-squares refit jointly with \(\lambda\) \(\lambda\) paths only
"bic", "ebic" minimum BIC / extended BIC of the penalised fit jointly with \(\lambda\) \(\lambda\) paths only
"cv_min", "cv_1se" cross-validation, lambda.min or lambda.1se BIC at the selected \(\lambda\) paths and cross-validation
"stability_bic", "stability_cv" stability selection those of "bic_relaxed" or "cv_min" paths and 50 subsamples (and cross-validation)

The node-wise BIC is \(n \log(RSS_j / n) + \log(n)\, df_j\), where \(df_j\) is the number of selected predictors. The extended BIC adds a penalty that grows with the number of candidate predictors and is more conservative when \(p\) or \(q\) is large. In the relaxed rules \(RSS_j\) is that of the least-squares refit of the predictors selected at each \(\lambda\); in "bic" and "ebic" it is that of the penalised fit, which the shrinkage inflates more and more as \(n\) grows, so that these rules select increasingly dense networks with large samples. Cross-validation with lambda.min (the rule of version 0.1.0) shows the same behaviour. Stability selection refits the \(\lambda\) path on random half-samples and keeps the predictors that are selected consistently; it is accurate but much more expensive.

The node-wise estimates are combined with symm_method: "AND" (default) keeps an edge only if it is selected in both regressions, "OR" if it is selected in either. In the simulations of the paper, "bic_relaxed" with "AND" (the default) was the most accurate combination for \(n \ge 5000\), in particular for binary covariate effects, while "ebic_relaxed" with "OR" was preferable for small samples (\(n \approx 1000\)), where the BIC selects more false edges in single regressions. Both relaxed rules break down when the number of predictors of each node regression, \(P = (p - 1)(q + 1)\) with \(q\) the number of covariate columns, approaches or exceeds \(n\): for \(P / n \ge 0.5\), "stability_bic" with "OR" recovered the population-level network much better, at several times the cost. The settings of the rules can be changed with selection_control, and refit = FALSE returns the penalised coefficients.

set.seed(1)
fit <- prcggm(x, covariates = covariates, prior = prior,
              alpha_grid = c(0.5, 0.9), theta_grid = c(1, 1.3))
fit$tuning
#>      node      lambda alpha theta        bic df         time
#> 1   Prot1 0.019115095   0.5     1  -582.5420  2 0.0003436844
#> 2   Prot2 0.003672944   0.9     1  -179.3316  2 0.0005059163
#> 3   Prot3 0.022993635   0.5     1 -1972.1592  8 0.0002581159
#> 4   Prot4 0.003410227   0.9     1  -346.2624  2 0.0003641168
#> 5   Prot5 0.020008197   0.5     1  -521.4287  1 0.0003136992
#> 6   Prot6 0.021641850   0.5     1  -647.4905  1 0.0003641486
#> 7   Prot7 0.002044759   0.9     1  -798.5281  3 0.0003522158
#> 8   Prot8 0.003052658   0.9     1  -515.8601  2 0.0003474832
#> 9   Prot9 0.019154603   0.5     1  -464.3495  1 0.0003332337
#> 10 Prot10 0.004127707   0.5     1  -703.9703  3 0.0003833334

For large grids, random_search = TRUE evaluates a random proportion p_random of the combinations at each node.

The cross-validation folds (shared by all nodes and hyperparameter values), the random-search subsets and the subsamples of stability selection are drawn from the random number generator before any model is fitted, which is why set.seed() makes the results reproducible, also when running in parallel.

Inspecting the fit

summary(fit)
#> Prior-informed conditional Gaussian graphical model
#>   Subjects: 1000  Features: 10  Covariates: 1 
#>   Prior knowledge: yes  Symmetrisation: AND 
#>   Selection: bic_relaxed, OLS refit 
#> 
#> Network components:
#>  component edges density mean_abs_weight
#>   Baseline     9  0.2000           0.177
#>       x1_1     1  0.0222           0.120
#> 
#> Selected (alpha, theta) across nodes:
#>      theta
#> alpha 1
#>   0.5 6
#>   0.9 4

fit$networks contains the symmetric adjacency matrices: "Baseline" and one matrix per covariate effect, named after the encoded covariate. Factors are dummy coded with the first level as the reference, so "x1_1" is the change in the network for subjects with x1 = 1 compared with x1 = 0. Use factor() or relevel() to choose the reference level.

plot(fit)

plot(fit, component = "x1_1")

Personalised networks

The network of a new individual is the baseline plus the covariate effects weighted by the individual’s covariates. predict() applies the same standardisation and dummy coding as in the estimation data.

new_subjects <- data.frame(x1 = factor(c("0", "1")))
nets <- predict(fit, new_subjects)
names(nets)
#> [1] "Subject_1" "Subject_2"
compare_networks(nets$Subject_1, nets$Subject_2, method = "frobenius")
#> [1] 0.1691675
plot_network_difference(nets$Subject_2, nets$Subject_1)

Simulating data

simulate_prcggm_data() generates data from the model, with a scale-free baseline network, random covariate effects and a perfect, noisy or absent prior, which is useful to explore the method. The precision matrix is positive definite for every subject by construction, and the true networks are returned on the scale of the estimates: the true baseline is the network at the mean of the continuous covariates and at the reference level of the binary ones, which is what prcggm() estimates.

set.seed(2)
sim <- simulate_prcggm_data(n = 500, p = 8, n_binary = 1, n_continuous = 1,
                            prior = "noisy")
fit_sim <- prcggm(sim$x, covariates = sim$covariates, prior = sim$prior,
                  tune = FALSE)
names(fit_sim$networks)
#> [1] "Baseline" "x1_1"     "x2"

Larger problems

Pre-screening

When \(p \times q\) is large compared with \(n\), screening = TRUE removes, for each node, the predictors whose absolute correlation with the node does not exceed gamma (by default the 20th percentile of all absolute pairwise correlations). A custom 0/1 matrix can be supplied with screening_matrix. Pairs with prior support are never removed.

Parallel computing

The node-wise regressions are independent. ncores runs them in parallel on the local machine:

fit <- prcggm(x, covariates = covariates, prior = prior, ncores = 4)

SLURM clusters

For very large networks each node can be a separate task of a ‘SLURM’ array job. The workflow has three non-interactive steps:

# 1. Prepare the inputs and job scripts in a shared directory
job <- prcggm_slurm_prepare(x, covariates = covariates, prior = prior,
                            dir = "/scratch/my_project/prcggm")
job$command   # the sbatch command to submit from a shell

# 2. Each array task runs prcggm_node() through the copied job script.
#    Edit prcggm_node.sbatch (partition, memory, R module) before submitting.

# 3. When all tasks have completed
fit <- prcggm_slurm_collect("/scratch/my_project/prcggm")

References

Mapelli, A., Massi, M. C., Cuccuru, G., Di Angelantonio, E. and Ieva, F. (2026). Prior-informed conditional Gaussian graphical models: an application to protein interaction network reconstruction. arXiv:2606.31805. https://doi.org/10.48550/arXiv.2606.31805

Zhang, J. and Li, Y. (2023). High-dimensional Gaussian graphical regression models with covariates. Journal of the American Statistical Association, 118(543), 2088–2100.