Base Class for a Collection of Models over a Range of Cluster Counts
Source:R/NormalBlockCollectionClusters.R
NormalBlockCollectionClusters.RdShared scaffolding for NormalBlockVarCollectionClusters and
NormalBlockMeanCollectionClusters: the models of the collection, one per
q in increasing order, model lookup and selection, the criteria plot and
the split/merge refine() search. Concrete subclasses only name the model
family.
Super class
NormalBlockCollection -> NormalBlockCollectionClusters
Active bindings
q_listnumber of blocks
deviance_violationsthe values of q whose deviance is higher than at the previous q of the collection. The models being nested, each one signals a poor local optimum, which
refine()can repair.
Methods
Inherited methods
NormalBlockCollectionClusters$new()
Create a collection over a range of q, sorted increasingly.
Usage
NormalBlockCollectionClusters$new(
mydata,
q_list,
zero_inflation = FALSE,
sparsity = 0,
control = NB_control()
)Arguments
mydataobject of NormalBlockData class, with responses and design matrix
q_listvalues of q (number of clusters) in the collection
zero_inflationwhether the models of the collection are zero-inflated
sparsitysparsity penalty on the network density
controlstructured list of more specific parameters, to generate with NB_control
NormalBlockCollectionClusters$get_best_model()
The best model of the collection for a criterion.
Usage
NormalBlockCollectionClusters$get_best_model(
crit = c("ICL", "BIC", "EBIC", "deviance")
)NormalBlockCollectionClusters$plot()
Plot the criteria of the models of the collection
against q, with a dashed line at the q selected by each criterion (see
also plot.NormalBlockCollection()).
Usage
NormalBlockCollectionClusters$plot(
criteria = c("deviance", "ICL", "BIC", "EBIC")
)Arguments
criteriathe criteria to plot, among
"deviance","ICL","BIC"and"EBIC"; all of them by default.
Returns
a ggplot2::ggplot graph
NormalBlockCollectionClusters$optimize()
optimizes every model in the collection, then – if
control$refine is TRUE (see NB_control(), the default) –
calls $refine() automatically, reporting in one line how many models
it improved.
Usage
NormalBlockCollectionClusters$optimize(
control = list(niter = 500, threshold = 1e-04, verbose = TRUE)
)NormalBlockCollectionClusters$refine()
Tries to improve every model in the collection with a
short split-and-reoptimize trial seeded from its smaller-q neighbor
("split"), a short merge-and-reoptimize trial seeded from its
larger-q neighbor ("merge"), or both (the default); a candidate
replaces the original only if it strictly lowers the deviance, so this
can only improve (or leave unchanged) each model it touches. Only
contiguous q pairs (q and q -/+ 1, both present in the collection)
are refined. Run by default after fitting a collection, see
NB_control()'s refine for the rationale.
Usage
NormalBlockCollectionClusters$refine(
trial_niter = 2,
max_candidates = 30,
directions = c("split", "merge"),
verbose = self$control$verbose,
split_rule = NULL
)Arguments
trial_niternumber of EM iterations used for the cheap trial candidates (passed to
candidates_split()/candidates_merge()) before fully re-optimizing only the best one.max_candidatespassed to
candidates_merge()(ignored for"split", which is never combinatorial in q) – see its documentation.directionswhich neighbor(s) to seed refinement candidates from:
"split"(smaller-q neighbor),"merge"(larger-q neighbor), or both (the default).verbosewhether to print, for each q attempted, whether the candidate from that neighbor improved on it. Defaults to
control$verbose(the value set at construction, seeNB_control()).split_rulehow a cluster is split to seed the q + 1 model, see the
ruleargument of the models'split():"kmeans","noise", orNULL(default) for the family's own default ("kmeans"for the variance-block family,"noise"for the mean-block one).
NormalBlockCollectionClusters$print()
User-friendly print method: as for any collection, plus a
warning line when the deviance increases with q somewhere (see
deviance_violations).