An R6 class to represent an SBM fit with missing data
Source:R/R6Class-missSBM_fit.R
missSBM_fit.RdThe function estimateMissSBM() fits a collection of SBM for varying number of block.
Each fitted SBM is an instance of an R6 object with class missSBM_fit, described here.
This class implements the designs whose missing dyads are integrated out given the blocks
("dyad", "node", "covar-dyad", "covar-node", "block-node", "block-dyad", "snowball"). The two
other designs have their own classes, inheriting from it: missSBM_fit_doubleStandard
(missing dyads integrated out too, with a joint update of the connectivity and of the sampling
parameters) and missSBM_fit_degree (missing dyads that cannot be integrated out, imputed by
variational parameters). Use new_missSBM_fit() to build the fit of any design.
Fields are accessed via active binding and cannot be changed by the user.
This class comes with a set of R6 methods, some of them being useful for the user and exported
as S3 methods. See the documentation for show(), print(), fitted(), predict(), plot().
Active bindings
fittedSBMthe fitted SBM with class
SimpleSBM_fit_noCov,SimpleSBM_fit_withCov,SimpleSBM_fit_degreeorSimpleSBM_fit_doubleStandardinheriting from classsbm::SimpleSBM_fitfittedSamplingthe fitted sampling, inheriting from class
networkSamplingand corresponding fitsimputedNetworkThe network data as a matrix with NAs values imputed with the current model
monitoringa list carrying information about the optimization process
occupiedBlocksthe number of classes actually occupied by at least one node; can be less than
fittedSBM$nbBlocksfor an over-specified fit whose VEM has collapsed one or more classes (seerepair())degenerateTRUEifoccupiedBlocks < fittedSBM$nbBlocksimputationsthe variational parameters of the missing dyads (sparse matrix with their pattern), for the designs whose missing dyads cannot be integrated out (
missSBM_fit_degree);NULLfor the other designs, which integrate them out given the blocks (seeimputedNetworkfor the imputed network of any design)entropyImputedthe entropy of the variational distribution of the missing dyads (0 when they are integrated out given the blocks)
entropythe entropy of the variational distribution: of the blocks, and of the missing dyads when they are not integrated out
vExpecdouble: variational expectation of the log-likelihood of the observed data (the observed dyads and the sampling matrix) and of the blocks, and of the missing dyads when they are not integrated out
penaltydouble, value of the penalty term in the ICL: the connectivity of the SBM (and the effects of the covariates) counts the observed dyads, on which it is estimated, the parameters of the sampling all the dyads (or all the nodes), as the sampling matrix is fully observed
loglikdouble: approximation of the log-likelihood (variational lower bound) reached
ICLdouble: the ICL (Integrated Classification Likelihood, the smaller the better), built on the observed data (the observed dyads and the sampling matrix), the missing dyads being integrated out: -2 times the variational lower bound of the log-likelihood of the observed data and of the blocks, evaluated at the MAP memberships (hard assignment of each node to its most probable block), plus the penalty. When the missing dyads cannot be integrated out (
missSBM_fit_degree), the bound includes the expected log-likelihood and the entropy of their variational distribution.
Methods
missSBM_fit$new()
constructor for networkSampling
Usage
missSBM_fit$new(partlyObservedNet, netSampling, clusterInit, useCov = TRUE)Arguments
partlyObservedNetAn object with class
partlyObservedNetwork.netSamplingThe sampling design for the modelling of missing data (see
estimateMissSBM()), one of the designs of the class: "double-standard" formissSBM_fit_doubleStandard, "degree" formissSBM_fit_degree, the others formissSBM_fit(seenew_missSBM_fit())clusterInitInitial clustering: a vector with size
ncol(adjacencyMatrix), providing a user-defined clustering. The number of blocks is deduced from the number of levels in withclusterInit.useCovlogical. If covariates are present in partlyObservedNet, should they be used for the inference or of the network sampling design, or just for the SBM inference? default is TRUE.
missSBM_fit$doVEM()
a method to perform inference of the current missSBM fit with variational EM
Usage
missSBM_fit$doVEM(
control = list(threshold = 0.01, maxIter = 100, fixPointIter = 3, trace = TRUE)
)Arguments
controla list of VEM control parameters (see
estimateMissSBM())
missSBM_fit$split()
clone of the current fit after splitting block index in two, via a
spectral bipartition of the sub-network it induces. Builds but does not fit the
candidate (see candidates_split()).
Arguments
indexindex (integer) of the block to split
in_placereplace
self's own fit (TRUE) or return a new object (FALSE, the default)?base_netoptional precomputed network to bipartition (as built internally at the top of this method); lets
candidates_split()avoid recomputing it once per candidate.
missSBM_fit$candidates_split()
generate and cheaply trial-fit candidates obtained by splitting each
splittable block in two (see split()). A block is splittable if it has at
least 4 members and non-zero variance in its induced sub-network.
Usage
missSBM_fit$candidates_split(
control = list(threshold = 0.01, maxIter = 100, fixPointIter = 3, trace = TRUE),
trial_niter = 2
)Arguments
controla list of VEM control parameters (see
estimateMissSBM());maxIteris overridden bytrial_nitertrial_niternumber of VEM iterations used for the trial fits. Default is 2.
missSBM_fit$merge()
clone of the current fit after merging blocks indices[1] and
indices[2] into one. Builds but does not fit the candidate (see
candidates_merge()).
missSBM_fit$candidates_merge()
generate and cheaply trial-fit candidates obtained by merging pairs of
blocks (see merge()). Beyond max_candidates pairs (quadratic in the
number of blocks), only the most similar-connectivity pairs are tried.
Usage
missSBM_fit$candidates_merge(
control = list(threshold = 0.01, maxIter = 100, fixPointIter = 3, trace = TRUE),
max_candidates = 30,
trial_niter = 2
)Arguments
controla list of VEM control parameters (see
estimateMissSBM());maxIteris overridden bytrial_nitermax_candidatescap on the number of pairs tried. Default is 30.
trial_niternumber of VEM iterations used for the trial fits. Default is 2.
missSBM_fit$repair()
recovers a degenerate fit (fewer occupied classes than its structural
nbBlocks, e.g. after a VEM component collapse) by filling the empty classes (see
repair_empty_classes()) and refitting the full VEM. Mutates self in place;
a no-op if the fit is not degenerate.
Usage
missSBM_fit$repair(
control = list(threshold = 0.01, maxIter = 100, fixPointIter = 3, trace = TRUE)
)Arguments
controla list of VEM control parameters (see
estimateMissSBM())
missSBM_fit$polish()
discrete node-swap polishing (Kernighan-Lin / greedy-ICL style): after VEM
convergence, tau is near-hard and its fixed point cannot relocate a single
misclassified node (only split()/merge() fix group-level mistakes). Each
sweep computes, for every node, the closed-form complete-data log-likelihood gain of
moving it to its best alternative class (theta/pi held fixed), applies the improving,
non-class-emptying moves, then runs a full VEM to resettle. Stops as soon as a sweep
fails to improve the ICL, mutates self in place, and never leaves the ICL worse
than before the call.
Usage
missSBM_fit$polish(
control = list(threshold = 0.01, maxIter = 100, fixPointIter = 3, trace = TRUE),
max_sweeps = 10
)Arguments
controla list of VEM control parameters (see
estimateMissSBM())max_sweepsmaximum number of swap sweeps. Default is 10.
Examples
## Sample 75% of dyads in French political Blogosphere's network data
adjMatrix <- missSBM::frenchblog2007 %>%
igraph::as_adjacency_matrix(sparse = FALSE) %>%
missSBM::observeNetwork(sampling = "dyad", parameters = 0.75)
collection <- estimateMissSBM(adjMatrix, 3:5, sampling = "dyad")
#>
#>
#> Adjusting Variational EM for Stochastic Block Model
#>
#> Imputation assumes a 'dyad' network-sampling process
#>
#> Initialization of 3 model(s).
#> Performing VEM inference
#> Model with 3 blocks.
Model with 5 blocks.
Model with 4 blocks.
Polishing (node-swap)
#>
#> Looking for better solutions
#> Pass 1 Going forward ++
Pass 1 Going backward ++
my_missSBM_fit <- collection$bestModel
class(my_missSBM_fit)
#> [1] "missSBM_fit" "R6"
plot(my_missSBM_fit, "imputed")