| Title: | LUCID with Multiple Omics Data |
|---|---|
| Description: | Implements Latent Unknown Clustering Integrating Multi-omics Data (LUCID; Peng et al. (2019) <doi:10.1093/bioinformatics/btz667>), which estimates latent clusters jointly from exposures, multi-omics data and a health outcome, with early, parallel (intermediate) or serial (late) integration of the omics layers. Provides model fitting; model selection over the number of clusters and over lasso-type penalties that select exposures and omics features, with refitting on the selected features; estimation with sporadic and list-wise missing omics data; prediction and g-computation of exposure effects; bootstrap confidence intervals whose replicates are aligned to the fitted model's cluster labels, with cluster-stability diagnostics; parallel computation of tuning grids and bootstrap replicates on all platforms; and summary and plot methods for every model type. The multi-omics framework is described in Zhao et al. (2024) <doi:10.32614/RJ-2024-012> and the missing-data extension in Zhao et al. (2024) <doi:10.1093/bioadv/vbae123>. |
| Authors: | Qiran Jia [aut, cre] (ORCID: <https://orcid.org/0000-0002-0790-5967>), Yinqi Zhao [aut] (ORCID: <https://orcid.org/0000-0003-2413-732X>), David Conti [ths] (ORCID: <https://orcid.org/0000-0002-2941-7833>), Jesse Goodrich [ctb] (ORCID: <https://orcid.org/0000-0001-6615-0472>) |
| Maintainer: | Qiran Jia <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 3.3.1 |
| Built: | 2026-12-04 05:46:44 UTC |
| Source: | https://github.com/contilab-usc/lucidus3 |
Summarises where missingness sits in an omics layer before a LUCID model is fitted, so that the choice between listwise and sporadic handling can be made from the data rather than assumed. Reports missingness by feature and by subject, flags the features and subjects that are more than half missing, and counts the distinct missingness patterns present.
The number of distinct patterns is the diagnostic that matters most for cost: the observed-data likelihood is evaluated once per pattern, so a matrix with few patterns (largely listwise missingness) is far cheaper to fit than one of the same sparsity spread over many patterns.
analyze_missing_pattern(Z)analyze_missing_pattern(Z)
Z |
An N by M omics matrix, or an object coercible to one by
|
A list with components:
Proportion missing for each of the M features.
Proportion missing for each of the N subjects.
Integer indices of features more than half missing.
Integer indices of subjects more than half missing.
Number of subjects with no missing feature.
Number of distinct missingness patterns, counting the complete pattern if any subject is complete.
Proportion of missing cells over the whole matrix.
check_na, which classifies subjects into the complete /
sporadic / listwise categories the EM algorithm branches on.
Z <- matrix(rnorm(200), nrow = 20) Z[1:3, 1] <- NA Z[5, ] <- NA analyze_missing_pattern(Z)[c("n_complete", "n_patterns", "total_missing")]Z <- matrix(rnorm(200), nrow = 20) Z[1:3, 1] <- NA Z[5, ] <- NA analyze_missing_pattern(Z)[c("n_complete", "n_patterns", "total_missing")]
Generate R bootstrap replicates of LUCID parameters and
derive confidence interval (CI) based on bootstrap. Bootstrap replicates are
generated by nonparametric resampling of subjects (the ordinary
bootstrap; the result is a boot object). Each replicate is refit with
the supplied model's own settings, warm-started from the model by default,
and its cluster labels are aligned to the model's before parameters are
combined. Supports lucid_model = "early",
lucid_model = "parallel", and lucid_model = "serial".
boot_lucid( G, Z, Y, lucid_model = NULL, CoG = NULL, CoY = NULL, model, conf = 0.95, R = 100, verbose = FALSE, min_valid = 2L, parallel = c("no", "multicore", "snow"), ncpus = 1L, cl = NULL, boot_init = c("reference", "default"), boot_n_starts = 0L, switch_tol = 1, boot_indices = NULL, ncores = NULL, drop_unstable = FALSE )boot_lucid( G, Z, Y, lucid_model = NULL, CoG = NULL, CoY = NULL, model, conf = 0.95, R = 100, verbose = FALSE, min_valid = 2L, parallel = c("no", "multicore", "snow"), ncpus = 1L, cl = NULL, boot_init = c("reference", "default"), boot_n_starts = 0L, switch_tol = 1, boot_indices = NULL, ncores = NULL, drop_unstable = FALSE )
G |
Exposures, a numeric vector, matrix, or data frame. Categorical variable should be transformed into dummy variables. If a matrix or data frame, rows represent observations and columns correspond to variables. |
Z |
Omics data: for LUCID early integration, a numeric matrix/data frame; for LUCID in parallel, a list of numeric matrices/data frames. Rows correspond to observations and columns correspond to variables. |
Y |
Outcome, a numeric vector. Categorical variable is not allowed. Binary outcome should be coded as 0 and 1. |
lucid_model |
Optional; "early", "parallel", or "serial". Auto-detected
from |
CoG |
Optional, covariates to be adjusted for estimating the latent cluster. A numeric vector, matrix or data frame. Categorical variable should be transformed into dummy variables. |
CoY |
Optional, covariates to be adjusted for estimating the association between latent cluster and the outcome. A numeric vector, matrix or data frame. Categorical variable should be transformed into dummy variables. |
model |
A LUCID model fitted by Bootstrap inference is only defined for an unpenalized fit, because a
penalized fit's selection can differ from resample to resample. Which
penalty counts is For a binary outcome fit with |
conf |
A numeric scalar between 0 and 1 to specify confidence level(s) of the required interval(s). |
R |
An integer to specify number of bootstrap replicates for LUCID model. If feasible, it is recommended to set R >= 1000. |
verbose |
A flag indicates whether detailed information is printed in console. Default is FALSE. |
min_valid |
Minimum number of bootstrap replicates that must yield finite
estimates before confidence limits can be formed. The default, 2, is the
mathematical floor. Replicates that fail are counted and warned about, and a
small number of replicates raises a warning that the limits are unstable, but
neither suppresses the limits; only fewer than |
parallel |
Type of parallelism for the bootstrap replicates:
|
ncpus |
Number of worker processes to use when |
cl |
Optional |
boot_init |
How each replicate is initialized. |
boot_n_starts |
Number of additional random starts per replicate
(default 0). A random start replaces the primary fit only if its
log-likelihood is higher by more than |
switch_tol |
Log-likelihood margin required for a random start to replace the primary fit (default 1). |
boot_indices |
Optional list of row-index vectors, one per replicate,
to use these exact resamples (for example the same resamples for several
outcomes). When given, |
ncores |
Shorthand for forked parallelism: |
drop_unstable |
If |
A list containing:
beta |
Bootstrap CI table(s) for G-to-X effects ( |
mu |
Bootstrap CI table(s) for cluster-specific omics means
( |
gamma |
Bootstrap CI table for X-to-Y parameters ( |
stage |
For |
bootstrap |
A |
stability |
Cluster stability across replicates: |
conf |
The confidence level used, so |
boot_status |
Replicate accounting: |
Two interval types are computed, both from boot::boot.ci: normal
(norm_lower/norm_upper) and percentile
(perc_lower/perc_upper). BCa intervals are not computed.
The normal limits are bias-corrected: boot::norm.ci
centres them on rather than on , so they
need not bracket the estimate column. That is the method, not an
inconsistency, and summary() now says so above its CI tables.
The estimate column (bootstrap$t0) is the supplied
model's own coefficient, for all three integration strategies. It has to be
set explicitly, because boot::boot() derives t0 by calling
the statistic on the unpermuted rows, which refits the model under a fresh
seed and so can land on a different local optimum. Before 3.3.0 only the
early branch did this, so a parallel or serial CI table reported a
throwaway refit's estimates and centred every interval on them.
# use simulated data (a small subset keeps the example quick) G <- sim_data$G[1:150, , drop = FALSE] Z <- sim_data$Z[1:150, , drop = FALSE] Y_normal <- sim_data$Y_normal[1:150] # fit lucid model fit1 <- estimate_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", family = "normal", K = 2, seed = 1008, max_itr = 20, max_tot.itr = 50) # conduct bootstrap resampling (lucid_model is auto-detected from fit1's class) # a small R keeps the example quick; `conf` sets the CI level (default 0.95) boot1 <- suppressWarnings( boot_lucid(G = G, Z = Z, Y = Y_normal, model = fit1, R = 3, conf = 0.9) ) # the replicates are independent refits, so they parallelize cleanly; each # replicate's seed is drawn up front, so set.seed() makes the run reproducible # for any number of cores. Use parallel = "multicore" on macOS/Linux and # parallel = "snow" on any platform, e.g. # boot_lucid(G = G, Z = Z, Y = Y_normal, model = fit1, R = 500, # parallel = "snow", ncpus = 4) # parallel integration: Z is a list of layers, and the result's beta/mu are # lists by layer Zp <- list(sim_data$Z[1:150, 1:5], sim_data$Z[1:150, 6:10]) fit2 <- estimate_lucid(G = G, Z = Zp, Y = Y_normal, lucid_model = "parallel", family = "normal", K = c(2, 2), seed = 1008, max_itr = 20, max_tot.itr = 50) boot3 <- suppressWarnings( boot_lucid(G = G, Z = Zp, Y = Y_normal, model = fit2, R = 3) ) names(boot3$beta) # serial integration: the result carries per-stage tables under $stage fit3 <- estimate_lucid(G = G, Z = Zp, Y = Y_normal, lucid_model = "serial", family = "normal", K = list(2, 2), seed = 1008, max_itr = 20, max_tot.itr = 50) boot4 <- suppressWarnings( boot_lucid(G = G, Z = Zp, Y = Y_normal, model = fit3, R = 3) ) names(boot4$stage[[1]])# use simulated data (a small subset keeps the example quick) G <- sim_data$G[1:150, , drop = FALSE] Z <- sim_data$Z[1:150, , drop = FALSE] Y_normal <- sim_data$Y_normal[1:150] # fit lucid model fit1 <- estimate_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", family = "normal", K = 2, seed = 1008, max_itr = 20, max_tot.itr = 50) # conduct bootstrap resampling (lucid_model is auto-detected from fit1's class) # a small R keeps the example quick; `conf` sets the CI level (default 0.95) boot1 <- suppressWarnings( boot_lucid(G = G, Z = Z, Y = Y_normal, model = fit1, R = 3, conf = 0.9) ) # the replicates are independent refits, so they parallelize cleanly; each # replicate's seed is drawn up front, so set.seed() makes the run reproducible # for any number of cores. Use parallel = "multicore" on macOS/Linux and # parallel = "snow" on any platform, e.g. # boot_lucid(G = G, Z = Z, Y = Y_normal, model = fit1, R = 500, # parallel = "snow", ncpus = 4) # parallel integration: Z is a list of layers, and the result's beta/mu are # lists by layer Zp <- list(sim_data$Z[1:150, 1:5], sim_data$Z[1:150, 6:10]) fit2 <- estimate_lucid(G = G, Z = Zp, Y = Y_normal, lucid_model = "parallel", family = "normal", K = c(2, 2), seed = 1008, max_itr = 20, max_tot.itr = 50) boot3 <- suppressWarnings( boot_lucid(G = G, Z = Zp, Y = Y_normal, model = fit2, R = 3) ) names(boot3$beta) # serial integration: the result carries per-stage tables under $stage fit3 <- estimate_lucid(G = G, Z = Zp, Y = Y_normal, lucid_model = "serial", family = "normal", K = list(2, 2), seed = 1008, max_itr = 20, max_tot.itr = 50) boot4 <- suppressWarnings( boot_lucid(G = G, Z = Zp, Y = Y_normal, model = fit3, R = 3) ) names(boot4$stage[[1]])
Turns a boot_lucid result into one row per parameter, with
the point estimate (the supplied model), the percentile confidence
interval, the share of replicates agreeing in sign with the point estimate
and the bias-corrected normal interval. Besides the model coefficients it
reports two derived quantities per stage and layer: the omics mean
difference of each non-reference cluster from the reference cluster
("mu_diff"), and the expected size of each non-reference cluster.
boot_lucid_table( boot, model, stage_names = NULL, layer_names = NULL, conf = 0.95 )boot_lucid_table( boot, model, stage_names = NULL, layer_names = NULL, conf = 0.95 )
boot |
The list returned by |
model |
The fitted model passed to |
stage_names |
Optional labels for the stages (serial) used in the
|
layer_names |
Optional labels for the omics layers within a stage (parallel stages); default "Layer1", ... |
conf |
Confidence level for the percentile and normal intervals. |
A data frame with columns Stage, Layer,
Block ("Beta (X ~ G)", "mu_diff (cl2 - cl1)", "cluster-2 size",
"Gamma (Y ~ X)"), Term, Estimate, n_boot,
CI_low, CI_high (percentile), same_sign,
CI_excl_0 (Beta and Gamma rows), median,
norm_lower, norm_upper, and Cluster (the
non-reference cluster the row refers to). For a stage-to-stage
coefficient, Term names the previous stage and layer, e.g.
"1mon_Metabolome" with stage_names = c("1mon", ...) and
layer_names = c(..., "Metabolome").
G <- sim_data$G[1:150, , drop = FALSE] Z <- sim_data$Z[1:150, , drop = FALSE] Y <- sim_data$Y_normal[1:150] fit <- estimate_lucid(G = G, Z = Z, Y = Y, lucid_model = "early", family = "normal", K = 2, seed = 1008) b <- suppressWarnings(boot_lucid(G = G, Z = Z, Y = Y, model = fit, R = 5)) head(boot_lucid_table(b, fit))G <- sim_data$G[1:150, , drop = FALSE] Z <- sim_data$Z[1:150, , drop = FALSE] Y <- sim_data$Y_normal[1:150] fit <- estimate_lucid(G = G, Z = Z, Y = Y, lucid_model = "early", family = "normal", K = 2, seed = 1008) b <- suppressWarnings(boot_lucid(G = G, Z = Z, Y = Y, model = fit, R = 5)) head(boot_lucid_table(b, fit))
Compares the values that were filled in against the values that were actually observed, feature by feature, and flags an imputation that has shifted the centre or the spread of the data far enough to distort a subsequent LUCID fit. This is a sanity check on the imputation, not a measure of its accuracy: the true values are unknown, so agreement in distribution is all that can be assessed.
For each feature, the imputed values are compared with the observed ones
through a standardised mean difference,
, and a spread ratio
. Features with no observed values or no imputed
values are skipped. The reported mean_diff is the mean absolute
standardised difference across features, and sd_ratio the mean spread
ratio. A feature that is constant where observed contributes a
sd_ratio of 1 if its imputed values are also constant, and Inf
if they are not.
The imputation is declared invalid when mean_diff exceeds 2 (the
filled values sit more than two observed standard deviations from the
observed centre), or when sd_ratio falls outside [0.3, 3] –
below that range indicates the near-constant imputation that mean-filling
produces at high missingness, which biases cluster covariances towards
singularity.
check_imputation_quality(original, imputed)check_imputation_quality(original, imputed)
original |
The data matrix before imputation, containing |
imputed |
The same matrix after imputation, with identical dimensions
and column order. A dimension mismatch is a warning, not an error, and
returns |
A list with components:
TRUE if neither threshold was breached and at
least one feature could be compared.
Mean absolute standardised mean difference across
comparable features, or NA if none.
Mean ratio of imputed to observed standard deviation, or
NA if none.
NULL when valid; otherwise a string naming the
thresholds that were breached.
safe_impute for the imputations this is meant to
check.
Z <- matrix(rnorm(200), nrow = 20) Z_na <- Z; Z_na[1:5, 1] <- NA check_imputation_quality(Z_na, safe_impute(Z_na, method = "mean"))Z <- matrix(rnorm(200), nrow = 20) Z_na <- Z; Z_na[1:5, 1] <- NA check_imputation_quality(Z_na, safe_impute(Z_na, method = "mean"))
Assigns every subject to one of the three missingness categories the LUCID EM algorithm branches on, and reports whether imputation is required at all. The categories follow the incomplete-omics extension of LUCID:
Every feature observed. Contributes the ordinary complete-data term to the likelihood.
Some but not all features observed. These are the subjects that require imputation: the missing coordinates are integrated out against the fitted cluster model in the I-step.
No feature observed for this layer. The omics term drops out of that subject's likelihood entirely, so the subject still informs the exposure and outcome models but needs no imputation.
The distinction matters for cost as well as correctness: impute_flag is
TRUE only when at least one sporadic subject exists, and a
dataset whose missingness is purely listwise is fitted without any imputation
step.
A warning is issued for any feature more than half missing, per layer.
check_na( Z, lucid_model = c("early", "parallel", "serial"), label = NULL, warn = TRUE )check_na( Z, lucid_model = c("early", "parallel", "serial"), label = NULL, warn = TRUE )
Z |
For |
lucid_model |
|
label |
Optional context for the high-missingness warning, e.g.
|
warn |
Whether to raise the high-missingness warning. It carries the
condition class |
For "early", a list with index (an N by M logical matrix
that is TRUE where observed), indicator_na (the length-N
vector of codes 1, 2, 3 above), impute_flag (a single logical), and
missing_analysis (the analyze_missing_pattern result).
For "parallel", index, indicator_na and
layer_analyses are lists with one element per layer,
impute_flag is a logical vector over layers, and
cross_layer_summary adds n_layers, n_observations,
features_per_layer, missing_pattern_counts (a table of the
joint across-layer pattern, so that subjects missing an entire layer can be
distinguished from those missing scattered features in several) and
total_missing_prop, the proportion of missing cells pooled
over layers rather than the mean of per-layer rates, which would weight a
one-feature layer as heavily as a fifty-feature one.
For "serial", n_stages, a stage list holding one
such result per stage (shaped per that stage's own type), and
impute_flag over stages.
analyze_missing_pattern for the per-layer detail.
Z <- matrix(rnorm(200), nrow = 20) Z[1:2, 1] <- NA # sporadic Z[20, ] <- NA # listwise table(check_na(Z, lucid_model = "early")$indicator_na) # parallel: one block per layer, plus a cross-layer view Zp <- list(Z, matrix(rnorm(200), nrow = 20)) check_na(Zp, lucid_model = "parallel")$cross_layer_summary$total_missing_prop # serial: one block per stage check_na(Zp, lucid_model = "serial")$n_stagesZ <- matrix(rnorm(200), nrow = 20) Z[1:2, 1] <- NA # sporadic Z[20, ] <- NA # listwise table(check_na(Z, lucid_model = "early")$indicator_na) # parallel: one block per layer, plus a cross-layer view Zp <- list(Z, matrix(rnorm(200), nrow = 20)) check_na(Zp, lucid_model = "parallel")$cross_layer_summary$total_missing_prop # serial: one block per stage check_na(Zp, lucid_model = "serial")$n_stages
EM algorithm to estimate LUCID with one or multiple omics layers
estimate_lucid( lucid_model = c("early", "parallel", "serial"), G, Z, Y, CoG = NULL, CoY = NULL, K, init_omic.data.model = "auto", useY = TRUE, tol = 0.001, max_itr = 1000, max_tot.itr = 10000, Rho_G = 0, Rho_Z_Mu = 0, Rho_Z_Cov = 0, family = c("normal", "binary"), seed = 123, init_impute = c("lod", "mix"), init_par = c("mclust", "random"), verbose = FALSE, n_starts = 1L, outcome_penalty = c("none", "firth"), Beta_ridge = 0, outcome_method = c("auto", "pip", "weighted"), init_model = NULL )estimate_lucid( lucid_model = c("early", "parallel", "serial"), G, Z, Y, CoG = NULL, CoY = NULL, K, init_omic.data.model = "auto", useY = TRUE, tol = 0.001, max_itr = 1000, max_tot.itr = 10000, Rho_G = 0, Rho_Z_Mu = 0, Rho_Z_Cov = 0, family = c("normal", "binary"), seed = 123, init_impute = c("lod", "mix"), init_par = c("mclust", "random"), verbose = FALSE, n_starts = 1L, outcome_penalty = c("none", "firth"), Beta_ridge = 0, outcome_method = c("auto", "pip", "weighted"), init_model = NULL )
lucid_model |
Specifying LUCID model, "early" for early integration, "parallel" for lucid in parallel, "serial" for lucid in serial |
G |
an N by P matrix representing exposures |
Z |
Omics data, if "early", an N by M matrix; If "parallel", a list, each element i is a matrix with N rows and P_i features; If "serial", a list, each element i is a matrix with N rows and p_i features or a list with two or more matrices with N rows and a certain number of features. Every omics block must hold at least 2 features: LUCID clusters a multivariate omics profile, so a single-feature block has no structure to cluster on and is rejected. |
Y |
a length N vector |
CoG |
an N by V matrix representing covariates to be adjusted for G -> X |
CoY |
an N by K matrix representing covariates to be adjusted for X -> Y |
K |
Number of latent clusters. If "early", an integer greater or equal to 2; If "parallel", an integer vector, same length as Z, with each element being an integer greater or equal to 2 (a list of single integers, |
init_omic.data.model |
The
The fitted object always reports the concrete geometry actually used, never
|
useY |
logical, if TRUE, EM algorithm fits a supervised LUCID; otherwise unsupervised LUCID. |
tol |
stopping criterion for the EM algorithm |
max_itr |
Maximum iterations of the EM algorithm. If the EM algorithm iterates more than max_itr without converging, the EM algorithm is forced to stop. |
max_tot.itr |
Max number of total iterations for |
Rho_G |
A scalar. This parameter is the LASSO penalty to regularize
exposure coefficients in the G-to-X model. |
Rho_Z_Mu |
A scalar. This parameter is the LASSO penalty to
regularize cluster-specific means for omics data (Z). If user wants to tune the
penalty, use the wrapper function |
Rho_Z_Cov |
A scalar. This parameter is the graphical LASSO
penalty to estimate sparse cluster-specific variance-covariance matrices for omics
data (Z). If user wants to tune the penalty, use the wrapper function |
family |
The distribution of the outcome. For |
seed |
Random seed to initialize the EM algorithm |
init_impute |
Method to initialize the imputation of missing values in
LUCID. |
init_par |
For "early", an interface to initialize EM algorithm, if mclust,
initiate the parameters using the |
verbose |
Logging level for fitting progress. If |
n_starts |
Number of independent random starts for the EM algorithm
(default 1). The EM algorithm converges only to a local optimum, so with
|
outcome_penalty |
For |
Beta_ridge |
A non-negative scalar (default 0). Ridge (weight-decay)
penalty on the multinomial cluster-assignment coefficients (G -> X, and,
for "serial", the stage-to-stage transition coefficients), passed to
|
outcome_method |
How the cluster-to-outcome (X -> Y) model is
estimated. "auto" (default) uses "weighted" when |
init_model |
Optional fitted model of the same |
An object of class early_lucid, lucid_parallel or
lucid_serial according to lucid_model. All three are lists;
the components common to every fit are:
Estimates of the exposure-to-cluster (G -> X) association.
For "early", a K by (1 + P + V) matrix of multinomial
logistic coefficients, cluster 1 as reference. For "parallel" and
"serial", a list holding the fitted object and the coefficient matrix
per layer or stage.
Cluster-specific omics means (the mu of X -> Z). A
K by M matrix for "early"; a list by layer or stage
otherwise.
Cluster-specific omics variance-covariance matrices (the
sigma of X -> Z). A list of K matrices for "early"; a list by
layer or stage otherwise.
Estimates of the cluster-to-outcome (X -> Y) association,
holding beta (absolute cluster levels), the reference-coded
cluster_effect contrasts printed by summary(), any
covariate coefficients, the residual sigma for a normal
outcome, and the parameterization used.
Posterior probability of cluster membership for each
observation, of Eq 3. An N by K matrix for
"early"; a list by layer or stage otherwise.
Number of latent clusters: an integer for "early", a list of integers for "parallel" and "serial".
Names of the G, Z and Y variables, as
list(Gnames, Znames, Ynames).
The mclust geometric model actually used
for the omics covariances – a concrete model name, never "auto",
with one entry per omics layer for "parallel" and per stage for "serial".
Under automatic selection this is the geometry BIC chose, which is what
summary() counts parameters from and what boot_lucid()
refits, so every bootstrap replicate uses the same geometry as the point
estimates.
Outcome distribution, "normal" or "binary".
Whether the outcome was used in fitting, i.e. whether the model is supervised.
The omics data the model was fitted to, for every integration
strategy: sporadically missing cells hold their imputed values and
listwise-missing rows remain NA. For "serial" it is a list with
one element per stage, each that stage's fitted omics (identical to
submodel[[i]]$Z). Before 3.3.0 a serial fit stored the omics
as supplied here instead, with every missing value intact.
The imputation method used to initialize missing omics values.
The parameter-initialization method used.
The penalties actually applied, as
list(Rho_G, Rho_Z_Mu, Rho_Z_Cov). On a lucid
fit this reports the penalties that were tuned; the companion
Rho_fit there records what the returned estimates were produced
under (zero, after the selection refit). boot_lucid
reads Rho_fit.
The outcome_penalty the model was fit
with ("none" or "firth"); boot_lucid() reads
this back to refit every bootstrap replicate the same way.
How much omics data was missing and in what pattern,
using the taxonomy of the incomplete-omics extension: complete_rows,
listwise_rows (a whole omics layer missing for that subject) and
sporadic_rows (some features missing), the corresponding
proportions, and cell-level counts total_missing_cells,
sporadic_missing_cells and prop_total_missing_cells.
For "parallel", a layer_summary data frame plus
cross_layer: the pooled proportion of missing cells (not
the mean of per-layer rates, which would weight a one-feature layer like
a fifty-feature one), rows_missing_any_layer,
rows_missing_all_layers and missing_pattern_counts, the
joint across-layer pattern. The joint view is what distinguishes a
subject missing one whole layer – who still contributes to every other
layer's E-step – from one missing all of them.
For "serial", n_stages, a per-stage breakdown, and
carried_forward, which holds by_stage (subjects with no
observed omics value at all, per stage) and into_next_stage (the
same counts per transition). See the Missing data section below for why
that matters.
When anything was imputed, imputation_quality holds the
check_imputation_quality score for the fit's own
imputation (per layer for "parallel"); a fit whose imputed values sit far
from the observed ones warns rather than passing silently.
The stopping controls used (tol, max_itr,
max_tot.itr), which bootstrap refits reuse, together with
convergence diagnostics. For "early" and "parallel" these are
converged (FALSE, with a warning, if the fit exhausted
max_itr without meeting tol), n_iter,
n_restart, loglik_trace, n_starts and
n_starts_ok. A "serial" fit runs no EM loop of its own, so it
reports converged (TRUE only if every sub-model converged),
n_iter (the total across sub-models), the per-sub-model
submodel_converged and submodel_n_iter, and
submodel_loglik_trace (each sub-model's own loglik_trace,
by stage); the full diagnostics for a stage are in
submodel[[i]]$em_control. For all three model types, the
log-likelihood trace is checked for monotonicity as it is recorded: a
decrease beyond a small, majorization-step-aware slack triggers a
warning() naming the iteration (or stage) and the two values,
once per fit with a total rather than once per iteration. What such a
decrease means depends on the regime, and the message says so: under a
plain EM step the objective cannot decrease, so a drop is a genuine
numerical problem; under sporadic missingness or a penalty the
imputation step is a majorization and the penalized mean/covariance
updates are approximate maximizers, so a bounded decrease is expected
behaviour of the algorithm as specified.
The remaining components appear only for some model types:
The observed-data log-likelihood at the returned
estimates, present for all three model types. For "early" and
"parallel" this is the single joint log-likelihood from the EM fit. A
"serial" fit runs no joint EM loop – it is a sequence of conditionally
fitted stages – so its likelihood is instead the sum of
each stage's own log-likelihood (matching cal_loglik_serial());
the individual per-stage values are in submodel[[i]]$likelihood.
Feature-selection indicators, present for all three model
types. select$selectG and select$selectZ are logical
vectors of retained exposures and omics features. For "parallel",
select$selectG is the exposure-wise union across layers (selected
in at least one layer), select$selectG_layer holds the per-layer
exposure selection, and select$selectZ holds the per-layer omics
selection (a list with at least one layer's selection reported). For
"serial", select is stage 1's own selection only
(submodel[[1]]$select) – stage 1 is the only stage whose G is
the user's actual exposures; every later stage's G is the previous
stage's posterior cluster-membership probabilities, so Rho_G is
always 0 there and that stage's selectG is not a meaningful
exposure-selection result (its selectZ still is). The complete
per-stage selection record remains available at
submodel[[i]]$select for every i.
Number of observations. Present for "parallel" and "serial"; for
"early", use nrow(fit$inclusion.p).
The E-step responsibilities over the joint cluster configuration
across layers, before they are marginalised into inclusion.p.
Present for "parallel" only – nothing in the package reads this field,
and there is no plan to extend it to "serial".
Estimates of the between-stage cluster transition
associations, one element per transition (length n_stages - 1).
Element i is the coefficient object of stage i + 1 fitted
with stage i's cluster assignment in place of the exposures, so it
has the same structure as res_Beta for that stage. Present for
"serial" only.
The fitted sub-models, one per stage, each itself an
early_lucid or lucid_parallel object. Present for "serial"
only.
Cluster labels are arbitrary in a mixture model, so LUCIDus fixes them by a
deterministic rule. When the outcome is used to estimate the clusters
(useY = TRUE), clusters are ordered by increasing outcome level (for
"serial", at the final stage). Every model or stage estimated without the
outcome (useY = FALSE, and every non-final "serial" stage) is
ordered by expected cluster size: cluster 1 (the reference) is the largest
cluster, with near-ties broken by the omics cluster means. With
useY = FALSE the labels therefore do not depend on which outcome is
attached.
CoG adjusts the first stage's exposure-to-cluster model only and
CoY the outcome model of the final stage only; later stages are
regressed on the previous stage's posterior probabilities alone.
Missing values are allowed in Z only (a missing value in G,
Y, CoG or CoY is rejected), and are handled for all
three integration strategies, for both outcome families. Two patterns are
modelled, following the incomplete-omics extension: listwise, where
a subject has no omics measurement at all, whose likelihood contribution
drops the omics term so its cluster posterior is driven by the exposures
(and the outcome, if supervised); and sporadic, where individual
cells are missing, which are treated as parameters and re-imputed inside
the EM loop from the current cluster model. Both may occur together. For a
"parallel" fit each layer is handled on its own, so a subject missing one
whole layer still contributes fully to every other layer.
A feature with no observed value in any row is rejected: no cluster mean or covariance can be estimated for it.
Two consequences of the sporadic (integrated-imputation) approach are worth stating plainly, because they affect how the reported numbers may be used:
likelihood is the integrated-imputation
objective, not the observed-data likelihood: once a cell is imputed the
density is evaluated at full dimension, treating the imputed value as
data. It is therefore not comparable across datasets with different
amounts of missingness, and the BIC inherits that – the imputed cells
are not counted as parameters and N is charged in full.
predict_lucid instead marginalizes over
missing coordinates, evaluating the density on the observed ones only.
So the same subject's cluster posterior can differ slightly between fit
time and predict time. Neither is wrong; they are different, and
deliberately so.
For a "serial" model, missingness is handled within each stage and is
not propagated across stages: a subject with no omics at stage 1
is carried into stage 2 as a fully-weighted pseudo-exposure, because that
stage's "G" is the previous stage's posterior cluster probabilities. This is
a property of the serial specification (each stage is its own sub-model),
not something the fit corrects;
missing_summary$carried_forward reports how many subjects are
affected so the limitation is at least visible.
i <- 1008 set.seed(i) G <- matrix(rnorm(500), nrow = 100) Z1 <- matrix(rnorm(1000), nrow = 100) Z2 <- matrix(rnorm(1000), nrow = 100) Z3 <- matrix(rnorm(1000), nrow = 100) Z <- list(Z1 = Z1, Z2 = Z2, Z3 = Z3) Y <- rnorm(100) CoY <- matrix(rnorm(200), nrow = 100) CoG <- matrix(rnorm(200), nrow = 100) fit1 <- estimate_lucid(G = G, Z = Z, Y = Y, K = list(2, 2, 2), lucid_model = "serial", family = "normal", seed = i, CoG = CoG, CoY = CoY, useY = TRUE, max_itr = 20, max_tot.itr = 50)i <- 1008 set.seed(i) G <- matrix(rnorm(500), nrow = 100) Z1 <- matrix(rnorm(1000), nrow = 100) Z2 <- matrix(rnorm(1000), nrow = 100) Z3 <- matrix(rnorm(1000), nrow = 100) Z <- list(Z1 = Z1, Z2 = Z2, Z3 = Z3) Y <- rnorm(100) CoY <- matrix(rnorm(200), nrow = 100) CoG <- matrix(rnorm(200), nrow = 100) fit1 <- estimate_lucid(G = G, Z = Z, Y = Y, K = list(2, 2, 2), lucid_model = "serial", family = "normal", seed = i, CoG = CoG, CoY = CoY, useY = TRUE, max_itr = 20, max_tot.itr = 50)
Computes the maximum-a-posteriori cluster label for every observation
directly from model$inclusion.p, with no need to re-run prediction
or supply G/Z/Y again. Shaped exactly like
predict_lucid()'s own pred.x: a numeric vector for early, a
list by layer for parallel, and a list by stage (recursively shaped) for
serial. Labels run 1, ..., K, matching Eq 21 and the row names used
by summary().
get_cluster_assignment(model)get_cluster_assignment(model)
model |
A fitted |
A numeric vector (early), a named list by layer (parallel), or a named list by stage (serial, each element shaped like the above depending on that stage's own type).
idx <- 1:200 G <- sim_data$G[idx, ] Z <- sim_data$Z[idx, ] Y_normal <- sim_data$Y_normal[idx, ] fit <- estimate_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", family = "normal", K = 2, max_itr = 10, max_tot.itr = 30) table(get_cluster_assignment(fit))idx <- 1:200 G <- sim_data$G[idx, ] Z <- sim_data$Z[idx, ] Y_normal <- sim_data$Y_normal[idx, ] fit <- estimate_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", family = "normal", K = 2, max_itr = 10, max_tot.itr = 30) table(get_cluster_assignment(fit))
Reports the exposure selection in the original feature space: one
entry per exposure as supplied, FALSE where the penalty dropped it.
get_selected_G(model, layer = NULL)get_selected_G(model, layer = NULL)
model |
A fitted |
layer |
For a parallel model only: which layer's own exposure
selection to return (an integer index or a layer name). If |
It reads model$selection when present – the record
lucid writes after refitting unpenalized on the surviving
features – and falls back to model$select for
estimate_lucid output, which is never refit. The
distinction matters: after the refit, model$select describes the
reduced dimensions and is all TRUE, so reading it reported
"nothing was dropped" on exactly the fits where something was. (Before
3.3.0 this function read select, and selection had no
readers at all.)
A named logical vector, one entry per exposure as supplied,
TRUE where retained. On a fit made without any penalty every
entry is TRUE.
A penalty large enough to retain too little to fit is handled by refitting on
the whole block, which leaves the recorded mask describing what the
penalty did rather than what the returned model used – all
FALSE for a fit that used every feature. When that happened, this
function warns and sets attr(, "degenerate") to TRUE on its
result, and the warning names the largest penalty that would have retained
something (from glmnet's own lambda path, for exposures).
summary() reports the same thing, and $selection carries
degenerate_G, degenerate_Z and the per-block
degenerate_Z_blocks.
For a serial model this is stage 1's selection. Stage 1 is the only stage
whose "G" is the cohort's actual exposures – from stage 2 on, "G" is the
previous stage's posterior cluster probabilities, so there is nothing there
for an exposure-selection result to describe.
idx <- 1:200 G <- sim_data$G[idx, ] Z <- sim_data$Z[idx, ] Y_normal <- sim_data$Y_normal[idx, ] fit <- estimate_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", family = "normal", K = 2, Rho_G = 0.1, max_itr = 10, max_tot.itr = 30) get_selected_G(fit)idx <- 1:200 G <- sim_data$G[idx, ] Z <- sim_data$Z[idx, ] Y_normal <- sim_data$Y_normal[idx, ] fit <- estimate_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", family = "normal", K = 2, Rho_G = 0.1, max_itr = 10, max_tot.itr = 30) get_selected_G(fit)
Reports the omics selection in the original feature space: one
entry per feature as supplied, FALSE where the penalty dropped it.
get_selected_Z(model, layer = NULL, stage = NULL)get_selected_Z(model, layer = NULL, stage = NULL)
model |
A fitted |
layer |
For a parallel model (or a serial stage that is itself a
parallel sub-model): which layer's own omics selection to return. If
|
stage |
For a serial model only: which stage's own omics selection to
return. If |
Like get_selected_G it prefers model$selection over
model$select, and it collapses any per-cluster selection matrix (a
parallel layer's selectZ can be K x M rather than a plain
vector) to one logical value per feature. A feature counts as deselected
when the penalty drove its mean to zero in every cluster, which is
Eq 18's "effect estimates are 0 across all latent clusters"; both the early
and the parallel M-step use that rule as of 3.3.0 (early previously tested
whether the cluster means differed, which also dropped a feature
whose means were equal but large).
Unlike exposure selection, every stage of a serial model has a meaningful omics selection, so this returns a per-stage breakdown rather than one stage's alone.
A named logical vector (early; parallel with layer given),
a named list of logical vectors (parallel with layer = NULL), or
a named list of per-stage results (serial).
As for get_selected_G: when a penalty retained too few
features in a block, that block was refit on all of them, so this function
warns and sets attr(, "degenerate"). The warning names the specific
layer or stage, read from $selection$degenerate_Z_blocks – asking
for one layer does not warn about a different one.
idx <- 1:200 G <- sim_data$G[idx, ] Z <- sim_data$Z[idx, ] Y_normal <- sim_data$Y_normal[idx, ] fit <- estimate_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", family = "normal", K = 2, Rho_Z_Mu = 5, max_itr = 10, max_tot.itr = 30) get_selected_Z(fit)idx <- 1:200 G <- sim_data$G[idx, ] Z <- sim_data$Z[idx, ] Y_normal <- sim_data$Y_normal[idx, ] fit <- estimate_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", family = "normal", K = 2, Rho_Z_Mu = 5, max_itr = 10, max_tot.itr = 30) get_selected_Z(fit)
Reuses plot_cluster_omic_profile()'s own feature-ranking criterion
(see its documentation for what "separation" means) rather than
introducing a second ranking rule: this is the same score
plot_cluster_omic_profile() sorts features by, just returned as
data instead of a plot. One panel is produced per relevant unit – the
whole omics matrix for early, one per layer for parallel, and for serial
one per stage (or one per layer within a stage that is itself parallel).
get_top_omics_features( model, top_n = 10, importance = c("separation", "range", "sd") )get_top_omics_features( model, top_n = 10, importance = c("separation", "range", "sd") )
model |
A fitted |
top_n |
Number of top features to return per panel (default 10). If
a panel has fewer features than |
importance |
Ranking criterion: "separation" (between-cluster spread
over within-cluster SD, the default), "range", or "sd" of the cluster
means – identical meaning to |
A named list, one entry per panel (layer/stage), each a named
numeric vector of the top top_n features by importance,
sorted descending.
idx <- 1:200 G <- sim_data$G[idx, ] Z <- sim_data$Z[idx, ] Y_normal <- sim_data$Y_normal[idx, ] fit <- estimate_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", family = "normal", K = 2, max_itr = 10, max_tot.itr = 30) get_top_omics_features(fit, top_n = 3)idx <- 1:200 G <- sim_data$G[idx, ] Z <- sim_data$Z[idx, ] Y_normal <- sim_data$Y_normal[idx, ] fit <- estimate_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", family = "normal", K = 2, max_itr = 10, max_tot.itr = 30) get_top_omics_features(fit, top_n = 3)
Fit a lucid model for integrated analysis on exposure, outcome and multi-omics data, allowing for tuning
lucid( G, Z, Y, CoG = NULL, CoY = NULL, family = c("normal", "binary"), K = 2, lucid_model = c("early", "parallel", "serial"), Rho_G = 0, Rho_Z_Mu = 0, Rho_Z_Cov = 0, verbose_tune = FALSE, ... )lucid( G, Z, Y, CoG = NULL, CoY = NULL, family = c("normal", "binary"), K = 2, lucid_model = c("early", "parallel", "serial"), Rho_G = 0, Rho_Z_Mu = 0, Rho_Z_Cov = 0, verbose_tune = FALSE, ... )
G |
Exposures, a numeric vector, matrix, or data frame. Categorical variable should be transformed into dummy variables. If a matrix or data frame, rows represent observations and columns correspond to variables. |
Z |
Omics data. If "early", an N by M matrix. If "parallel", a list, each element i is a matrix with N rows and P_i features. If "serial", a list, each element i is either a matrix with N rows and p_i features, or a list with two or more matrices with N rows. Every omics block must hold at least 2 features: LUCID clusters a multivariate omics profile, so a single-feature block has no structure to cluster on and is rejected. |
Y |
Outcome, a numeric vector. Categorical variable is not allowed. Binary outcome should be coded as 0 and 1. |
CoG |
Optional, covariates to be adjusted for estimating the latent cluster. A numeric vector, matrix or data frame. Categorical variable should be transformed into dummy variables. |
CoY |
Optional, covariates to be adjusted for estimating the association between latent cluster and the outcome. A numeric vector, matrix or data frame. Categorical variable should be transformed into dummy variables. |
family |
Distribution of outcome. For continuous outcome, use "normal"; for binary outcome, use "binary". Default is "normal". |
K |
Number of latent clusters to be tuned. For lucid_model = "early", number of latent clusters (should be greater or equal than 2). Either an integer or a vector of integer. If K is a vector, model selection on K is performed. For lucid_model = "parallel",a list with vectors of integers or just integers, same length as Z, if the element itself is a vector, model selection on K is performed; For lucid_model = "serial", a list, each element is either an integer or an list of integers, same length as Z, if the smallest element (integer) itself is a vector, model selection on K is performed |
lucid_model |
Specifying LUCID model, "early" for early integration, "parallel" for lucid in parallel, "serial" for lucid in serial |
Rho_G |
A scalar or a vector. This parameter is the LASSO penalty to regularize
exposure coefficients in the G-to-X model; |
Rho_Z_Mu |
A scalar or a vector. This parameter is the LASSO penalty to
regularize cluster-specific means for omics data (Z). If it is a vector,
|
Rho_Z_Cov |
A scalar or a vector. This parameter is the graphical LASSO
penalty to estimate sparse cluster-specific variance-covariance matrices for omics
data (Z). If it is a vector, |
verbose_tune |
A flag to print details of tuning process. |
... |
Other parameters passed to |
A fitted LUCID model of class early_lucid,
lucid_parallel or lucid_serial – the candidate with the lowest
BIC when K or any penalty is given as a vector, and otherwise simply
the single fitted model. The components are those documented in
estimate_lucid, with one addition:
Present for all three integration strategies
(it was "early" only before 3.3.0), whenever a non-zero penalty was
requested. Records what the tuned penalties dropped, in the
original feature space, so FALSE marks a dropped
feature: selectG (named over the input exposures),
selectG_layer (per layer, for "parallel"), selectZ
(a vector for "early", a list by layer for "parallel", a list by stage
for "serial"), the corresponding Gnames/Znames, the
tuned Rho, degenerate_G/degenerate_Z (with the
per-block degenerate_Z_blocks, which names which layer or
stage was degenerate), ceiling_G (the largest Rho_G that
would have retained an exposure, when one was needed),
TRUE when nothing survived the penalty and the model was
therefore refit on everything (which also raises a warning).
selection is what get_selected_G and
get_selected_Z report. It is deliberately not the same
as the model's own select, which after the refit describes the
reduced dimensions and is what summary() and the BIC
index res_Beta/res_Mu with.
The penalties the returned estimates were actually
produced under – all zero after a selection refit – as distinct from
Rho, which reports the penalties that were tuned.
boot_lucid reads Rho_fit to decide whether a fit
is penalized.
When any penalty is non-zero, lucid tunes over the grid, then refits
the winning model unpenalized on the surviving features and
records what was dropped in selection. This applies to all three
integration strategies: before 3.3.0 only "early" did it, so a penalized
"parallel" or "serial" fit returned coefficients still shrunk towards zero.
The refit carries the tuned fit's init_omic.data.model,
init_impute, init_par, n_starts and
outcome_penalty forward, so it differs from the tuned candidate only
in its penalty and its feature set.
Two consequences worth knowing: summary(fit)$BIC is computed on the
refit's reduced dimensions and so need not equal the BIC that selected it
from the tuning table; and if no feature survives the penalty, the model is
refit on all of them and a warning is raised – selection then
records degenerate_G/degenerate_Z rather than silently
reporting that nothing was dropped.
# LUCID early integration (quick smoke example) G <- sim_data$G[1:80, , drop = FALSE] Z <- sim_data$Z[1:80, , drop = FALSE] Y <- sim_data$Y_normal[1:80] fit_early <- lucid( G = G, Z = Z, Y = Y, lucid_model = "early", family = "normal", K = 2, max_itr = 30, max_tot.itr = 60, seed = 1008 ) # LUCID in parallel (two layers) i <- 1008 set.seed(i) G <- matrix(rnorm(240), nrow = 80) Z1 <- matrix(rnorm(320), nrow = 80) Z2 <- matrix(rnorm(320), nrow = 80) Z <- list(Z1 = Z1, Z2 = Z2) CoY <- matrix(rnorm(160), nrow = 80) CoG <- matrix(rnorm(160), nrow = 80) Y <- rnorm(80) fit_parallel <- lucid( G = G, Z = Z, Y = Y, K = list(2, 2), CoG = CoG, CoY = CoY, lucid_model = "parallel", family = "normal", seed = i, max_itr = 30, max_tot.itr = 60 ) # Variable selection now works the same way for all three strategies: # tune over the penalty grid, refit unpenalized on the survivors, and # report what was dropped in the ORIGINAL feature space. A penalty that # would leave a block with fewer than 2 features is reported as a degenerate # selection and refit on the whole block, so pick one that still selects. fit_parallel_sel <- lucid( G = G, Z = Z, Y = Y, K = list(2, 2), lucid_model = "parallel", family = "normal", Rho_Z_Mu = c(0, 6), seed = i, max_itr = 30, max_tot.itr = 60 ) get_selected_Z(fit_parallel_sel) fit_parallel_sel$Rho # the penalty that was tuned fit_parallel_sel$Rho_fit # the penalty the estimates were produced under fit_serial_sel <- lucid( G = G, Z = Z, Y = Y, K = list(2, 2), lucid_model = "serial", family = "normal", Rho_Z_Mu = c(0, 6), seed = i, max_itr = 30, max_tot.itr = 60 ) get_selected_Z(fit_serial_sel)# LUCID early integration (quick smoke example) G <- sim_data$G[1:80, , drop = FALSE] Z <- sim_data$Z[1:80, , drop = FALSE] Y <- sim_data$Y_normal[1:80] fit_early <- lucid( G = G, Z = Z, Y = Y, lucid_model = "early", family = "normal", K = 2, max_itr = 30, max_tot.itr = 60, seed = 1008 ) # LUCID in parallel (two layers) i <- 1008 set.seed(i) G <- matrix(rnorm(240), nrow = 80) Z1 <- matrix(rnorm(320), nrow = 80) Z2 <- matrix(rnorm(320), nrow = 80) Z <- list(Z1 = Z1, Z2 = Z2) CoY <- matrix(rnorm(160), nrow = 80) CoG <- matrix(rnorm(160), nrow = 80) Y <- rnorm(80) fit_parallel <- lucid( G = G, Z = Z, Y = Y, K = list(2, 2), CoG = CoG, CoY = CoY, lucid_model = "parallel", family = "normal", seed = i, max_itr = 30, max_tot.itr = 60 ) # Variable selection now works the same way for all three strategies: # tune over the penalty grid, refit unpenalized on the survivors, and # report what was dropped in the ORIGINAL feature space. A penalty that # would leave a block with fewer than 2 features is reported as a degenerate # selection and refit on the whole block, so pick one that still selects. fit_parallel_sel <- lucid( G = G, Z = Z, Y = Y, K = list(2, 2), lucid_model = "parallel", family = "normal", Rho_Z_Mu = c(0, 6), seed = i, max_itr = 30, max_tot.itr = 60 ) get_selected_Z(fit_parallel_sel) fit_parallel_sel$Rho # the penalty that was tuned fit_parallel_sel$Rho_fit # the penalty the estimates were produced under fit_serial_sel <- lucid( G = G, Z = Z, Y = Y, K = list(2, 2), lucid_model = "serial", family = "normal", Rho_Z_Mu = c(0, 6), seed = i, max_itr = 30, max_tot.itr = 60 ) get_selected_Z(fit_serial_sel)
Shows which omics features distinguish the latent clusters, and in which direction, for an early, parallel or serial fit. A parallel or serial model produces one plot per omics layer, returned as a named list, so no figure has to accommodate every layer at once.
The default rendering is a cluster-by-feature heatmap in the style used for single-cell cluster markers: features on the vertical axis ordered by how strongly they separate the clusters, clusters across the top, and fill showing how high or low each cluster sits for that feature.
plot_cluster_omic_profile( x, type = c("heatmap", "bar"), top_n = 10, importance = c("separation", "range", "sd"), layer_names = NULL, layer_colors = NULL, cluster_labels = NULL, scale = TRUE )plot_cluster_omic_profile( x, type = c("heatmap", "bar"), top_n = 10, importance = c("separation", "range", "sd"), layer_names = NULL, layer_colors = NULL, cluster_labels = NULL, scale = TRUE )
x |
A fitted LUCID model: |
type |
|
top_n |
Number of features to show per panel, default 10. A layer with fewer features than this shows all of them rather than erroring. |
importance |
Ranking measure; see Which features are shown. |
layer_names |
Character vector of layer or stage names, used as plot
subtitles. Defaults to the names of the omics list the model was fitted to,
falling back to |
layer_colors |
One colour per layer. The heatmap uses it as the high end of its diverging scale, and the bar plot as the darkest of a sequential ramp across clusters – which is what lets the bar plot handle any number of clusters without recycling colours. |
cluster_labels |
Optional labels for the clusters, defaulting to
|
scale |
If |
A named list of ggplot objects, one per omics layer – length one
for an early fit. Each carries the data it drew as the attribute
"profile_data": a data frame of feature, cluster, value (what is
plotted), mean (the fitted cluster mean), sd (within-cluster standard
deviation) and score (the importance value the ranking used), so the
ranking can be extracted without recomputing it. That data frame also
carries a "centred" attribute recording whether the fill was centred
rather than z-scored, which is what happens by default at K = 2.
Only the top_n most discriminating features per panel are drawn, ranked by
importance:
"separation" (default)The spread of the cluster means divided by
the typical within-cluster spread,
. This is
the only option that accounts for noise: a feature whose cluster means
differ by two units is uninformative if its within-cluster standard
deviation is also two. It is scale-free, so features on different scales
are comparable, and it is defined the same way for any number of
clusters.
"range", in the data's own
units. The most directly interpretable, and the quantity the package's
own feature selection thresholds.
"sd"The standard deviation of the cluster means, without standardizing by within-cluster spread.
A feature the model deselected has identical means across clusters and so scores zero under all three, sorting last.
With scale = TRUE (the default) the fill is a z-score computed across
clusters within each feature, so the palette is centred at zero and a
feature's own baseline does not dominate. With scale = FALSE the fill is
the fitted cluster mean on the data's original scale.
Two clusters are a special case. A z-score over two values is always
exactly , so at K = 2 every tile would saturate and
the fill would carry the sign of the difference but nothing about its size.
When K = 2 and scale is left at its default, the fill is therefore
centred without rescaling – each cluster mean minus that feature's average
across clusters – which keeps the palette diverging while restoring
magnitude. Passing scale = TRUE explicitly overrides this and gives the
degenerate z-score. The legend always names whichever quantity was used, and
the returned data records it in the "centred" attribute.
The underlying means and within-cluster standard deviations are always available on the returned object, see Value.
# a small subset keeps the example quick G <- sim_data$G[1:150, , drop = FALSE] Z <- sim_data$Z[1:150, , drop = FALSE] Y <- sim_data$Y_normal[1:150] fit <- estimate_lucid(G = G, Z = Z, Y = Y, lucid_model = "early", family = "normal", K = 2, seed = 1008, max_itr = 20, max_tot.itr = 50) p <- plot_cluster_omic_profile(fit) p[[1]] # bar rendering, and more features plot_cluster_omic_profile(fit, type = "bar", top_n = 15)[[1]] # the ranking behind the figure head(unique(attr(p[[1]], "profile_data")[, c("feature", "score")]))# a small subset keeps the example quick G <- sim_data$G[1:150, , drop = FALSE] Z <- sim_data$Z[1:150, , drop = FALSE] Y <- sim_data$Y_normal[1:150] fit <- estimate_lucid(G = G, Z = Z, Y = Y, lucid_model = "early", family = "normal", K = 2, seed = 1008, max_itr = 20, max_tot.itr = 50) p <- plot_cluster_omic_profile(fit) p[[1]] # bar rendering, and more features plot_cluster_omic_profile(fit, type = "bar", top_n = 15)[[1]] # the ranking behind the figure head(unique(attr(p[[1]], "profile_data")[, c("feature", "score")]))
Draws the fitted model as a Sankey diagram: exposures flow into the latent clusters, and the clusters flow on into the omics features and the outcome. Each node is either a variable (exposure, omics or outcome) or a latent cluster, and its colour indicates which. Each link is an estimated association: its width is the magnitude of the effect and its colour the sign, so the diagram shows at a glance which exposures drive which cluster and how that cluster differs in the omics layer.
Only exposures and omics features retained by the model are drawn, so a penalized fit yields a correspondingly sparser diagram.
## S3 method for class 'early_lucid' plot(x, ...)## S3 method for class 'early_lucid' plot(x, ...)
x |
A LUCID model fitted by |
... |
Appearance options, all optional:
|
An HTML widget created by sankeyNetwork. It
renders when printed, in the RStudio viewer or a browser, and can be written
to a standalone file with htmlwidgets::saveWidget.
All three integration strategies have a Sankey method:
plot.lucid_parallel draws one cluster set per omics layer,
and plot.lucid_serial draws the chain of stages with their
transition coefficients. They share this method's visual language and
appearance options.
# prepare data (a small subset keeps the example quick) G <- sim_data$G[1:150, ] Z <- sim_data$Z[1:150, ] Y_normal <- sim_data$Y_normal[1:150, , drop = FALSE] # plot lucid model fit1 <- estimate_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", CoY = NULL, family = "normal", K = 2, seed = 1008, max_itr = 20, max_tot.itr = 50) plot(fit1) # change node color plot(fit1, G_color = "yellow") plot(fit1, Z_color = "red") # change link color plot(fit1, pos_link_color = "red", neg_link_color = "green")# prepare data (a small subset keeps the example quick) G <- sim_data$G[1:150, ] Z <- sim_data$Z[1:150, ] Y_normal <- sim_data$Y_normal[1:150, , drop = FALSE] # plot lucid model fit1 <- estimate_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", CoY = NULL, family = "normal", K = 2, seed = 1008, max_itr = 20, max_tot.itr = 50) plot(fit1) # change node color plot(fit1, G_color = "yellow") plot(fit1, Z_color = "red") # change link color plot(fit1, pos_link_color = "red", neg_link_color = "green")
Draws the fitted model as a Sankey diagram, in the same visual language as
plot.early_lucid: exposures flow into each omics layer's own
latent clusters, those clusters flow on into that layer's omics features,
and every layer's clusters flow into the shared outcome. Link width is the
magnitude of the estimated association and link colour its sign.
Because a parallel model has one latent variable per layer, cluster nodes
are labelled with their layer – the layer's own name when Z is a
named list, otherwise "Layer 1", "Layer 2", ... – and an
omics feature name that occurs in more than one layer is prefixed with its
layer so the two stay distinct nodes.
## S3 method for class 'lucid_parallel' plot(x, ...)## S3 method for class 'lucid_parallel' plot(x, ...)
x |
A LUCID model fitted with |
... |
Appearance options; see |
An HTML widget created by sankeyNetwork.
G <- sim_data$G[1:150, ] Z <- list(sim_data$Z[1:150, 1:5], sim_data$Z[1:150, 6:10]) Y <- sim_data$Y_normal[1:150, , drop = FALSE] fit <- estimate_lucid(G = G, Z = Z, Y = Y, lucid_model = "parallel", family = "normal", K = c(2, 2), seed = 1008, max_itr = 20, max_tot.itr = 50) plot(fit)G <- sim_data$G[1:150, ] Z <- list(sim_data$Z[1:150, 1:5], sim_data$Z[1:150, 6:10]) Y <- sim_data$Y_normal[1:150, , drop = FALSE] fit <- estimate_lucid(G = G, Z = Z, Y = Y, lucid_model = "parallel", family = "normal", K = c(2, 2), seed = 1008, max_itr = 20, max_tot.itr = 50) plot(fit)
Draws the fitted model as a Sankey diagram in the same visual language as
plot.early_lucid, following the serial chain left to right:
exposures flow into stage 1's latent clusters, each stage's clusters flow
into the next stage's clusters (the transition coefficients), and the final
stage's clusters flow into the outcome.
By default the omics features are not drawn, so the figure is the
pathway alone – which is what a serial model exists to express. That is
deliberate; see the section below for why a serial chain cannot simply draw
them alongside. The omics arm is available through the omics
argument, or per feature and per stage through
plot_cluster_omic_profile.
A stage that is itself a parallel sub-model contributes one cluster node set per layer, and (in the modes that draw omics) a feature name occurring in more than one stage is prefixed with its stage so the two stay distinct.
## S3 method for class 'lucid_serial' plot(x, ...)## S3 method for class 'lucid_serial' plot(x, ...)
x |
A LUCID model fitted with |
... |
Appearance options; see |
An HTML widget created by sankeyNetwork.
A Sankey assigns each node a column from the longest path into it, and that
is not something networkD3 lets a caller override (it exposes no
nodeAlign/nodeDepth argument and drops any extra
Nodes column). For a serial chain this collides: stage 's
omics features sit at the same depth as stage 's clusters, so on
a six-stage fit five of eight columns mixed omics leaves with the next
stage's cluster nodes. The omics argument decides how to avoid that:
"none"The default. Draw the chain only:
, one kind of node per
column. The omics arm is left to
plot_cluster_omic_profile, which returns one panel per
stage for a serial fit and ranks each stage's features by how strongly
they separate its clusters.
"aggregate"One omics node per stage (per stage and
layer when the stage is a parallel sub-model), labelled with its feature
count, and all of them pushed into a terminal column, so the chain's
columns still hold clusters only. The link to an aggregate node carries,
for each cluster, that cluster's largest mean in absolute
value, keeping its sign: the width is the strongest separation the block
offers and the colour is that feature's direction. It is a derived
summary, not a coefficient, and matches the "separation" notion
plot_cluster_omic_profile ranks features by.
"features"Every feature keeps its own node, also pushed into a terminal column, so nothing is aggregated or dropped. No column mixes kinds, but the terminal column is as tall as the total feature count (37 nodes on the six-stage example).
"per_stage"Every feature hanging off its own stage, as in the first release that could draw a serial diagram at all. Kept reachable, but note that this is the mode whose columns mix clusters with the previous stage's omics.
Serial figures also default to link_scale = "within_block", where the
other methods default to "raw". A serial model's cluster-to-cluster
transition coefficients regress on a posterior probability confined to
, so on one shared width scale they run tens of times wider
than any exposure or outcome effect – 73x on this package's own example
data – and flatten the rest of the chain to hairlines. Pass
link_scale = "raw" to see the unscaled widths, and the warning that
explains them.
plot_cluster_omic_profile for the omics-by-cluster
view, which omics = "none" defers to.
G <- sim_data$G[1:150, ] Z <- list(sim_data$Z[1:150, 1:5], sim_data$Z[1:150, 6:10]) Y <- sim_data$Y_normal[1:150, , drop = FALSE] fit <- estimate_lucid(G = G, Z = Z, Y = Y, lucid_model = "serial", family = "normal", K = list(2, 2), seed = 1008, max_itr = 20, max_tot.itr = 50) plot(fit) # bring the omics arm into the figure: one node per stage, or every feature plot(fit, omics = "aggregate") plot(fit, omics = "features") # unscaled link widths (warns: the transitions dwarf the other blocks) plot(fit, link_scale = "raw")G <- sim_data$G[1:150, ] Z <- list(sim_data$Z[1:150, 1:5], sim_data$Z[1:150, 6:10]) Y <- sim_data$Y_normal[1:150, , drop = FALSE] fit <- estimate_lucid(G = G, Z = Z, Y = Y, lucid_model = "serial", family = "normal", K = list(2, 2), seed = 1008, max_itr = 20, max_tot.itr = 50) plot(fit) # bring the omics arm into the figure: one node per stage, or every feature plot(fit, omics = "aggregate") plot(fit, omics = "features") # unscaled link widths (warns: the transitions dwarf the other blocks) plot(fit, link_scale = "raw")
Predict cluster assignment and outcome using new data on G, Z, and optional Y.
If g_computation = TRUE, prediction uses only the G-to-X path from the
fitted model and returns counterfactual-style predictions under modified G.
This function can also be used to extract latent cluster assignments when using
the training data as input.
predict_lucid( model, lucid_model = NULL, G, Z = NULL, Y = NULL, CoG = NULL, CoY = NULL, response = TRUE, g_computation = FALSE, verbose = FALSE )predict_lucid( model, lucid_model = NULL, G, Z = NULL, Y = NULL, CoG = NULL, CoY = NULL, response = TRUE, g_computation = FALSE, verbose = FALSE )
model |
A model fitted and returned by |
lucid_model |
Optional; "early", "parallel", or "serial". Auto-detected
from |
G |
Exposures, a numeric vector, matrix, or data frame. Categorical variable should be transformed into dummy variables. If a matrix or data frame, rows represent observations and columns correspond to variables. |
Z |
Omics data, and required for every model type unless
The requirement is not arbitrary: the E-step forms the posterior from the
omics likelihood, so with no |
Y |
Outcome, a numeric vector. Categorical variable is not allowed. Binary outcome should be coded as 0 and 1. |
CoG |
Optional, covariates to be adjusted for estimating the latent cluster. A numeric vector, matrix or data frame. Categorical variable should be transformed into dummy variables. |
CoY |
Optional, covariates to be adjusted for estimating the association between latent cluster and the outcome. A numeric vector, matrix or data frame. Categorical variable should be transformed into dummy variables. |
response |
If |
g_computation |
If |
verbose |
A flag indicates whether detailed information is printed in console. Default is FALSE. Applies consistently to all three model types (early, parallel, serial). |
A list containing:
inclusion.p |
Posterior inclusion probabilities for latent clusters (a
matrix for "early"; a list by layer for "parallel" and "serial"). Columns are
ordered by cluster, matching the row order of the model's |
pred.x |
Predicted latent-cluster labels (a numeric vector for "early";
a list by layer for "parallel" and "serial"), obtained as the maximum a
posteriori column of |
pred.y |
Predicted outcome values. For binary outcomes, this is class
labels when |
pred.z |
Predicted omics means under g-computation mode
( |
Supplying Y makes the cluster prediction supervised: the outcome
enters the posterior alongside G and Z, as it does during fitting. Omitting
it predicts clusters from G and Z alone, which is what is wanted when the
outcome is unavailable or must not inform the assignment.
# prepare data (a small subset keeps the example quick) G <- sim_data$G[1:150, ] Z <- sim_data$Z[1:150, ] Y_normal <- sim_data$Y_normal[1:150, , drop = FALSE] # fit lucid model fit1 <- estimate_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", K = 2, family = "normal", max_itr = 20, max_tot.itr = 50) # prediction on training set (lucid_model is auto-detected from fit1's class) pred1 <- predict_lucid(model = fit1, G = G, Z = Z, Y = Y_normal) pred2 <- predict_lucid(model = fit1, G = G, Z = Z) # g-computation style prediction using only G pred_g <- predict_lucid(model = fit1, G = G, Z = NULL, g_computation = TRUE)# prepare data (a small subset keeps the example quick) G <- sim_data$G[1:150, ] Z <- sim_data$Z[1:150, ] Y_normal <- sim_data$Y_normal[1:150, , drop = FALSE] # fit lucid model fit1 <- estimate_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", K = 2, family = "normal", max_itr = 20, max_tot.itr = 50) # prediction on training set (lucid_model is auto-detected from fit1's class) pred1 <- predict_lucid(model = fit1, G = G, Z = Z, Y = Y_normal) pred2 <- predict_lucid(model = fit1, G = G, Z = Z) # g-computation style prediction using only G pred_g <- predict_lucid(model = fit1, G = G, Z = NULL, g_computation = TRUE)
Print the output of LUCID in a nicer table
## S3 method for class 'sumlucid_early' print(x, ...)## S3 method for class 'sumlucid_early' print(x, ...)
x |
An object returned by |
... |
Other parameters to be passed to |
Prints a structured model summary, including model specification, missing-data
profile, feature-selection overview, model fit statistics, regularization settings,
and detailed parameter estimates. If boot.se is provided in summary(),
bootstrap CI tables are shown for sections (1) Y, (2) Z, and (3) E.
# use simulated data (a small subset keeps the example quick) G <- sim_data$G[1:150, , drop = FALSE] Z <- sim_data$Z[1:150, , drop = FALSE] Y_normal <- sim_data$Y_normal[1:150] # fit lucid model fit1 <- estimate_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", family = "normal", K = 2, seed = 1008, max_itr = 20, max_tot.itr = 50) # conduct bootstrap resampling boot1 <- suppressWarnings( boot_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", model = fit1, R = 2) ) # print the summary of the lucid model in a table temp <- summary(fit1) print(temp)# use simulated data (a small subset keeps the example quick) G <- sim_data$G[1:150, , drop = FALSE] Z <- sim_data$Z[1:150, , drop = FALSE] Y_normal <- sim_data$Y_normal[1:150] # fit lucid model fit1 <- estimate_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", family = "normal", K = 2, seed = 1008, max_itr = 20, max_tot.itr = 50) # conduct bootstrap resampling boot1 <- suppressWarnings( boot_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", model = fit1, R = 2) ) # print the summary of the lucid model in a table temp <- summary(fit1) print(temp)
Print the output of LUCID in a nicer table
## S3 method for class 'sumlucid_parallel' print(x, ...)## S3 method for class 'sumlucid_parallel' print(x, ...)
x |
An object returned by |
... |
Other parameters to be passed to |
x, invisibly. Called for its side effect: printing a structured
parallel-model summary – per-layer missing-data profile, overall and
per-layer feature-selection overview, model fit statistics, regularization
settings, and parameter estimates for sections (1) Y, (2) Z and (3) E. If
boot.se was provided to summary(), bootstrap confidence limits
are shown for each of those three sections.
Print the output of LUCID in a nicer table
## S3 method for class 'sumlucid_serial' print(x, ...)## S3 method for class 'sumlucid_serial' print(x, ...)
x |
An object returned by |
... |
Other parameters to be passed to |
x, invisibly. Called for its side effect: printing the serial
model's summary stage by stage – per-stage missing-data profile,
feature-selection overview, model fit statistics and parameter estimates,
with the outcome section attached to the final stage. If boot.se was
supplied to summary(), bootstrap confidence limits are shown
alongside the estimates.
Fills missing entries feature by feature with a single summary of that feature's observed values.
This is a user-facing utility, not part of LUCID's own fitting
path: estimate_lucid() initializes missing omics values itself from
the init_impute argument ("lod", an internal
limit-of-detection fill, or "mix", via mclust::imputeData)
and then re-imputes them inside the EM loop under the fitted cluster model.
Nothing in the package calls safe_impute(). Use it to pre-fill omics
data before handing it to another tool, to prepare a mean-imputation
comparator, or to rescue a feature with nothing observed – which
estimate_lucid() now rejects outright, since no cluster mean or
covariance can be estimated for it.
Unlike a bare mean(x, na.rm = TRUE), a feature with no observed
value does not yield NaN: it falls back to the mean over the whole
matrix and warns. Note that this fallback uses the mean whichever
method was requested, since a median or limit of detection is not
defined for a feature with nothing observed.
safe_impute(Z, method = c("mean", "median", "lod"))safe_impute(Z, method = c("mean", "median", "lod"))
Z |
A numeric matrix with missing values coded |
method |
The summary used to fill a feature:
|
A matrix of the same dimensions as Z with no missing values,
unless every value of Z is missing, in which case Z is
returned unchanged with a warning.
check_imputation_quality to check the result, and the
init_impute argument of estimate_lucid for the
imputation LUCID applies internally.
Z <- matrix(rnorm(100), nrow = 10) Z[2:4, 2] <- NA colMeans(is.na(safe_impute(Z, method = "median")))Z <- matrix(rnorm(100), nrow = 10) Z[2:4, 2] <- NA colMeans(is.na(safe_impute(Z, method = "median")))
An example dataset used to illustrate the LUCID model, simulated
under two latent clusters. The exposures are associated with the latent
cluster, which in turn affects PFAS concentration and liver injury in
children; the clusters are also characterised by differential metabolite
levels. Because the generating cluster membership is retained in X, the
data can be used to check recovered clusters against the truth, up to the
arbitrary labelling of clusters.
sim_datasim_data
A list of 6 elements, each with 2000 observations:
A 2000 by 10 matrix of exposures.
A 2000 by 10 matrix of metabolites.
A 2000 by 1 matrix; continuous outcome, PFAS concentration in children.
A 2000 by 1 matrix; binary outcome, liver injury status, coded 0 and 1.
A 2000 by 2 matrix of continuous covariates, usable as
either CoG or CoY.
An integer vector of length 2000 giving the latent cluster each observation was generated from.
The Human Early-Life Exposome (HELIX) project is a multi-center research project that aims to characterize early-life environmental exposures and associate these with omics biomarkers and child health outcomes (Vrijheid, 2014. doi: 10.1289/ehp.1307204). This is a simulated subset of the HELIX data released for the Exposome Data Challenge 2021 (held by ISGlobal), used to illustrate the LUCID model on three omics layers.
The three omics layers share the same 420 subjects in the same row order, so
they can be passed together as the Z list of a parallel or serial fit,
or used one at a time for early integration.
simulated_HELIX_datasimulated_HELIX_data
A list of 4 elements, each with 420 observations:
A 420 by 6 data frame holding the exposure, the outcome
and the covariates: id; hs_hg_m_scaled, the scaled
maternal exposure to in-utero mercury, used as G;
ck18_scaled, a scaled continuous indicator of
metabolic-dysfunction-associated fatty liver disease (MAFLD), used as
Y; and the covariates hs_child_age_yrs_None,
e3_sex_None and h_fish_preg_Ter.
A 420 by 10 matrix of methylomics features.
A 420 by 10 matrix of transcriptomics features.
A 420 by 10 matrix of miRNA features.
Assembles the reported quantities for a fitted LUCID model and, by default,
prints them. The same components are returned invisibly as a list of class
sumlucid_early, so they can be extracted programmatically rather than
parsed from the printed output.
Two conventions are worth noting when reading the output. Outcome effects are printed as an intercept – cluster 1's level – followed by explicit contrasts of each remaining cluster against it, so the second row is a between-cluster difference and not that cluster's own mean. And the parameter tables are restricted to the features the model retained, so their dimensions match the fit rather than the original input.
summary_lucid(object, ...) ## S3 method for class 'early_lucid' summary(object, ...)summary_lucid(object, ...) ## S3 method for class 'early_lucid' summary(object, ...)
object |
A LUCID model fitted by |
... |
Additional arguments. |
A list of class sumlucid_early with components:
The Bayesian information criterion and the
observed-data log-likelihood at the estimates. Also repeated inside
model_fit, alongside n_parameters, the effective
parameter count the BIC charges (Eq 13, reduced per Eq 18 when a
penalty deselected variables).
The outcome family, the number of clusters
K, n_observations, and n_features, which counts
retained exposures and omics features.
Which exposures and omics features survived, and
how many were dropped. On a lucid fit made with a
penalty, see get_selected_G/get_selected_Z
for the same information in the original feature space.
The penalties in force, Rho_G,
Rho_Z_Mu and Rho_Z_Cov.
Estimates restricted to the retained features:
beta (exposure-to-cluster, intercept column always kept along
with any covariate columns), mu (cluster-specific omics means)
and gamma (cluster-to-outcome, in both absolute and
reference-coded form).
The fit's missing_summary; see
estimate_lucid.
The boot.se argument as supplied, or NULL.
When boot.se is supplied, every printed CI table (G-to-X,
cluster-to-Y, and cluster-specific omics means) carries:
estimate (or gamma/Gamma) – the
supplied model's own coefficient, the same number this function
prints without boot.se;
norm_lower/norm_upper – the normal-theory limits.
These are bias-corrected (boot::norm.ci centres them
on ), so they need not bracket estimate;
that is the method, not an inconsistency, and a note above the tables
says so along with the confidence level used;
sig – "*" where the interval excludes 0,
"" where it does not, and "NA" where no interval could
be formed at all (too few finite replicates for that parameter). The
last case used to print as "", indistinguishable from
"tested, not significant";
OR, OR_lower, OR_upper on the log-odds
tables – the elementwise exp() of the coefficient columns.
sig is always assessed on the coefficient scale (null = 0).
Note the intercept row's exp() is a baseline odds, not
an odds ratio.
The percentile limits are computed but not printed (sig is
determined from the normal interval alone); they remain on the
boot_lucid object.
BIC is (Eq 13), with D reduced
by one per variable the penalty deselected (Eq 18). Four caveats matter when
comparing BIC values:
Covariance geometry. The covariance contribution is
charged as , the unconstrained count,
regardless of the mclust geometry actually fitted
(init_omic.data.model, by default selected by BIC, usually has
fewer free parameters – 25 rather than 30 at for
"EEV", and 1 for "EII"). This inflates BIC, biases K selection towards
smaller K, and within one penalty grid favours penalized
candidates, which really do estimate unstructured/glasso covariances.
The default is kept so previously reported values reproduce; set
options(LUCIDus.geometry_df = TRUE) or pass
geometry_df = TRUE for the geometry-aware count (it is applied
only to unpenalized fits, where the covariance really did come from
mclust).
Rho_Z_Cov earns no credit. Selection is driven by
the cluster means, so zeroing off-diagonal precision entries reduces the
log-likelihood without reducing D. Tuning Rho_Z_Cov
alone can therefore only raise BIC, and Rho_Z_Cov = 0 wins
almost mechanically.
Eq 18 undercounts sparsity. Deselecting one exposure
actually zeroes coefficients and one omics feature zeroes
means plus a covariance row and column; Eq 18 subtracts 1. This
is fidelity to the paper, not an oversight, but it means penalized fits
are charged nearly the full count.
Not comparable across lucid_model. An early fit
estimates one residual SD per cluster where a parallel fit estimates
one, and a serial BIC is the sum of its stages' own BICs, paying
once per stage. Compare BIC within an integration
strategy, not across them. For a lucid fit made with a
penalty, this BIC is also computed on the refit's reduced dimensions and
so need not equal the BIC in tune_lucid's table
that selected it.
boot_lucid for the confidence limits, and
predict_lucid for cluster and outcome prediction.
# use simulated data (a small subset keeps the example quick) G <- sim_data$G[1:150, , drop = FALSE] Z <- sim_data$Z[1:150, , drop = FALSE] Y_normal <- sim_data$Y_normal[1:150] # fit lucid model fit1 <- estimate_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", family = "normal", K = 2, seed = 1008, max_itr = 20, max_tot.itr = 50) # conduct bootstrap resampling boot1 <- suppressWarnings( boot_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", model = fit1, R = 3) ) # summarize lucid model summary(fit1) # summarize lucid model with bootstrap CIs summary(fit1, boot.se = boot1)# use simulated data (a small subset keeps the example quick) G <- sim_data$G[1:150, , drop = FALSE] Z <- sim_data$Z[1:150, , drop = FALSE] Y_normal <- sim_data$Y_normal[1:150] # fit lucid model fit1 <- estimate_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", family = "normal", K = 2, seed = 1008, max_itr = 20, max_tot.itr = 50) # conduct bootstrap resampling boot1 <- suppressWarnings( boot_lucid(G = G, Z = Z, Y = Y_normal, lucid_model = "early", model = fit1, R = 3) ) # summarize lucid model summary(fit1) # summarize lucid model with bootstrap CIs summary(fit1, boot.se = boot1)
Summarize results of the parallel LUCID model
## S3 method for class 'lucid_parallel' summary(object, ...)## S3 method for class 'lucid_parallel' summary(object, ...)
object |
A LUCID model fitted by |
... |
Additional argument |
A list of class sumlucid_parallel, with the same components as
the early-model summary (see summary_lucid) but resolved per
omics layer: feature_selection reports both the overall retained set
and the per-layer sets, parameters holds mu by layer and
beta by layer alongside the single gamma, and
missing_data is a list by layer. BIC and loglik remain
scalars for the joint model. Returned invisibly when printed.
Summarize results of the serial LUCID model
## S3 method for class 'lucid_serial' summary(object, ...)## S3 method for class 'lucid_serial' summary(object, ...)
object |
A LUCID model fitted by |
... |
Additional arguments. |
A list of class sumlucid_serial with components:
Assembled over the whole serial model, and repeated
inside model_fit.
The outcome family, n_observations,
n_stages, stage_type (whether each stage is an "early" or
a "parallel" sub-model) and stage_K, the clusters per stage.
The penalties in force, or NULL if none.
n_stages and a per-stage breakdown.
The heart of the object: one summary per stage, each with the same shape as the corresponding early or parallel summary. Outcome parameters appear on the final stage, the only one the outcome enters.
How consecutive stages connect: labels names the
previous stage's clusters as they enter the next stage's design, and
prev_stage_type records that stage's type. The first element is
empty, the first stage having no predecessor.
The boot.se argument as supplied, or NULL.
A legacy alias of stage_summary, retained for
downstream code written before the rename. Prefer
stage_summary.
Returned invisibly when printed.
Fit a grid of LUCID models over candidate numbers of latent
clusters K and (optionally) L1 penalties Rho_G,
Rho_Z_Mu, and Rho_Z_Cov. The input format for K differs
by lucid_model. For "early", use an integer vector (for example,
2:4). For "parallel", use a list of vectors/integers, one per layer
(for example, list(2:3, 2:3, 2)). For "serial", use a nested list as
required by the serial model.
tune_lucid( G, Z, Y, CoG = NULL, CoY = NULL, family = c("normal", "binary"), K, lucid_model = c("early", "parallel", "serial"), Rho_G = 0, Rho_Z_Mu = 0, Rho_Z_Cov = 0, verbose_tune = FALSE, parallel = c("no", "multicore", "snow"), ncpus = 1L, cl = NULL, ... )tune_lucid( G, Z, Y, CoG = NULL, CoY = NULL, family = c("normal", "binary"), K, lucid_model = c("early", "parallel", "serial"), Rho_G = 0, Rho_Z_Mu = 0, Rho_Z_Cov = 0, verbose_tune = FALSE, parallel = c("no", "multicore", "snow"), ncpus = 1L, cl = NULL, ... )
G |
Exposures, a numeric vector, matrix, or data frame. Categorical variables should be transformed into dummy variables. |
Z |
Omics data. If "early", an N by M matrix. If "parallel", a list of matrices (same N). If "serial", a list matching the serial model structure. |
Y |
Outcome, a numeric vector. Binary outcomes should be coded as 0/1. |
CoG |
Optional covariates for the G-to-X model. |
CoY |
Optional covariates for the X-to-Y model. |
family |
Outcome family: "normal" or "binary". |
K |
Candidate latent-cluster values in model-specific format. |
lucid_model |
LUCID model type: "early", "parallel", or "serial". |
Rho_G |
Scalar or vector penalty for exposure coefficients in the
G-to-X model. |
Rho_Z_Mu |
Scalar or vector penalty for cluster-specific Z means. Vector tuning is supported for all three integration strategies; for "serial" it applies to every stage. |
Rho_Z_Cov |
Scalar or vector penalty for cluster-specific Z covariance
matrices. Vector tuning is supported for all three integration strategies;
for "serial" it applies to every stage. Note that |
verbose_tune |
Logical; print tuning progress if |
parallel |
How to fit the grid points: |
ncpus |
Number of workers when |
cl |
Optional |
... |
Additional arguments passed to |
A list holding the tuning table, every fitted candidate, and the
selected model. The element names differ by lucid_model:
"early": tune_list, res_model, best_model
"parallel" and "serial": tune_K, model_list,
model_opt
The tuning table has one row per grid point, in the order the candidates were
fitted, and the fitted-model list is aligned with it by position. Its columns
are the grid coordinates – K (one column per layer for "parallel";
a list column holding each candidate's per-stage K for "serial")
together with Rho_G, Rho_Z_Mu and Rho_Z_Cov –
followed by BIC.
Selection is on BIC, minimised over the rows. For "early" and
"parallel" this is the penalized BIC of Eq 18: the full parameter count is
reduced by one for each variable deselected by the penalty, so a sparser fit
is not charged for coefficients it has driven to zero. For "serial" it is
the sum of the stages' own BICs (Eq 26 treats the stages as independent
sub-models), so is charged once per stage. Penalties are
tuned for every strategy, "serial" included, as of 3.3.0 – a serial grid
crosses the K candidates with the penalty combinations, and
Rho_G applies to stage 1 only, since a later stage's "G" is the
previous stage's cluster probabilities rather than an exposure. A candidate
whose EM algorithm failed records NA and is skipped; if every
candidate fails, an error is raised rather than a model returned, and it
distinguishes a structural data problem from non-convergence. Ties are
broken by taking the first minimising row.
Note that the returned optimum is the penalized fit itself. It is
lucid, not this function, that refits the selected variables
without a penalty and records $selection – so estimates taken
straight from best_model or model_opt here are shrunk
towards zero. Because that refit is on the reduced feature set, the BIC
summary() reports for a lucid fit need not equal the
BIC in this table that selected it.
The covariance contribution to BIC is charged as
– the unconstrained count – regardless of
the mclust geometry named by init_omic.data.model – which
is BIC-selected by default and usually has fewer free parameters. The default is kept for
reproducibility of previously reported values; set
options(LUCIDus.geometry_df = TRUE), or pass
summary(fit, geometry_df = TRUE), for the geometry-aware count. See
summary_lucid for the full list of caveats.
Rho_Z_Cov earns no degrees-of-freedom credit, and that is Eq 18's own
definition rather than an omission: the penalized BIC is
, one credit per deselected variable, never per
zeroed covariance entry. Crediting graphical-lasso sparsity would be an
extension beyond the paper and would change which candidate is selected, so
it is held in place by a test (see
tests/testthat/test-paper-equations-oracle.R). BIC is also not
comparable across lucid_model; summary() prints the basis of
the number it reports.
## Not run: G <- sim_data$G Z <- sim_data$Z Y <- sim_data$Y_normal tune_early <- tune_lucid(G = G, Z = Z, Y = Y, lucid_model = "early", K = 2:3) tune_rho <- tune_lucid( G = G, Z = Z, Y = Y, lucid_model = "early", K = 2, Rho_G = c(0, 0.1), Rho_Z_Mu = c(0, 5), Rho_Z_Cov = c(0, 0.1) ) # parallel and serial tune over penalties too, and their tables carry the # Rho_* columns Zp <- list(sim_data$Z[, 1:5], sim_data$Z[, 6:10]) tune_par <- tune_lucid(G = G, Z = Zp, Y = Y, lucid_model = "parallel", K = list(2, 2), Rho_Z_Mu = c(0, 20)) tune_ser <- tune_lucid(G = G, Z = Zp, Y = Y, lucid_model = "serial", K = list(2, 2), Rho_Z_Mu = c(0, 20)) tune_ser$tune_K ## End(Not run)## Not run: G <- sim_data$G Z <- sim_data$Z Y <- sim_data$Y_normal tune_early <- tune_lucid(G = G, Z = Z, Y = Y, lucid_model = "early", K = 2:3) tune_rho <- tune_lucid( G = G, Z = Z, Y = Y, lucid_model = "early", K = 2, Rho_G = c(0, 0.1), Rho_Z_Mu = c(0, 5), Rho_Z_Cov = c(0, 0.1) ) # parallel and serial tune over penalties too, and their tables carry the # Rho_* columns Zp <- list(sim_data$Z[, 1:5], sim_data$Z[, 6:10]) tune_par <- tune_lucid(G = G, Z = Zp, Y = Y, lucid_model = "parallel", K = list(2, 2), Rho_Z_Mu = c(0, 20)) tune_ser <- tune_lucid(G = G, Z = Zp, Y = Y, lucid_model = "serial", K = list(2, 2), Rho_Z_Mu = c(0, 20)) tune_ser$tune_K ## End(Not run)