| Title: | Gaussian Models with Latent Clustering of Variables |
|---|---|
| Description: | Implements two families of Gaussian models with a latent clustering of the variables, for multivariate data whose variables co-vary, or respond to covariates, in groups. In the Normal-Block-Var model, the clusters structure the covariance through latent variables, and a network is inferred between the clusters rather than between the variables, which reduces its dimension and eases its interpretation (Tous and Chiquet (2026) <doi:10.1016/j.csda.2026.108347>). In the Normal-Block-Mean model, the variables of a cluster share the same regression profile, and a network between the variables can be inferred from their residual covariance. In both families, the clustering is either known or inferred, the network can be sparse (graphical lasso), and zero-inflated variants handle data with an excess of zeros. The parameters are estimated by expectation-maximization or variational expectation-maximization algorithms, accelerated by squared extrapolation, and a split and merge procedure improves the fits of a collection of models. The number of clusters, the sparsity of the network and the shape of the covariance are chosen with penalized criteria, cross-validation or stability selection. |
| Authors: | Jeanne Tous [aut], Julien Chiquet [aut, cre] (ORCID: <https://orcid.org/0000-0002-3629-3429>), Nestor Ngalala Manguitini [aut] |
| Maintainer: | Julien Chiquet <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.0.0 |
| Built: | 2026-11-24 09:47:51 UTC |
| Source: | https://github.com/jchiquet/normalblockr |
Extracts the (variational) BIC of a fitted normal-block
model, computed as deviance + penalty (lower is better). The penalty
charges each group of parameters the log of the number of observations
informing it (see the penalty_terms field of NormalBlockBase), so it
differs from stats::BIC()'s default log(nobs) * df computed from
logLik().
## S3 method for class 'NormalBlockBase' BIC(object, ...)## S3 method for class 'NormalBlockBase' BIC(object, ...)
object |
An object of class NormalBlockBase. |
... |
not used, only here for S3 compatibility |
A scalar: the (variational) BIC.
ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) BIC(model)ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) BIC(model)
Returns the (variational) BIC of every model in a collection of normal-block models.
## S3 method for class 'NormalBlockCollection' BIC(object, ...)## S3 method for class 'NormalBlockCollection' BIC(object, ...)
object |
An object inheriting from NormalBlockCollection. |
... |
not used, only here for S3 compatibility |
A numeric vector of BIC values, one per model in the collection.
ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) models <- normal_block(data, blocks = 2:5, control = NB_control(verbose = FALSE)) BIC(models)ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) models <- normal_block(data, blocks = 2:5, control = NB_control(verbose = FALSE)) BIC(models)
Reverse-phase protein array (RPPA) measurements of 163 proteins across 346 breast cancer tumor samples from The Cancer Genome Atlas (TCGA), along with the PAM50 molecular subtype of each sample. Used as the running example in Tous & Chiquet (2026).
brca_rppabrca_rppa
A list with 3 elements:
a 346 x 163 numeric matrix of protein expression levels (normalized log-ratios), samples in rows (named by TCGA sample identifier), proteins in columns.
a data frame with one row per sample, in the same
order as the rows of expr: sampleId (matches rownames(expr)) and 11
clinical variables, factors unless noted otherwise –
CN_CLUSTER (copy-number cluster, 5 levels), CONVERTED_STAGE (tumor
stage), ER_STATUS (estrogen receptor status), FRACTION_GENOME_ALTERED
(numeric, in [0, 1]), HER2_STATUS, METASTASIS_CODED,
METHYLATION_CLUSTER (5 levels), MUTATION_COUNT (numeric),
PAM50_SUBTYPE (5 levels: Basal-like, HER2-enriched, Luminal A, Luminal
B, Normal-like), RPPA_CLUSTER (7 levels) and AGE (numeric, in
years). A few of these have missing values for a handful of samples
(FRACTION_GENOME_ALTERED, HER2_STATUS, METASTASIS_CODED).
a data frame with one row per protein, in the
same order as the columns of expr: protein (matches colnames(expr)),
entrezGeneId, hugoGeneSymbol, type ("protein-coding" or
"phosphoprotein") and go_bp_term (a Gene Ontology Biological Process
classification, one term per protein, or "unknown" if none could be
found – see Details).
go_bp_term is derived from org.Hs.eg.db, queried by
entrezGeneId for "protein-coding" rows. Phospho-site antibodies
(type == "phosphoprotein", e.g. "EGFR_PY1068") carry a placeholder,
negative entrezGeneId (there is no separate gene for a specific
phosphorylation site, only the underlying gene) and are instead queried by
gene symbol (the part of protein before the first "_"). Each protein
typically has dozens of GO Biological Process terms; go_bp_term keeps,
for each protein, the one term shared by the most other proteins in this
dataset – giving a handful of non-trivial groups rather than one
near-singleton group per protein, more useful for comparing against an
inferred clustering. See data-raw/brca_rppa_go_annotation.R for the full
extraction code.
TCGA breast cancer cohort (Cancer Genome Atlas Network, 2012,
doi:10.1038/nature11412), downloaded via cBioPortal (brca_tcga_pub
study, https://www.cbioportal.org). go_bp_term (see Details) was
added afterwards from org.Hs.eg.db.
expr <- brca_rppa$expr X <- model.matrix(~ 0 + PAM50_SUBTYPE, data = brca_rppa$covariates) nb_data <- NormalBlockData$new(expr, X) table(brca_rppa$gene_annotation$go_bp_term)expr <- brca_rppa$expr X <- model.matrix(~ 0 + PAM50_SUBTYPE, data = brca_rppa$covariates) nb_data <- NormalBlockData$new(expr, X) table(brca_rppa$gene_annotation$go_bp_term)
Extract the regression coefficients B of a normal-block model. For the variance-block models, one column per variable, on the original scale of Y even when the variables were rescaled for the fit. For the mean-block models, one column per cluster, on the scale of the fit (the original one by default), since a profile is shared by variables of different scales.
## S3 method for class 'NormalBlockBase' coef(object, ...)## S3 method for class 'NormalBlockBase' coef(object, ...)
object |
An object of class NormalBlockBase. |
... |
not used, only here for S3 compatibility |
A d x p (variance-block) or d x q (mean-block) matrix.
ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) coef(model)[, 1:5]ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) coef(model)[, 1:5]
Extract the fitted values of a normal-block model, on the
original scale of Y. For the variance-block models, they include the
posterior mean of the latent block signals, X B + E[W] C'; for the
mean-block models, they are X B C' (with the posterior cluster
probabilities when the clustering is unknown). Zero-inflated models set
the observed zeros to 0.
## S3 method for class 'NormalBlockBase' fitted(object, ...)## S3 method for class 'NormalBlockBase' fitted(object, ...)
object |
An object of class NormalBlockBase. |
... |
not used, only here for S3 compatibility |
A matrix of fitted values extracted from the object.
ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) head(fitted(model)[, 1:5])ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) head(fitted(model)[, 1:5])
A function to draw data from the normal block model (see details). The function returns both the generated data and the corresponding model parameters, in a list.
generate_normal_block_mean_data( n = 100, p = 40, d = 1, q = 3, kappa = 0, omega_structure = "erdos-renyi", u_v = c(0.3, 0.1), SNR = 5, alpha = rep(1/q, q), range_X = c(0, 10) )generate_normal_block_mean_data( n = 100, p = 40, d = 1, q = 3, kappa = 0, omega_structure = "erdos-renyi", u_v = c(0.3, 0.1), SNR = 5, alpha = rep(1/q, q), range_X = c(0, 10) )
n |
number of individuals. Default to 100. |
p |
number of variables. Default to 40. |
d |
number of covariates. Default to 1. |
q |
number of groups. Default to 3. |
kappa |
vector (or scalar) of variable-wise probability of zero inflation. Default to 0. |
omega_structure |
the structure of the graph on which the precision matrix between variables is built. Can be a symmetric matrix with p rows/columns or a character picked in "erdos-renyi", "preferential_attachment", "community" in which case a graph is drawn with sensible generation parameters. See generate_precision_matrix for details. |
u_v |
two-size vector of positive numbers v and u controlling the generation of the precision matrix Omega: v scales the off-diagonal elements of the precision matrix (magnitude of partial correlations), and u is a positive number added to the diagonal elements to ensure positive-definiteness. The default value is c(0.3, 0.1). |
SNR |
signal-to-noise ratio: the residual covariance Sigma is
rescaled so that the squared norm of the signal X B C' is |
alpha |
the q-size vector of group proportion. Default to rep(1/q, q) |
range_X |
A 2-size vector defining the range of the uniform distribution used to draw values in X, the regressor matrix. Default is c(0, 10) |
A named list with the following element
Y a matrix of responses
X a regressor/design matrix
a list of model parameters, encompassing
B: matrix of regression coefficients
C: matrix of group membership
Omega: precision matrix of the variables
Sigma: covariance matrix of the variables
kappa: vector of ZI inflation probabilities (one per variable)
ex <- generate_normal_block_mean_data(n = 50, p = 20, d = 2, q = 3) dim(ex$Y) ex$parameters$B # one regression profile per clusterex <- generate_normal_block_mean_data(n = 50, p = 20, d = 2, q = 3) dim(ex$Y) ex$parameters$B # one regression profile per cluster
A function to draw data from the normal block model (see details). The function returns both the generated data and the corresponding model parameters, in a list.
generate_normal_block_var_data( n = 100, p = 40, d = 1, q = 3, kappa = 0, omega_structure = "erdos-renyi", u_v = c(0.3, 0.1), SNR = 0.75, alpha = rep(1/q, q), range_X = c(0, 10), range_D = c(0.5, 1.5) )generate_normal_block_var_data( n = 100, p = 40, d = 1, q = 3, kappa = 0, omega_structure = "erdos-renyi", u_v = c(0.3, 0.1), SNR = 0.75, alpha = rep(1/q, q), range_X = c(0, 10), range_D = c(0.5, 1.5) )
n |
number of individuals. Default to 100. |
p |
number of variables. Default to 40. |
d |
number of covariates. Default to 1. |
q |
number of groups. Default to 3. |
kappa |
vector (or scalar) of variable-wise probability of zero inflation. Default to 0. |
omega_structure |
the structure of the graph on which the precision matrix between groups is built. Can be a symmetric matrix with q rows/columns or a character picked in "erdos-renyi", "preferential_attachment", "community" in which case a graph is drawn with sensible generation parameters. See generate_precision_matrix for details. |
u_v |
two-size vector of positive numbers v and u controlling the generation of the precision matrix Omega: v scales the off-diagonal elements of the precision matrix (magnitude of partial correlations), and u is a positive number added to the diagonal elements to ensure positive-definiteness. The default value is c(0.3, 0.1). |
SNR |
signal-to-noise ratio: the regression coefficients B are
rescaled so that the variance of the entries of X B is |
alpha |
the q-size vector of group proportion. Default to rep(1/q, q) |
range_X |
A 2-size vector defining the range of the uniform distribution used to draw values in X, the regressor matrix. Default is c(0, 10) |
range_D |
A 2-size vector defining the range of the uniform distribution used to draw values in D, the diagonal matrix of variances of variables. Default is c(0.5, 1.5) |
A named list with the following element
Y a matrix of responses
X a regressor/design matrix
a list of model parameters, encompassing
B: matrix of regression coefficients
C: matrix of group membership
D: diagonal matrix of variance of the variables
Omega: precision matrix of the groups
Sigma: covariance matrix of the groups
kappa: vector of ZI inflation probabilities (one per variable)
ex <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) dim(ex$Y) colSums(ex$parameters$C) # sizes of the clustersex <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) dim(ex$Y) colSums(ex$parameters$C) # sizes of the clusters
Creates, without fitting it, the model (or collection of models) that
normal_block() would fit for the same arguments.
get_model( data, blocks, sparsity = 0, zero_inflation = FALSE, control = NB_control(), model = c("var", "mean") )get_model( data, blocks, sparsity = 0, zero_inflation = FALSE, control = NB_control(), model = c("var", "mean") )
data |
a NormalBlockData object, holding the responses (Y, n x p) and the covariates (X, n x d). |
blocks |
the clustering of the variables: a p x q indicator matrix
for a known clustering (e.g. |
sparsity |
the graphical-lasso penalty on Omega: |
zero_inflation |
whether to model an excess of exact zeros in Y. |
control |
a list of settings, built with |
model |
the model family: |
an R6 object: a model or a collection of models, not optimized yet.
ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) ## the model is created but not fitted, unlike with normal_block() model <- get_model(data, blocks = 3, control = NB_control(verbose = FALSE)) class(model)ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) ## the model is created but not fitted, unlike with normal_block() model <- get_model(data, blocks = 3, control = NB_control(verbose = FALSE)) class(model)
Checks if a model is of class NormalBlockBase(), i.e. any
normal-block model (variance-block or mean-block family).
isNB(object)isNB(object)
object |
An R object. |
A boolean telling whether object inherits from the NormalBlockBase class.
ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) isNB(model)ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) isNB(model)
Returns the (variational) log-likelihood of a fitted
normal-block model as a "logLik" object, compatible with stats::AIC()
and stats::BIC().
## S3 method for class 'NormalBlockBase' logLik(object, ...)## S3 method for class 'NormalBlockBase' logLik(object, ...)
object |
An object of class NormalBlockBase. |
... |
not used, only here for S3 compatibility |
An object of class "logLik". The numeric value is the
log-likelihood or its variational lower bound (ELBO), on the scale of the
data the model was fitted on (rescaled or not, see NormalBlockData); use
the heldout_loglik() method for a log-likelihood on Y's original scale.
Attributes df and nobs hold the number of parameters and observations.
ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) logLik(model)ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) logLik(model)
Returns the log-likelihood of every model in a collection of normal-block models (see NormalBlockVarCollectionClusters, NormalBlockVarCollectionSparsity, NormalBlockVarCollectionClustersSparsity).
## S3 method for class 'NormalBlockCollection' logLik(object, ...)## S3 method for class 'NormalBlockCollection' logLik(object, ...)
object |
An object inheriting from NormalBlockCollection. |
... |
not used, only here for S3 compatibility |
A numeric vector of log-likelihood values, one per model in the collection.
ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) models <- normal_block(data, blocks = 2:5, control = NB_control(verbose = FALSE)) logLik(models)ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) models <- normal_block(data, blocks = 2:5, control = NB_control(verbose = FALSE)) logLik(models)
Control the model settings and various optimization parameters
NB_control( niter = 500, threshold = 1e-04, fixed_point_niter = 5, sparsity_weights = NULL, sparsity_penalties = NULL, n_sparsity_penalties = 30, min_ratio = 0.01, fixed_tau = FALSE, clustering_init = NULL, verbose = TRUE, heuristic = FALSE, noise_covariance = NULL, refine = TRUE, acceleration = NULL )NB_control( niter = 500, threshold = 1e-04, fixed_point_niter = 5, sparsity_weights = NULL, sparsity_penalties = NULL, n_sparsity_penalties = 30, min_ratio = 0.01, fixed_tau = FALSE, clustering_init = NULL, verbose = TRUE, heuristic = FALSE, noise_covariance = NULL, refine = TRUE, acceleration = NULL )
niter |
maximal number of (V)EM iterations. |
threshold |
the (V)EM stops when the objective (log-likelihood or
ELBO) increases by less than this. A negative value runs exactly |
fixed_point_niter |
number of sweeps of the tau update for Normal-Block-Mean models with unknown clusters. Each sweep visits the rows of tau sequentially and maximizes the ELBO exactly in each, so it can never decrease the ELBO. |
sparsity_weights |
a symmetric matrix of weights applied to the penalty, entry by entry: q x q (variance-block) or p x p (mean-block). By default, 1 off the diagonal and 0 on it (the diagonal is not penalized). |
sparsity_penalties |
the penalties of a sparsity path ( |
n_sparsity_penalties |
number of penalties of the default path. |
min_ratio |
ratio between the smallest and the largest penalty of the default path. |
fixed_tau |
whether the posterior cluster probabilities stay at their
initial value ( |
clustering_init |
how to obtain the initial clustering of the q
unknown blocks: a heuristic name ("ward2", "kmeans", "sbm" or
"spectral"), an actual clustering (a vector of labels or a p x q indicator
matrix, or a list of either per q for a collection), or "best_of_inits" to
try several heuristics per model and keep the best-ELBO fit (see
NormalBlockBase's |
verbose |
whether to print the progress of the optimization. |
heuristic |
whether to use the heuristic approach (moment-based, no (V)EM
recursion) instead of the full (V)EM. Default is FALSE. In heuristic mode, no
likelihood/ELBO is computed, so |
noise_covariance |
shape of the residual covariance. Variance-block
models accept "diagonal" (variable-specific) or "spherical" (common);
mean-block models, whose Sigma is the full p x p residual covariance, also
accept "full". Default |
refine |
for collections over a range of cluster counts (both
families): whether |
acceleration |
whether the (V)EM is accelerated by SQUAREM
(Varadhan & Roland, 2008), an extrapolation built on two successive (V)EM
steps and accepted only if it does not lower the objective. Default |
A named list of parameters to pass to normal_block()'s control
argument.
ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) ## silent fits, without the split and merge search ctrl <- NB_control(verbose = FALSE, refine = FALSE) collection <- normal_block(data, blocks = 2:4, control = ctrl) summary(collection)ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) ## silent fits, without the split and merge search ctrl <- NB_control(verbose = FALSE, refine = FALSE) collection <- normal_block(data, blocks = 2:4, control = ctrl) summary(collection)
Fits a Normal-Block model, or a collection of them, by (variational) EM.
The arguments select the model: the family (model), whether the
clustering is known (blocks), whether the network is penalized
(sparsity) and whether Y is zero-inflated (zero_inflation).
normal_block( data, blocks, sparsity = 0, zero_inflation = FALSE, control = NB_control(), model = c("var", "mean") )normal_block( data, blocks, sparsity = 0, zero_inflation = FALSE, control = NB_control(), model = c("var", "mean") )
data |
a NormalBlockData object, holding the responses (Y, n x p) and the covariates (X, n x d). |
blocks |
the clustering of the variables: a p x q indicator matrix
for a known clustering (e.g. |
sparsity |
the graphical-lasso penalty on Omega: |
zero_inflation |
whether to model an excess of exact zeros in Y. |
control |
a list of settings, built with |
model |
the model family: |
a fitted model (an R6 object, see the classes listed in the reference index), or a collection of fitted models.
## Variance-block models over a range of q ex_data <- generate_normal_block_var_data(n = 100, p = 30, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) my_normal_block <- normal_block(data, blocks = 1:5) plot(my_normal_block) best <- my_normal_block$get_best_model("ICL") plot(ex_data$Y, fitted(best)); abline(0, 1) ## the same with zero-inflation ex_data_zi <- generate_normal_block_var_data(n = 50, p = 30, d = 1, q = 3, kappa = rep(0.5, 30)) zidata <- NormalBlockData$new(ex_data_zi$Y, ex_data_zi$X) my_zi_block <- normal_block(zidata, blocks = 3, zero_inflation = TRUE) ## a mean-block model (clustering in the mean rather than the covariance) ex_mean <- generate_normal_block_mean_data(n = 50, p = 20, d = 1, q = 3) mean_data <- NormalBlockData$new(ex_mean$Y, ex_mean$X) my_mean_block <- normal_block(mean_data, blocks = 3, model = "mean") coef(my_mean_block)## Variance-block models over a range of q ex_data <- generate_normal_block_var_data(n = 100, p = 30, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) my_normal_block <- normal_block(data, blocks = 1:5) plot(my_normal_block) best <- my_normal_block$get_best_model("ICL") plot(ex_data$Y, fitted(best)); abline(0, 1) ## the same with zero-inflation ex_data_zi <- generate_normal_block_var_data(n = 50, p = 30, d = 1, q = 3, kappa = rep(0.5, 30)) zidata <- NormalBlockData$new(ex_data_zi$Y, ex_data_zi$X) my_zi_block <- normal_block(zidata, blocks = 3, zero_inflation = TRUE) ## a mean-block model (clustering in the mean rather than the covariance) ex_mean <- generate_normal_block_mean_data(n = 50, p = 20, d = 1, q = 3) mean_data <- NormalBlockData$new(ex_mean$Y, ex_mean$X) my_mean_block <- normal_block(mean_data, blocks = 3, model = "mean") coef(my_mean_block)
Splits the observations into folds, fits normal_block() on all but one
fold and evaluates the held-out log-likelihood of the left-out fold (see
heldout_loglik() in NormalBlockBase), for every model of the
collection. It selects the number of clusters without a penalty, and
compares models of different families, shapes of Sigma or scalings.
normal_block_cv( data, blocks, model = c("var", "mean"), zero_inflation = FALSE, sparsity = 0, folds = 5, control = NB_control(verbose = FALSE) )normal_block_cv( data, blocks, model = c("var", "mean"), zero_inflation = FALSE, sparsity = 0, folds = 5, control = NB_control(verbose = FALSE) )
data |
a NormalBlockData object |
blocks |
as in |
model, zero_inflation, sparsity
|
as in |
folds |
the number of folds, or a vector of |
control |
a list of controls, see |
an object of class normal_block_cv: a data frame with one row
per model (q), the total held-out log-likelihood over the n
observations (loglik, larger is better) and its standard error
(se, from the spread of the per-observation values); the
per-observation values are kept in the per_observation attribute
(n x number of models) and the folds in folds. Its best attribute
is the q chosen by the one-standard-error rule, the smallest q within one
standard error of the maximum; best_max is the maximum itself, which
tends to over-select.
ex <- generate_normal_block_var_data(n = 60, p = 15, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) set.seed(1) cv <- normal_block_cv(data, blocks = 2:4, folds = 3) cvex <- generate_normal_block_var_data(n = 60, p = 15, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) set.seed(1) cv <- normal_block_cv(data, blocks = 2:4, folds = 3) cv
Fits the two model families one after the other: a mean-block model (NormalBlockMeanBase) groups the variables by how they respond to the covariates, then a variance-block model (NormalBlockVarBase) groups the residuals of that fit by how they co-vary. The two answer different questions and generally return unrelated partitions, so running both is often more informative than choosing one.
normal_block_sequential( data, blocks_mean, blocks_var, crit = c("ICL", "BIC"), zero_inflation = FALSE, control_mean = NB_control(verbose = FALSE), control_var = NB_control(verbose = FALSE) )normal_block_sequential( data, blocks_mean, blocks_var, crit = c("ICL", "BIC"), zero_inflation = FALSE, control_mean = NB_control(verbose = FALSE), control_var = NB_control(verbose = FALSE) )
data |
a NormalBlockData object |
blocks_mean |
number of clusters for the mean-block stage: an integer,
a vector of integers to explore, or a p x q indicator matrix. It can also be
a mean-block model or collection already fitted on |
blocks_var |
idem for the variance-block stage, run on the residuals |
crit |
criterion used to pick a model when a range is explored, "ICL" (the default) or "BIC" |
zero_inflation |
whether Y carries structural zeros. Both stages are then zero-inflated, sharing the same mask: the second one would otherwise re-derive it from residuals, which are never exactly zero. |
control_mean |
control list for the mean-block stage, see |
control_var |
control list for the variance-block stage |
The second stage uses an intercept-only design on purpose: the covariate effects have already been removed by the first stage.
This is a heuristic two-stage estimator, not a joint model.
an object of class normal_block_sequential, a list with the fitted
mean and var models and the residual matrix residuals handed from one
stage to the other.
ex <- generate_normal_block_mean_data(n = 80, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) fit <- normal_block_sequential(data, blocks_mean = 3, blocks_var = 2) fitex <- generate_normal_block_mean_data(n = 80, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) fit <- normal_block_sequential(data, blocks_mean = 3, blocks_var = 2) fit
R6 class holding the responses and design matrix used to fit a normal-block model.
scale)Each column of Y can be divided by its own standard deviation before
fitting. scale = NULL (the default) leaves the choice to the model
family, resolved when a model is fitted: rescaled for variance-block
models, raw for mean-block ones; TRUE or FALSE forces it for both.
Columns are never centered: the model's own intercept already absorbs each
variable's mean.
The two families need opposite defaults. A variance-block model loads every variable of a block on the same latent signal with the same weight, while on real data the variables of a block may carry that signal with different amplitudes; rescaling evens them out. A mean-block model shares a mean profile within a block, which a division by variable-specific standard deviations would break.
The resulting B, Omega and clustering are properties of the data the
model was fitted on; with rescaled data, use $B_original,
$dm1_original and fitted() for quantities in Y's original units (a
shared block covariance has no unique original-scale counterpart, since
the scaling factors differ within a block).
Ythe matrix of responses (rescaled column-wise if scale = TRUE)
Y_scalethe per-column standard deviation Y was divided by (all 1's if Y was not rescaled)
scalethe scale argument as given: TRUE, FALSE, or NULL
for the family default (see for_family())
Xthe matrix of covariates
X0the matrix of zero-inflation covariates, if applicable
formuladescribes the relationship between Y and X, and X0 if applicable, useful if not all of X's or X0's covariates should be used, should be formatted ~ X1 + X2... | Z1 + Z2... with the Normal formula before the | and the ZI formula after the |
nsample size
dnumber of covariates
d0number of zero-inflation covariates, if applicable
pnumber of variables
XtXuseful for inference in some cases
XtXm1inverse of XtX, useful for inference
XtYuseful for inference
npYtotal number of non zeros in Y
nYtotal number of non zeros for each column/variable in Y
zeroswhere are the zero in Y
zeros_barwhere are the non-zeros in Y
Y_originalthe matrix of responses as given, before any rescaling
NormalBlockData$new()Create a new NormalBlockData object.
NormalBlockData$new( Y, X, X0 = NULL, formula = NULL, scale = NULL, zeros = NULL, check_constant = TRUE )
Ythe matrix of responses (called Y in the model).
Xdesign matrix (called X in the model).
X0zero-inflation design matrix, if applicable.
formuladescribes the relationship between Y and X, useful if not all of X's covariates should be used.
scalewhether to rescale each column of Y by its own standard
deviation (no centering): NULL (default) for the model family's
default, see the section "Rescaling Y" below and for_family().
zerosan optional 0/1 matrix of structural zeros, overriding the
default Y == 0.
check_constantwhether to refuse constant columns of Y, which
carry no information to cluster on. FALSE for data only used to
evaluate a fitted model (see heldout_loglik()).
NormalBlockData$for_family()The data a model of the given family is fitted on. When
scale was given explicitly, the object itself. Otherwise (scale = NULL) the family decides: the object itself, unscaled, for the
mean-block family; a rescaled copy for the variance-block family,
built once and shared by every model fitted on it.
NormalBlockData$for_family(model = c("var", "mean"))
modelthe model family, "var" or "mean"
a NormalBlockData object
NormalBlockData$subset()The data restricted to some observations, with the same covariates, formula, zeros and scale request (a rescaled Y is rescaled again on these rows).
NormalBlockData$subset(rows, check_constant = TRUE)
rowsthe observations to keep (indices or a logical vector)
check_constantas in new()
a NormalBlockData object
NormalBlockData$ols_fit()Ordinary-least-squares fit of Y on X, with its residuals and their covariance. Computed once and memoized.
NormalBlockData$ols_fit()
a list with B (d x p), R (n x p residuals) and Sigma
(p x p residual covariance)
NormalBlockData$zi_ols_fit()Masked counterpart of ols_fit(): a per-variable weighted
least-squares fit of B under the zero-inflation mask, with its inverse
residual variances and residuals (see zi_weighted_fit()).
Computed once and memoized.
NormalBlockData$zi_ols_fit()
a list with B (d x p), dm1 (p) and R (n x p masked residuals)
NormalBlockData$zi_fit()Zero-inflation component: p independent logistic
regressions of each variable's zero pattern on X0, and the fixed
contribution they make to the log-likelihood. The (V)EM never revisits
these, so they are a property of the data rather than of a model.
NormalBlockData$zi_fit()
a list with B0 (d0 x p), kappa (n x p zero-inflation
probabilities) and ZI_cond_mean (a scalar)
NormalBlockData$clone()The objects of this class are cloneable with this method.
NormalBlockData$clone(deep = FALSE)
deepWhether to make a deep clone.
ex <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) c(n = data$n, p = data$p, d = data$d)ex <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) c(n = data$n, p = data$p, d = data$d)
R6 class for a collection of mean-block models (NormalBlockMeanBase) with different numbers of clusters (q). As for NormalBlockVarCollectionClusters, the q-independent part of the initial clustering heuristic is computed once for the whole collection.
NormalBlockCollection -> NormalBlockCollectionClusters -> NormalBlockMeanCollectionClusters
NormalBlockCollection$summary()NormalBlockCollectionClusters$get_best_model()NormalBlockCollectionClusters$get_model()NormalBlockCollectionClusters$initialize()NormalBlockCollectionClusters$optimize()NormalBlockCollectionClusters$plot()NormalBlockCollectionClusters$print()NormalBlockCollectionClusters$refine()NormalBlockMeanCollectionClusters$clone()The objects of this class are cloneable with this method.
NormalBlockMeanCollectionClusters$clone(deep = FALSE)
deepWhether to make a deep clone.
ex <- generate_normal_block_mean_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) models <- normal_block(data, blocks = 2:5, model = "mean") plot(models, criteria = c("BIC", "ICL")) models$get_best_model()ex <- generate_normal_block_mean_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) models <- normal_block(data, blocks = 2:5, model = "mean") plot(models, criteria = c("BIC", "ICL")) models$get_best_model()
R6 class for a collection of mean-block models (NormalBlockMeanBase) over both a range of cluster counts (q) and a sparsity path, i.e. one NormalBlockMeanCollectionSparsity per q. Mirrors NormalBlockVarCollectionClustersSparsity.
NormalBlockCollection -> NormalBlockCollectionClustersSparsity -> NormalBlockMeanCollectionClustersSparsity
NormalBlockMeanCollectionClustersSparsity$clone()The objects of this class are cloneable with this method.
NormalBlockMeanCollectionClustersSparsity$clone(deep = FALSE)
deepWhether to make a deep clone.
ex <- generate_normal_block_mean_data(n = 60, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) models <- normal_block(data, blocks = 2:4, sparsity = TRUE, model = "mean", control = NB_control(n_sparsity_penalties = 4)) plot(models, criterion = "BIC") models$get_best_model("BIC")ex <- generate_normal_block_mean_data(n = 60, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) models <- normal_block(data, blocks = 2:4, sparsity = TRUE, model = "mean", control = NB_control(n_sparsity_penalties = 4)) plot(models, criterion = "BIC") models$get_best_model("BIC")
R6 class for a collection of mean-block models (NormalBlockMeanBase) with a fixed clustering (or a fixed number of blocks) and different sparsity levels applied to the p x p precision matrix of the variables. Mirrors NormalBlockVarCollectionSparsity, StARS included; the default penalty grid is read off the covariance of the least-squares residuals.
NormalBlockCollection -> NormalBlockCollectionSparsity -> NormalBlockMeanCollectionSparsity
NormalBlockMeanCollectionSparsity$new()Create a new NormalBlockMeanCollectionSparsity object.
NormalBlockMeanCollectionSparsity$new( mydata, blocks, zero_inflation = FALSE, control = NB_control() )
mydataobject of NormalBlockData class, with responses and design matrix
blockseither a clustering matrix (known, fixed clustering) or a single integer (number of blocks to infer)
zero_inflationmust be FALSE: the path penalizes a full Sigma,
which zero-inflated mean-block models do not carry
controlstructured list of parameters to handle sparsity control
A new NormalBlockMeanCollectionSparsity object
NormalBlockMeanCollectionSparsity$clone()The objects of this class are cloneable with this method.
NormalBlockMeanCollectionSparsity$clone(deep = FALSE)
deepWhether to make a deep clone.
ex <- generate_normal_block_mean_data(n = 60, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) models <- normal_block(data, blocks = 3, sparsity = TRUE, model = "mean", control = NB_control(n_sparsity_penalties = 5)) plot(models, criteria = c("BIC", "EBIC"))ex <- generate_normal_block_mean_data(n = 60, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) models <- normal_block(data, blocks = 3, sparsity = TRUE, model = "mean", control = NB_control(n_sparsity_penalties = 5)) plot(models, criteria = c("BIC", "EBIC"))
R6 class for a Normal-Block-Mean model with a known clustering.
NormalBlockBase -> NormalBlockMeanBase -> NormalBlockMeanKnownClusters
NormalBlockBase$best_of_inits()NormalBlockBase$candidates_merge()NormalBlockBase$candidates_split()NormalBlockBase$heldout_loglik()NormalBlockBase$latent_network()NormalBlockBase$optimize()NormalBlockBase$plot()NormalBlockBase$plot_loglik()NormalBlockBase$plot_network()NormalBlockBase$print()NormalBlockBase$update()NormalBlockBase$warm_start_from()NormalBlockMeanBase$merge()NormalBlockMeanBase$predict()NormalBlockMeanBase$split()NormalBlockMeanKnownClusters$new()Create a new NormalBlockMeanKnownClusters object.
NormalBlockMeanKnownClusters$new(data, C, sparsity = 0, control = NB_control())
dataobject of NormalBlockData class, with responses and design matrix
Cp x q clustering matrix, C_jk = 1 if variable j belongs to cluster k
sparsityto apply on variance matrix when calling GLASSO
controlstructured list of more specific parameters, to generate with NB_control
A new NormalBlockMeanKnownClusters object
NormalBlockMeanKnownClusters$clone()The objects of this class are cloneable with this method.
NormalBlockMeanKnownClusters$clone(deep = FALSE)
deepWhether to make a deep clone.
ex <- generate_normal_block_mean_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) model <- normal_block(data, blocks = ex$parameters$C, model = "mean") plot(model)ex <- generate_normal_block_mean_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) model <- normal_block(data, blocks = ex$parameters$C, model = "mean") plot(model)
R6 class for a Normal-Block-Mean model with a fixed number of clusters (but unknown clustering), inferred by variational EM.
NormalBlockBase -> NormalBlockMeanBase -> NormalBlockMeanUnknownClusters
model_parthe parameters of NormalBlockMeanBase (B, Omega), plus alpha (cluster proportions)
var_para list with the variational parameter: tau (posterior group probabilities)
NormalBlockBase$best_of_inits()NormalBlockBase$candidates_merge()NormalBlockBase$candidates_split()NormalBlockBase$heldout_loglik()NormalBlockBase$latent_network()NormalBlockBase$optimize()NormalBlockBase$plot()NormalBlockBase$plot_loglik()NormalBlockBase$plot_network()NormalBlockBase$print()NormalBlockBase$update()NormalBlockBase$warm_start_from()NormalBlockMeanBase$merge()NormalBlockMeanBase$predict()NormalBlockMeanBase$split()NormalBlockMeanUnknownClusters$new()Create a new NormalBlockMeanUnknownClusters object.
NormalBlockMeanUnknownClusters$new( data, q, sparsity = 0, control = NB_control() )
dataobject of NormalBlockData class, with responses and design matrix
qnumber of clusters
sparsityto apply on variance matrix when calling GLASSO
controlstructured list of more specific parameters, to generate with NB_control
A new NormalBlockMeanUnknownClusters object
NormalBlockMeanUnknownClusters$clone()The objects of this class are cloneable with this method.
NormalBlockMeanUnknownClusters$clone(deep = FALSE)
deepWhether to make a deep clone.
ex <- generate_normal_block_mean_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) model <- normal_block(data, blocks = 3, model = "mean") model$clusteringex <- generate_normal_block_mean_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) model <- normal_block(data, blocks = 3, model = "mean") model$clustering
R6 class for a collection of normal-block models with different number of clusters (q) and a fixed sparsity level. The q-independent part of the initial clustering heuristic is computed once for the whole collection.
NormalBlockCollection -> NormalBlockCollectionClusters -> NormalBlockVarCollectionClusters
NormalBlockCollection$summary()NormalBlockCollectionClusters$get_best_model()NormalBlockCollectionClusters$get_model()NormalBlockCollectionClusters$initialize()NormalBlockCollectionClusters$optimize()NormalBlockCollectionClusters$plot()NormalBlockCollectionClusters$print()NormalBlockCollectionClusters$refine()NormalBlockVarCollectionClusters$clone()The objects of this class are cloneable with this method.
NormalBlockVarCollectionClusters$clone(deep = FALSE)
deepWhether to make a deep clone.
ex <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) models <- normal_block(data, blocks = 2:4, control = NB_control(verbose = FALSE)) models$get_best_model("ICL")$qex <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) models <- normal_block(data, blocks = 2:4, control = NB_control(verbose = FALSE)) models$get_best_model("ICL")$q
R6 class for a collection of normal-block models with different number of clusters (q) and different sparsity levels, i.e. one NormalBlockVarCollectionSparsity per q.
NormalBlockCollection -> NormalBlockCollectionClustersSparsity -> NormalBlockVarCollectionClustersSparsity
NormalBlockVarCollectionClustersSparsity$clone()The objects of this class are cloneable with this method.
NormalBlockVarCollectionClustersSparsity$clone(deep = FALSE)
deepWhether to make a deep clone.
ex <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) models <- normal_block(data, blocks = 2:3, sparsity = TRUE, control = NB_control(verbose = FALSE, n_sparsity_penalties = 3)) models$get_best_model("BIC")$qex <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) models <- normal_block(data, blocks = 2:3, sparsity = TRUE, control = NB_control(verbose = FALSE, n_sparsity_penalties = 3)) models$get_best_model("BIC")$q
R6 class for a collection of normal-block models with a fixed clustering (blocks) and different sparsity levels. The default penalty grid is read off the latent block covariance of a short unpenalized fit.
NormalBlockCollection -> NormalBlockCollectionSparsity -> NormalBlockVarCollectionSparsity
NormalBlockCollection$print()NormalBlockCollection$summary()NormalBlockCollectionSparsity$get_best_model()NormalBlockCollectionSparsity$get_model()NormalBlockCollectionSparsity$initialize()NormalBlockCollectionSparsity$optimize()NormalBlockCollectionSparsity$plot()NormalBlockCollectionSparsity$stability_selection()NormalBlockVarCollectionSparsity$clone()The objects of this class are cloneable with this method.
NormalBlockVarCollectionSparsity$clone(deep = FALSE)
deepWhether to make a deep clone.
ex <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) models <- normal_block(data, blocks = ex$parameters$C, sparsity = TRUE, control = NB_control(verbose = FALSE, n_sparsity_penalties = 5)) models$get_best_model("BIC")$sparsityex <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) models <- normal_block(data, blocks = ex$parameters$C, sparsity = TRUE, control = NB_control(verbose = FALSE, n_sparsity_penalties = 5)) models$get_best_model("BIC")$sparsity
R6 class for a normal-block model with known clustering.
NormalBlockBase -> NormalBlockVarBase -> NormalBlockVarKnownClusters
posterior_para list with the parameters of posterior distribution W | Y
NormalBlockBase$best_of_inits()NormalBlockBase$candidates_merge()NormalBlockBase$candidates_split()NormalBlockBase$heldout_loglik()NormalBlockBase$latent_network()NormalBlockBase$optimize()NormalBlockBase$plot()NormalBlockBase$plot_loglik()NormalBlockBase$plot_network()NormalBlockBase$predict()NormalBlockBase$print()NormalBlockBase$update()NormalBlockBase$warm_start_from()NormalBlockVarBase$merge()NormalBlockVarBase$split()NormalBlockVarBase$within_block_correlations()NormalBlockVarKnownClusters$new()Create a new NormalBlockVarKnownClusters object.
NormalBlockVarKnownClusters$new(data, C, sparsity = 0, control = NB_control())
dataobject of NormalBlockVarData class, with responses and design matrix
Cp x q clustering matrix, C_jk = 1 if variable j belongs to cluster k
sparsityto apply on variance matrix when calling GLASSO
controlstructured list of more specific parameters, to generate with NB_control
A new NormalBlockVarKnownClusters object
NormalBlockVarKnownClusters$clone()The objects of this class are cloneable with this method.
NormalBlockVarKnownClusters$clone(deep = FALSE)
deepWhether to make a deep clone.
ex <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) model <- normal_block(data, blocks = ex$parameters$C, control = NB_control(verbose = FALSE)) model$clusteringex <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) model <- normal_block(data, blocks = ex$parameters$C, control = NB_control(verbose = FALSE)) model$clustering
R6 class for a normal-block model with a fixed number of clusters (but unknown clustering).
NormalBlockBase -> NormalBlockVarBase -> NormalBlockVarUnknownClusters
model_parthe parameters of NormalBlockVarBase (B, B0, dm1, Omega), plus alpha (cluster proportions)
var_para list with the matrices of the variational parameters: M (means), S (variances), tau (posterior group probabilities)
NormalBlockBase$best_of_inits()NormalBlockBase$candidates_merge()NormalBlockBase$candidates_split()NormalBlockBase$heldout_loglik()NormalBlockBase$latent_network()NormalBlockBase$optimize()NormalBlockBase$plot()NormalBlockBase$plot_loglik()NormalBlockBase$plot_network()NormalBlockBase$predict()NormalBlockBase$print()NormalBlockBase$update()NormalBlockBase$warm_start_from()NormalBlockVarBase$merge()NormalBlockVarBase$split()NormalBlockVarBase$within_block_correlations()NormalBlockVarUnknownClusters$new()Create a new NormalBlockVarUnknownClusters object.
NormalBlockVarUnknownClusters$new( data, q, sparsity = 0, control = NB_control() )
datacontains the matrix of responses (Y) and the design matrix (X).
qrequired number of groups
sparsitysparsity penalty to add on blocks precision matrix for sparsity
controlstructured list for specific parameters
A new NormalBlockVarUnknownClusters object
NormalBlockVarUnknownClusters$clone()The objects of this class are cloneable with this method.
NormalBlockVarUnknownClusters$clone(deep = FALSE)
deepWhether to make a deep clone.
ex <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) model$clusteringex <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) model$clustering
Fish biomass per species, aggregated by sampling station, together with environmental covariates for each station. Derived from the fish community monitoring of stream sections across metropolitan France (1995-2018) by the French Office for Biodiversity (formerly ONEMA, "Office National de l'Eau et des Milieux Aquatiques"), using electrofishing.
onemaonema
A list with 2 elements:
a 399 x 46 numeric matrix of total biomass (grams) per species (3-letter species code, columns) and station (row names).
a data frame with one row per station, in the same
order as the rows of biomass: station (matches rownames(biomass))
and 14 environmental variables – slope, alt (altitude), d_source
(distance to source), strahler (Strahler stream order),
width_river_mean/width_river_cv, avg_depth_station_mean/
avg_depth_station_cv, DBO_med/DBO_cv (biological oxygen demand),
flow_med/flow_cv and temperature_med/temperature_cv (_med =
median, _cv = coefficient of variation, over the monitoring period).
The source data is organized around fishing operations (opcod):
several electrofishing operations can be carried out at the same
station over time. onema aggregates this to one row per station:
every operation is first mapped to its station (fishing_protocol.csv),
then biomass (in grams) is summed over every operation recorded at a
given station, separately for each species (i.e. biomass[s, ] is the
total biomass of each species ever caught at station s, not a single
operation's catch). Stations without environmental data are dropped.
Species observed at fewer than 10 stations are also dropped: at that
level of rarity, a zero-inflated fit's iterative initialization can fit a
species' handful of non-zero observations exactly, driving its estimated
noise precision to infinity (these species also carry essentially no
information for clustering anyway).
Danet, A., Mouchet, M., Bonnaffe, W., Thebault, E., Fontaine, C. (2021) "Species richness and food-web structure jointly drive community biomass and its temporal stability in fish communities", data set, Zenodo, doi:10.5281/zenodo.5095656.
Y <- log(1 + onema$biomass) X <- model.matrix(~ 1, data = onema$covariates) nb_data <- NormalBlockData$new(Y, X) ## zero-inflated fits; ward2 initializations suit abundance data out <- normal_block(nb_data, 2:6, zero_inflation = TRUE, control = NB_control(clustering_init = "ward2", verbose = FALSE)) out$get_best_model("ICL")Y <- log(1 + onema$biomass) X <- model.matrix(~ 1, data = onema$covariates) nb_data <- NormalBlockData$new(Y, X) ## zero-inflated fits; ward2 initializations suit abundance data out <- normal_block(nb_data, 2:6, zero_inflation = TRUE, control = NB_control(clustering_init = "ward2", verbose = FALSE)) out$get_best_model("ICL")
The held-out log-likelihood against the number of clusters, with one standard error on either side.
## S3 method for class 'normal_block_cv' plot(x, ...)## S3 method for class 'normal_block_cv' plot(x, ...)
x |
an object of class |
... |
not used, only here for S3 compatibility |
a ggplot2::ggplot graph
ex <- generate_normal_block_var_data(n = 60, p = 15, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) set.seed(1) cv <- normal_block_cv(data, blocks = 2:4, folds = 3) plot(cv)ex <- generate_normal_block_var_data(n = 60, p = 15, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) set.seed(1) cv <- normal_block_cv(data, blocks = 2:4, folds = 3) plot(cv)
Plots the evolution of the objective (log-likelihood or
ELBO) across the (V)EM iterations of the last call to optimize(), see
$plot_loglik().
## S3 method for class 'NormalBlockBase' plot(x, ...)## S3 method for class 'NormalBlockBase' plot(x, ...)
x |
An object of class NormalBlockBase. |
... |
not used, only here for S3 compatibility |
Invisibly returns the ggplot2::ggplot object; called for its side effect of plotting.
ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) plot(model)ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) plot(model)
Plots the model-selection criteria of a collection of normal-block models: against the number of clusters q for a collection over q (NormalBlockVarCollectionClusters, NormalBlockMeanCollectionClusters), against the penalty for a sparsity path (NormalBlockVarCollectionSparsity, NormalBlockMeanCollectionSparsity), with a dashed line at the model selected by each criterion; as a heatmap over q and the penalty for a collection over both (NormalBlockVarCollectionClustersSparsity, NormalBlockMeanCollectionClustersSparsity).
## S3 method for class 'NormalBlockCollection' plot(x, ...)## S3 method for class 'NormalBlockCollection' plot(x, ...)
x |
An object inheriting from NormalBlockCollection. |
... |
passed to the collection's |
Invisibly returns the ggplot2::ggplot object; called for its side effect of plotting.
ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) models <- normal_block(data, blocks = 2:5, control = NB_control(verbose = FALSE)) plot(models) plot(models, criteria = c("BIC", "ICL"))ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) models <- normal_block(data, blocks = 2:5, control = NB_control(verbose = FALSE)) plot(models) plot(models, criteria = c("BIC", "ICL"))
Predicts the mean of the observations Y for new covariates X,
on the original scale of Y: B' X for the variance-block models (the
latent block signals, centered, average out; unlike fitted(), which adds
their posterior mean for the training observations), C B' X for the
mean-block models. For zero-inflated models, the mean of the Gaussian
component.
## S3 method for class 'NormalBlockBase' predict(object, new_X, ...)## S3 method for class 'NormalBlockBase' predict(object, new_X, ...)
object |
An object of class NormalBlockBase. |
new_X |
New set of covariates. |
... |
not used, only here for S3 compatibility |
A n*p prediction matrix for new observations
ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) predict(model, ex_data$X[1:3, , drop = FALSE])[, 1:5]ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) predict(model, ex_data$X[1:3, , drop = FALSE])[, 1:5]
Print a Cross-Validated Log-Likelihood
## S3 method for class 'normal_block_cv' print(x, ...)## S3 method for class 'normal_block_cv' print(x, ...)
x |
an object of class |
... |
not used, only here for S3 compatibility |
Invisibly returns x.
ex <- generate_normal_block_var_data(n = 60, p = 15, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) set.seed(1) cv <- normal_block_cv(data, blocks = 2:4, folds = 3) print(cv)ex <- generate_normal_block_var_data(n = 60, p = 15, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) set.seed(1) cv <- normal_block_cv(data, blocks = 2:4, folds = 3) print(cv)
Reports both stages and, when aricode is available, how related the two partitions are.
## S3 method for class 'normal_block_sequential' print(x, ...)## S3 method for class 'normal_block_sequential' print(x, ...)
x |
an object of class |
... |
not used, only here for S3 compatibility |
Invisibly returns x.
ex <- generate_normal_block_mean_data(n = 80, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) fit <- normal_block_sequential(data, blocks_mean = 3, blocks_var = 2) print(fit)ex <- generate_normal_block_mean_data(n = 80, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex$Y, ex$X) fit <- normal_block_sequential(data, blocks_mean = 3, blocks_var = 2) print(fit)
Print a short summary of a fitted normal-block model: model type, goodness-of-fit criteria, and the useful fields/methods to explore it further.
## S3 method for class 'NormalBlockBase' print(x, ...)## S3 method for class 'NormalBlockBase' print(x, ...)
x |
An object of class NormalBlockBase. |
... |
not used, only here for S3 compatibility |
Invisibly returns x.
ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) print(model)ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) print(model)
Print a short summary of a collection of normal-block
models: model type and the range of q/sparsity explored. See
summary.NormalBlockCollection() for the full criteria table.
## S3 method for class 'NormalBlockCollection' print(x, ...)## S3 method for class 'NormalBlockCollection' print(x, ...)
x |
An object inheriting from NormalBlockCollection. |
... |
not used, only here for S3 compatibility |
Invisibly returns x.
ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) models <- normal_block(data, blocks = 2:5, control = NB_control(verbose = FALSE)) print(models)ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) models <- normal_block(data, blocks = 2:5, control = NB_control(verbose = FALSE)) print(models)
Print method for objects returned by summary.NormalBlockBase().
## S3 method for class 'summary.NormalBlockBase' print(x, ...)## S3 method for class 'summary.NormalBlockBase' print(x, ...)
x |
An object of class |
... |
not used, only here for S3 compatibility |
Invisibly returns x.
ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) print(summary(model))ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) print(summary(model))
Print method for objects returned by summary.NormalBlockCollection().
## S3 method for class 'summary.NormalBlockCollection' print(x, ...)## S3 method for class 'summary.NormalBlockCollection' print(x, ...)
x |
An object of class |
... |
not used, only here for S3 compatibility |
Invisibly returns x.
ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) collection <- normal_block(data, blocks = 2:4, control = NB_control(verbose = FALSE)) print(summary(collection))ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) collection <- normal_block(data, blocks = 2:4, control = NB_control(verbose = FALSE)) print(summary(collection))
Extract the covariance matrix Omega^-1. For the
variance-block models, the q x q covariance of the latent block signals,
on the scale of the fit (it has no original-scale counterpart when the
variables of a block were rescaled by different factors). For the
mean-block models, the p x p residual covariance between variables, on
the original scale of Y.
## S3 method for class 'NormalBlockBase' sigma(object, ...)## S3 method for class 'NormalBlockBase' sigma(object, ...)
object |
An object of class NormalBlockBase. |
... |
not used, only here for S3 compatibility |
The covariance matrix, of size q x q or p x p depending on the model.
ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) sigma(model)ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) sigma(model)
Summarizes a fitted normal-block model: model type, goodness-of-fit criteria, cluster sizes, and the density of the inferred network between blocks.
## S3 method for class 'NormalBlockBase' summary(object, ...)## S3 method for class 'NormalBlockBase' summary(object, ...)
object |
An object of class NormalBlockBase. |
... |
not used, only here for S3 compatibility |
An object of class summary.NormalBlockBase (a list with the
model's who_am_I, criteria, cluster_sizes and network density),
printed with a dedicated print.summary.NormalBlockBase() method.
ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) summary(model)ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) model <- normal_block(data, blocks = 3, control = NB_control(verbose = FALSE)) summary(model)
Summarizes a collection of normal-block models: model type, the full criteria table, and the range of q/sparsity explored.
## S3 method for class 'NormalBlockCollection' summary(object, ...)## S3 method for class 'NormalBlockCollection' summary(object, ...)
object |
An object inheriting from NormalBlockCollection. |
... |
not used, only here for S3 compatibility |
An object of class summary.NormalBlockCollection (a list
with the collection's who_am_I, criteria, q_range and
sparsity_range), printed with a dedicated
print.summary.NormalBlockCollection() method.
ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) models <- normal_block(data, blocks = 2:5, control = NB_control(verbose = FALSE)) summary(models)ex_data <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3) data <- NormalBlockData$new(ex_data$Y, ex_data$X) models <- normal_block(data, blocks = 2:5, control = NB_control(verbose = FALSE)) summary(models)
Term-frequency data derived from the student personal webpages of the CMU "World Wide Knowledge Base" (WebKB) project's "4 Universities" dataset (Cornell, Texas, Washington, Wisconsin computer science departments, collected January 1997). Used as one of the running examples in Tous & Chiquet (2026).
universityuniversity
A list with 3 elements:
a 504 x 1867 numeric matrix of term frequencies (row sums to 1): for each document (row, named by its original file path) and term (column), the fraction of that document's (post-preprocessing) word count made up of that term.
a named numeric vector of length 1867 (one value per
column of frequencies, same names/order), the normalized Shannon
entropy of each term's distribution across documents.
a character vector of the 100 column names of
frequencies with the highest entropies, ordered by decreasing
entropy.
Each of the 504 pages (rows) is a document; each of the 1867 columns is a
term retained after lower-casing, stripping URLs/HTML tags/control
characters/punctuation/numbers, removing English stopwords and dropping
terms occurring in fewer than 2 documents. entropies ranks every term by
how evenly it is spread across documents (Shannon entropy of each term's
normalized document distribution, in [0, 1], 1 = perfectly uniform);
terms is the 100 highest-entropy terms, i.e. the terms that are the most
informative for distinguishing documents from one another rather than
just reflecting a few documents' idiosyncratic vocabulary – the
transformation used by Tan et al. (2015).
CMU Text Learning Group, "World Wide Knowledge Base (Web->KB)
project", http://www.cs.cmu.edu/~webkb/; "4 Universities" subset,
https://www.cs.cmu.edu/afs/cs/project/theo-20/www/data/. Tan, P.-N.,
Steinbach, M., Kumar, V. (2015) "Introduction to Data Mining" (transform
used to derive entropies/terms).
Y <- log(1 + university$frequencies[, university$terms]) nb_data <- NormalBlockData$new(Y, X = matrix(1, nrow(Y), 1)) out <- normal_block(nb_data, 2:6, control = NB_control(verbose = FALSE)) out$get_best_model("ICL")Y <- log(1 + university$frequencies[, university$terms]) nb_data <- NormalBlockData$new(Y, X = matrix(1, nrow(Y), 1)) out <- normal_block(nb_data, 2:6, control = NB_control(verbose = FALSE)) out$get_best_model("ICL")
R6 class for a zero-inflated Normal-Block-Mean model with a known clustering. Sigma is diagonal or spherical here. See NormalBlockMeanBase for why a full one is out of reach under a mask.
NormalBlockBase -> NormalBlockMeanBase -> ZINormalBlockMeanKnownClusters
model_parthe parameters of NormalBlockMeanBase (B, Omega), plus B0 (zero-inflation coefficients) and kappa (zero-inflation probabilities)
NormalBlockBase$best_of_inits()NormalBlockBase$candidates_merge()NormalBlockBase$candidates_split()NormalBlockBase$heldout_loglik()NormalBlockBase$latent_network()NormalBlockBase$optimize()NormalBlockBase$plot()NormalBlockBase$plot_loglik()NormalBlockBase$plot_network()NormalBlockBase$print()NormalBlockBase$update()NormalBlockBase$warm_start_from()NormalBlockMeanBase$merge()NormalBlockMeanBase$predict()NormalBlockMeanBase$split()ZINormalBlockMeanKnownClusters$new()Create a new ZINormalBlockMeanKnownClusters object.
ZINormalBlockMeanKnownClusters$new( data, C, sparsity = 0, control = NB_control() )
dataobject of NormalBlockData class, with responses and design matrix
Cp x q clustering matrix, C_jk = 1 if variable j belongs to cluster k
sparsityunused here, kept for signature symmetry (must be 0)
controlstructured list of more specific parameters, to generate with NB_control
A new ZINormalBlockMeanKnownClusters object
ZINormalBlockMeanKnownClusters$clone()The objects of this class are cloneable with this method.
ZINormalBlockMeanKnownClusters$clone(deep = FALSE)
deepWhether to make a deep clone.
ex <- generate_normal_block_mean_data(n = 50, p = 20, d = 1, q = 3) Y <- ex$Y; Y[runif(length(Y)) < 0.2] <- 0 data <- NormalBlockData$new(Y, ex$X) model <- normal_block(data, blocks = ex$parameters$C, model = "mean", zero_inflation = TRUE) model$clusteringex <- generate_normal_block_mean_data(n = 50, p = 20, d = 1, q = 3) Y <- ex$Y; Y[runif(length(Y)) < 0.2] <- 0 data <- NormalBlockData$new(Y, ex$X) model <- normal_block(data, blocks = ex$parameters$C, model = "mean", zero_inflation = TRUE) model$clustering
R6 class for a zero-inflated Normal-Block-Mean model with a fixed number of clusters (but unknown clustering), inferred by variational EM. Sigma is diagonal or spherical here. See NormalBlockMeanBase for why a full one is out of reach under a mask.
NormalBlockBase -> NormalBlockMeanBase -> ZINormalBlockMeanUnknownClusters
var_para list with the variational parameter: tau (posterior group probabilities)
model_parthe parameters of NormalBlockMeanBase (B, Omega), plus B0 (zero-inflation coefficients), kappa (zero-inflation probabilities) and alpha (cluster proportions)
NormalBlockBase$best_of_inits()NormalBlockBase$candidates_merge()NormalBlockBase$candidates_split()NormalBlockBase$heldout_loglik()NormalBlockBase$latent_network()NormalBlockBase$optimize()NormalBlockBase$plot()NormalBlockBase$plot_loglik()NormalBlockBase$plot_network()NormalBlockBase$print()NormalBlockBase$update()NormalBlockBase$warm_start_from()NormalBlockMeanBase$merge()NormalBlockMeanBase$predict()NormalBlockMeanBase$split()ZINormalBlockMeanUnknownClusters$new()Create a new ZINormalBlockMeanUnknownClusters object.
ZINormalBlockMeanUnknownClusters$new( data, q, sparsity = 0, control = NB_control() )
dataobject of NormalBlockData class, with responses and design matrix
qnumber of clusters
sparsityunused here, kept for signature symmetry (must be 0)
controlstructured list of more specific parameters, to generate with NB_control
A new ZINormalBlockMeanUnknownClusters object
ZINormalBlockMeanUnknownClusters$clone()The objects of this class are cloneable with this method.
ZINormalBlockMeanUnknownClusters$clone(deep = FALSE)
deepWhether to make a deep clone.
ex <- generate_normal_block_mean_data(n = 50, p = 20, d = 1, q = 3) Y <- ex$Y; Y[runif(length(Y)) < 0.2] <- 0 data <- NormalBlockData$new(Y, ex$X) model <- normal_block(data, blocks = 3, model = "mean", zero_inflation = TRUE) model$clusteringex <- generate_normal_block_mean_data(n = 50, p = 20, d = 1, q = 3) Y <- ex$Y; Y[runif(length(Y)) < 0.2] <- 0 data <- NormalBlockData$new(Y, ex$X) model <- normal_block(data, blocks = 3, model = "mean", zero_inflation = TRUE) model$clustering
R6 class for a zero-inflated normal-block model with a known clustering.
NormalBlockBase -> NormalBlockVarBase -> ZINormalBlockVarKnownClusters
posterior_para list with the parameters of posterior distribution W | Y
model_parthe parameters of NormalBlockVarBase (B, B0, dm1, Omega), plus kappa (zero-inflation probabilities)
NormalBlockBase$best_of_inits()NormalBlockBase$candidates_merge()NormalBlockBase$candidates_split()NormalBlockBase$heldout_loglik()NormalBlockBase$latent_network()NormalBlockBase$optimize()NormalBlockBase$plot()NormalBlockBase$plot_loglik()NormalBlockBase$plot_network()NormalBlockBase$predict()NormalBlockBase$print()NormalBlockBase$update()NormalBlockBase$warm_start_from()NormalBlockVarBase$merge()NormalBlockVarBase$split()NormalBlockVarBase$within_block_correlations()ZINormalBlockVarKnownClusters$new()Create a new ZINormalBlockVarKnownClusters object.
ZINormalBlockVarKnownClusters$new( data, C, sparsity = 0, control = NB_control() )
dataobject of NormalBlockData class, with responses and design matrix
Cp x q clustering matrix, C_jk = 1 if variable j belongs to cluster k
sparsityto apply on variance matrix when calling GLASSO
controlstructured list of more specific parameters, to generate with NB_control
A new ZINormalBlockVarKnownClusters object
ZINormalBlockVarKnownClusters$clone()The objects of this class are cloneable with this method.
ZINormalBlockVarKnownClusters$clone(deep = FALSE)
deepWhether to make a deep clone.
ex <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3, kappa = rep(0.3, 20)) data <- NormalBlockData$new(ex$Y, ex$X) model <- normal_block(data, blocks = ex$parameters$C, zero_inflation = TRUE, control = NB_control(verbose = FALSE)) model$clusteringex <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3, kappa = rep(0.3, 20)) data <- NormalBlockData$new(ex$Y, ex$X) model <- normal_block(data, blocks = ex$parameters$C, zero_inflation = TRUE, control = NB_control(verbose = FALSE)) model$clustering
R6 class for a zero-inflated normal-block model with a fixed number of clusters (but unknown clustering).
NormalBlockBase -> NormalBlockVarBase -> ZINormalBlockVarUnknownClusters
var_para list with variational parameters
model_parthe parameters of NormalBlockVarBase (B, B0, dm1, Omega), plus kappa (zero-inflation probabilities) and alpha (cluster proportions)
NormalBlockBase$best_of_inits()NormalBlockBase$candidates_merge()NormalBlockBase$candidates_split()NormalBlockBase$heldout_loglik()NormalBlockBase$latent_network()NormalBlockBase$optimize()NormalBlockBase$plot()NormalBlockBase$plot_loglik()NormalBlockBase$plot_network()NormalBlockBase$predict()NormalBlockBase$print()NormalBlockBase$update()NormalBlockBase$warm_start_from()NormalBlockVarBase$merge()NormalBlockVarBase$split()NormalBlockVarBase$within_block_correlations()ZINormalBlockVarUnknownClusters$new()Create a new ZINormalBlockVarUnknownClusters object.
ZINormalBlockVarUnknownClusters$new( data, q, sparsity = 0, control = NB_control() )
dataobject of NormalBlockVarData class, with responses and design matrix
qrequired number of groups
sparsityto apply on variance matrix when calling GLASSO
controlstructured list of more specific parameters
A new ZINormalBlockVarUnknownClusters object
ZINormalBlockVarUnknownClusters$clone()The objects of this class are cloneable with this method.
ZINormalBlockVarUnknownClusters$clone(deep = FALSE)
deepWhether to make a deep clone.
ex <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3, kappa = rep(0.3, 20)) data <- NormalBlockData$new(ex$Y, ex$X) model <- normal_block(data, blocks = 3, zero_inflation = TRUE, control = NB_control(verbose = FALSE)) model$clusteringex <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3, kappa = rep(0.3, 20)) data <- NormalBlockData$new(ex$Y, ex$X) model <- normal_block(data, blocks = 3, zero_inflation = TRUE, control = NB_control(verbose = FALSE)) model$clustering