R6 abstract class for a generic sparse Normal-Block model.
Active bindings
inference_methodinference procedure used (heuristic or integrated with EM)
nnumber of samples
pnumber of responses per sample
dnumber of variables (dimensions in X)
d0number of zi variables (dimensions in X0)
qnumber of blocks
n_edgesnumber of edges of the network (non null coefficient of the sparse precision matrix Omegaq)
model_para list with the matrices of the model parameters: B (covariates), dm1 (species variance), Omegaq (groups precision matrix)). On the internal fitting scale (`self$data$Y`, possibly column-rescaled by `NormalBlockData(scale = TRUE)`) – use `$B_original`/`$dm1_original` for the same quantities converted back to Y's original units.
B_originalregression coefficients (d x p), converted back to Y's original units (undoing `NormalBlockData(scale = TRUE)`'s column-wise rescaling, if any). Use `model_par$B` instead for the coefficients on the internal fitting scale.
dm1_originalinverse residual variance per variable (1 / Var(Y_j)), converted back to Y's original units. Use `model_par$dm1` instead for the internal fitting scale. With `noise_covariance = "spherical"`, `model_par$dm1` is a single value repeated p times (one shared variance on the fitting scale); once converted back per-variable, the p values returned here generally differ from one another whenever Y's columns were rescaled by different factors – correctly so, since a single shared *scaled* variance does not correspond to a single shared variance in the original, heterogeneous-scale units.
nb_paramnumber of parameters in the model
objectiveevolution of the objective function during (V)EM algorithm
loglik(or its variational lower bound)
deviance(or its variational lower bound)
BIC(or its variational lower bound)
entropyEntropy of the conditional distribution when applicable
ICLvariational lower bound of the ICL
EBICvariational lower bound of the EBIC
criteriaa vector with loglik, BIC and number of parameters
sparsity(overall sparsity parameter)
sparsity_weights(weights associated to each pair of groups)
sparsity_term(sparsity_term term in log-likelihood due to sparsity)
get_res_covariancewhether the residual covariance is diagonal or spherical
membershipscluster memberships
clusteringgiven as the list of elements contained in each cluster
cluster_sizesgiven as a vector of cluster sizes
elements_per_clustergiven as the list of elements contained in each cluster
Methods
NormalBlockVarBase$new()
Create a new [`NormalBlockVarBase`] object.
Usage
NormalBlockVarBase$new(
data,
q,
sparsity = 0,
control = NB_control(),
zero_inflation = FALSE
)Arguments
dataobject of NormalBlockData class, with responses and design matrix
qnumber of block/cluster
sparsitysparsity penalty on the network density
controlstructured list of more specific parameters, to generate with NB_control
zero_inflationwhether the concrete subclass models zero-inflation; set by the ZI subclasses themselves, not meant to be set by the end user. When `FALSE`, the (costly) zero-inflation probability fit (`kappa`/`B0`) is skipped entirely, since it would otherwise never be used downstream.
NormalBlockVarBase$update()
Update a [`NormalBlockVarBase`] object
All possible parameters of the child classes
Usage
NormalBlockVarBase$update(
B = NA,
dm1 = NA,
C = NA,
Omegaq = NA,
gamma = NA,
mu = NA,
kappa = NA,
alpha = NA,
M = NA,
S = NA,
ll_list = NA,
warm_started = NA,
clustering_init = NA
)Arguments
Bregression matrix
dm1diagonal vector of inverse variance matrix (variables level)
Cthe matrix of groups memberships (posterior probabilities)
Omegaqgroups inverse variance matrix
gammavariance of posterior distribution of W
mumean for posterior distribution of W
kappavector of zero-inflation probabilities
alphavector of groups probabilities
Mvariational mean for posterior distribution of W
Svariational diagonal of variances for posterior distribution of W
ll_listlist of log-lik (elbo) values
warm_startedwhether `EM_initialize()` should treat the model as already initialized (reuse B/Omegaq/dm1/C/alpha/M/S as they stand) rather than recomputing a fresh heuristic initialization – set by [warm_start_from()] and by [split()]/[merge()].
clustering_initname of a clustering heuristic to switch to, re-derived at the next `optimize()` call instead of reusing the current state (see `NB_control(clustering_init = )`). Used by [best_of_inits()].
NormalBlockVarBase$best_of_inits()
Try several clustering-initialization heuristics and keep the best-ELBO converged fit (see `NB_control(clustering_init = )` and `inst/methods_initialization_and_refine.md` for the rationale). Every candidate is first screened with a short `trial_niter` run (same idea as `candidates_split()`/`candidates_merge()`), and only the `max_training` best-screened ones are fully retrained with `control`.
Arguments
initsvector of clustering-heuristic names to try
trial_niternumber of (V)EM iterations used to cheaply screen every candidate in `inits` before fully retraining the best few
max_traininghow many of the screened candidates (best `loglik` after `trial_niter` iterations) get fully retrained with `control`
control`optimize()` control list (`niter`/`threshold`) used for the final full retraining of the `max_training` best candidates
NormalBlockVarBase$optimize()
calls optimization (EM or heuristic) and updates relevant fields
Usage
NormalBlockVarBase$optimize(
control = list(niter = 500, threshold = 1e-04),
warn = TRUE
)Arguments
controla list for controlling the optimization process
warnwhether to warn when the (V)EM stops at the `niter` cap without reaching `threshold` (see `private$warn_if_not_converged()`). Set to `FALSE` for deliberately-truncated trial fits (cheap candidate scoring in `candidates_split()`/`candidates_merge()`, the sparsity-path warm-start probe in [NormalBlockVarCollectionSparsity]) where stopping at the cap is expected and not a sign of trouble.
NormalBlockVarBase$warm_start_from()
Seed this model's starting parameters from another, already-optimized model with the same q, instead of a fresh heuristic clustering. Used by [NormalBlockVarCollectionSparsity] to warm-start each penalty in a sparsity path from the previous one's solution. `B0`/`kappa` (zero-inflation) are left untouched: they depend only on the data, already set correctly and independently on every model.
NormalBlockVarBase$split()
Create a clone of the current [`NormalBlockVarBase`] object after splitting cluster `cl` We split the cluster according to the species variances
NormalBlockVarBase$candidates_split()
generate and select a set of candidate models by splitting the clusters of the current model
NormalBlockVarBase$candidates_merge()
generate and select a set of candidate models by merging the clusters of the current model
Arguments
max_candidatesmerge candidates are, unlike split's, quadratic in q (`choose(q, q-2)` pairs) – beyond `max_candidates` pairs, only the most promising ones (largest `|Omegaq[i, j]|`, i.e. the most strongly related cluster pairs in the current fit) are actually built and trial-optimized, since merging two nearly independent blocks is rarely competitive anyway. Set to `Inf` to always try every pair.
trial_nitersee [candidates_split()]
NormalBlockVarBase$merge()
Create a clone of the current [`NormalBlockVarBase`] object after merging clusters `cl1` and `cl2`
NormalBlockVarBase$latent_network()
Extract interaction network in the latent space, as a matrix rather than a plot – see `$plot_network()` to plot it instead.
Usage
NormalBlockVarBase$latent_network(
type = c("partial_cor", "support", "precision")
)NormalBlockVarBase$plot_loglik()
plots the evolution of the objective (log-likelihood or ELBO) across the (V)EM iterations of the last call to `optimize()`.
NormalBlockVarBase$plot_network()
plot the latent network. To extract the network as a matrix instead of plotting it, use `$latent_network()`.
Usage
NormalBlockVarBase$plot_network(
type = c("partial_cor", "support"),
output = c("igraph", "corrplot"),
edge.color = c("#F8766D", "#00BFC4"),
remove.isolated = FALSE,
node.labels = NULL,
layout = igraph::layout_in_circle,
plot = TRUE
)Arguments
typeedge value in the network. Either "precision" (coefficient of the precision matrix) or "partial_cor" (partial correlation between species).
outputOutput type. Either `igraph` (for the network) or `corrplot` (for the adjacency matrix)
edge.colorLength 2 color vector. Color for positive/negative edges. Default is `c("#F8766D", "#00BFC4")`. Only relevant for igraph output.
remove.isolatedif `TRUE`, isolated node are remove before plotting. Only relevant for igraph output.
node.labelsvector of character. The labels of the nodes. The default will use the column names ot the response matrix.
layoutan optional igraph layout. Only relevant for igraph output.
plotlogical. Should the final network be displayed or only sent back to the user. Default is `TRUE`.
NormalBlockVarBase$plot()
plots the evolution of the objective during model optimization (see `plot_loglik()`)
NormalBlockVarBase$print()
User friendly print method
Usage
NormalBlockVarBase$print(model = paste("A", self$who_am_I, ".\n"))