LUCID (Latent Unknown Clusters by Integrating multi-omics Data) finds
latent subgroups of subjects that are simultaneously (1) predictable
from a set of exposures G, (2) characterized by distinct
omics profiles Z, and (3) associated with a health outcome
Y. This document is a comprehensive, user-facing tour of
the package’s public API: everything a user needs to
fit, tune, summarize, predict from, bootstrap, and visualize a LUCID
model, worked through end to end on a small simulated dataset. It
intentionally does not describe internal implementation details – only
functions you are meant to call directly.
It covers:
estimate_lucid(),
tune_lucid(), lucid()summary(), predict_lucid()
(including g_computation mode), boot_lucid(),
plot(), plot_cluster_omic_profile()get_selected_G(), get_selected_Z(),
get_cluster_assignment(),
get_top_omics_features()check_na(),
analyze_missing_pattern(), safe_impute(),
check_imputation_quality()Two things intentionally stay out of view. First, several internal EM
building blocks (a low-level data-filling routine, and a handful of
numerical-stability safeguards for the optimizer) support the functions
above but are not exported and are not part of the API this guide
teaches; section 7 explains what they do for you conceptually where it
matters. Second, this is a breadth guide – runtime is kept
small throughout so the whole document fits together as one example.
Section 3-model tutorials
(lucid_3models_normal_outcome.Rmd,
lucid_3models_binary_outcome.Rmd) go deeper on each
architecture, including the two-step penalized-screen-then- refit
workflow used for real feature selection.
| Functionality | Main API |
|---|---|
| Fit early/parallel/serial model directly | estimate_lucid() |
Grid search for K and penalties |
tune_lucid() |
| One-step wrapper (fit or tune+fit) | lucid() |
| Structured model summary | summary() |
| Prediction and cluster assignment on new/held-out data | predict_lucid() |
| Bootstrap CI inference | boot_lucid() |
| Sankey-style path visualization | plot() |
| Per-cluster omics profile visualization | plot_cluster_omic_profile() |
| Extract selected exposures / omics features from a fit | get_selected_G(), get_selected_Z() |
| Extract hard cluster assignment from a fit | get_cluster_assignment() |
| Extract top-N most important omics features from a fit | get_top_omics_features() |
| Missingness diagnostics | check_na(), analyze_missing_pattern() |
| Robust imputation helpers | safe_impute(),
check_imputation_quality() |
The four get_*() extractors share one design point worth
calling out up front: every one of them takes only the fitted model
object and figures out on its own whether it is looking at an early,
parallel, or serial fit. You never pass a lucid_model
argument to them, and (since this release) predict_lucid()
and boot_lucid() no longer require one either – they detect
it from class(model). The only place you still name the
model type explicitly is when fitting one, since that is the
argument that decides which architecture gets fit in the first
place.
A LUCID model only has something interesting to find if
G, the latent cluster, Z, and Y
are actually related – fitting it to independent noise would produce
arbitrary clusters and make every example below meaningless. This
simulation deliberately wires in that structure: a subset of exposures
in G drive a binary latent state x,
x in turn shifts each omics layer’s means apart (so the
layers actually separate by cluster) and shifts the outcome
Y. That known ground truth is also what lets the fitted
models’ recovered clusters and selected features be checked for sanity
throughout this document.
make_demo_data <- function(n = 80, pG = 6, pZ = 4, seed = 20260309) {
set.seed(seed)
# Exposures
G <- matrix(rnorm(n * pG), nrow = n, ncol = pG)
colnames(G) <- paste0("G", seq_len(pG))
# Covariates associated with exposures
CoG <- cbind(
cov_g1 = G[, 1] + 0.2 * G[, 2] + rnorm(n, sd = 0.2),
cov_g2 = -0.3 * G[, 3] + 0.4 * G[, 4] + rnorm(n, sd = 0.25)
)
CoY <- CoG
# Latent cluster driver
lin <- 1.0 * G[, 1] - 0.8 * G[, 2] + 0.4 * CoG[, 1]
prob_x <- plogis(lin)
x <- rbinom(n, size = 1, prob = prob_x)
# Layer 1 and 2 for parallel stage
Z1 <- cbind(
1.2 * x + 0.5 * G[, 1] + rnorm(n, sd = 0.5),
1.0 * x - 0.4 * G[, 2] + rnorm(n, sd = 0.5),
0.8 * x + 0.3 * G[, 3] + rnorm(n, sd = 0.5),
0.6 * x + 0.2 * G[, 4] + rnorm(n, sd = 0.5)
)
Z2 <- cbind(
-1.1 * x + 0.45 * G[, 2] + rnorm(n, sd = 0.5),
-0.9 * x - 0.35 * G[, 1] + rnorm(n, sd = 0.5),
-0.7 * x + 0.25 * G[, 5] + rnorm(n, sd = 0.5),
-0.5 * x + 0.20 * G[, 6] + rnorm(n, sd = 0.5)
)
# Layer 3 for serial second stage (early stage)
Z3 <- cbind(
0.9 * x + 0.30 * G[, 1] + rnorm(n, sd = 0.55),
0.7 * x - 0.25 * G[, 3] + rnorm(n, sd = 0.55),
-0.8 * x + 0.20 * G[, 4] + rnorm(n, sd = 0.55),
-0.6 * x + 0.15 * G[, 6] + rnorm(n, sd = 0.55)
)
colnames(Z1) <- paste0("Z1_f", seq_len(pZ))
colnames(Z2) <- paste0("Z2_f", seq_len(pZ))
colnames(Z3) <- paste0("Z3_f", seq_len(pZ))
# Outcomes
Y_normal <- 1.1 * x + 0.5 * G[, 1] - 0.25 * G[, 3] + 0.35 * CoY[, 2] + rnorm(n, sd = 0.7)
Y_binary <- rbinom(n, size = 1, prob = plogis(-0.2 + 1.0 * x + 0.35 * G[, 1] - 0.2 * CoY[, 1]))
# Structures for each model
Z_parallel <- list(layer1 = Z1, layer2 = Z2)
Z_early <- cbind(Z1, Z2)
Z_serial_mixed <- list(list(layer1 = Z1, layer2 = Z2), Z3)
list(
G = G,
CoG = CoG,
CoY = CoY,
Y_normal = as.numeric(Y_normal),
Y_binary = as.numeric(Y_binary),
Z1 = Z1,
Z2 = Z2,
Z3 = Z3,
Z_parallel = Z_parallel,
Z_early = Z_early,
Z_serial_mixed = Z_serial_mixed
)
}
d <- make_demo_data()The three Z_* structures at the bottom –
Z_early (one concatenated matrix), Z_parallel
(a named list of layer matrices), Z_serial_mixed (a list
whose first element is itself a parallel-style list) – are exactly the
three shapes estimate_lucid() expects for early, parallel,
and serial fitting respectively. Building all three up front from the
same underlying Z1/Z2/Z3 layers
means every model type below is fit on data that differ only in how the
layers are packaged, not in what they contain.
Multi-omics studies rarely have complete data: whole layers can be missing for a subject (e.g. a blood sample was never collected – “listwise” missingness within that layer), or a handful of individual features can be missing sporadically. LUCID’s EM fitting handles both patterns natively – the missing-data helpers in section 6 exist to let you check that handling, not to do it manually. This chunk injects both patterns into copies of the data built above, purely so the diagnostics in section 6 have something to report on.
# Early matrix missingness
Z_early_miss <- d$Z_early
Z_early_miss[1, ] <- NA # listwise
Z_early_miss[2:4, 1] <- NA # sporadic block
Z_early_miss[5, 3] <- NA # sporadic cell
# Parallel list missingness
Z_parallel_miss <- d$Z_parallel
Z_parallel_miss[[1]][1, ] <- NA # listwise on layer1
Z_parallel_miss[[2]][2, 2] <- NA # sporadic on layer2
# Serial mixed missingness (stage1 parallel + stage2 early)
Z_serial_miss <- list(
list(
layer1 = Z_parallel_miss[[1]],
layer2 = Z_parallel_miss[[2]]
),
{tmp <- d$Z3; tmp[3, ] <- NA; tmp}
)estimate_lucid() imputes missing omics values
internally, conditional on the current model fit, as part of its EM loop
– there is no separate “impute first, then fit” step for you to run.
What the two functions below give you is visibility into that
process: whether the missingness pattern looks the way you expect, and
whether a quick standalone imputation of the same data is directionally
sane.
analyze_missing_pattern() and
check_na()analyze_missing_pattern() reports how much data is
missing and how it is distributed; check_na() additionally
classifies, per subject and per omics layer, which missingness pattern
applies (fully observed, listwise missing, or sporadically missing) –
the same three-way classification the EM loop itself uses internally to
decide how to handle each subject.
miss_info_early <- analyze_missing_pattern(Z_early_miss)
na_early <- check_na(Z_early_miss, lucid_model = "early")
na_parallel <- check_na(Z_parallel_miss, lucid_model = "parallel")
miss_info_early$total_missing## [1] 0.01875
##
## 1 2 3
## 75 4 1
## $n_layers
## [1] 2
##
## $n_observations
## [1] 80
##
## $features_per_layer
## layer1 layer2
## 4 4
##
## $missing_pattern_counts
##
## 1 1 1 2 3 1
## 78 1 1
##
## $total_missing_prop
## [1] 0.0078125
miss_info_early$total_missing should match the number of
NAs injected above (6, from the 1 listwise row, the 3-cell
sporadic block, and the 1 sporadic cell).
table(na_early$indicator_na) cross-tabulates subjects by
pattern; na_parallel$cross_layer_summary shows the same
thing per layer for the parallel structure, which is the number to check
when a specific layer is suspected of being a bigger driver of
missingness than the others.
safe_impute() and
check_imputation_quality()safe_impute() is a standalone imputation you can run
outside of model fitting – useful for a quick look at the data, or for a
workflow that needs a complete matrix for some other purpose before ever
calling estimate_lucid().
check_imputation_quality() then scores how plausible the
imputed values are relative to the observed distribution of each
column.
# Use a sub-matrix for concise display
orig_sub <- Z_early_miss[, 1:4, drop = FALSE]
imputed_sub <- safe_impute(orig_sub, method = "mean")
quality_sub <- check_imputation_quality(orig_sub, imputed_sub)
quality_sub$overall_quality## NULL
overall_quality summarizes, across all imputed cells,
how close the filled values landed to each column’s observed range and
variance – a low score here would flag an imputation that looks
implausible (e.g. a filled value far outside the observed range), which
is worth knowing about a data set even before it reaches
estimate_lucid(). estimate_lucid()’s own
internal imputation is more informed than this standalone version – it
fills a missing value conditional on the fitted cluster structure and
covariance, re-estimated at every EM iteration, rather than with a
single fixed column statistic – but the two are checking the same basic
question: are the filled-in values sane?
estimate_lucid()estimate_lucid() is the single entry point for fitting
any of the three architectures at one fixed K (number of
clusters) and one fixed penalty. lucid_model picks the
architecture; everything else (G, Z,
Y, family, K, the
Rho_* penalties) has the same meaning across all three.
Rho_G penalizes the G -> cluster
coefficients toward zero (an exposure whose coefficient is driven to
exactly zero is “not selected”); Rho_Z_Mu and
Rho_Z_Cov do the analogous thing for the omics
mean/covariance structure, so weakly-differentiating features can be
zeroed out of the cluster definition. This guide fits at
Rho_* = 0 throughout for simplicity and speed; the 3-model
tutorials walk through the penalized-screen-then- zero-penalty-refit
workflow that real feature selection uses.
One argument that is easy to overlook:
init_omic.data.model, the mclust covariance
geometry the EM is initialised from. Since 3.3.0 it defaults to
"auto", which selects the geometry by BIC per omics
layer, restricted to the geometries that layer’s n
and number of features can identify. Two layers of a parallel fit can
therefore end up with different geometries, which is usually what you
want when they are, say, methylation and transcriptomics. The previous
fixed default was "EEV"; pass it explicitly to reproduce
older results. NULL searches every mclust
geometry without the identifiability filter – it returns the same choice
in practice and is far slower, so it is kept only for backward
compatibility. The geometry actually used is reported on the fit as
fit$init_omic.data.model, one entry per layer, and it is
that concrete value – never the string "auto" – that
summary() counts parameters from and
boot_lucid() refits under.
Early integration concatenates every omics layer into one matrix and fits one cluster variable from the pooled features – the right choice when you expect a single latent state to manifest across all your omics layers at once.
set.seed(101)
fit_early <- estimate_lucid(
lucid_model = "early",
G = d$G,
Z = Z_early_miss,
Y = d$Y_normal,
CoG = d$CoG,
CoY = d$CoY,
family = "normal",
K = 2,
Rho_G = 0,
Rho_Z_Mu = 0,
Rho_Z_Cov = 0,
max_itr = 8,
max_tot.itr = 30,
tol = 1e-2,
seed = 101,
verbose = FALSE
)## Fitting LUCID early model (K = 2)...
## Finished LUCID early model.
## [1] "early_lucid"
Every field below is documented on ?estimate_lucid’s
@return; the same field names and shapes are used across
all three model types where a field applies to more than one. Rather
than reading fit_early$select$selectG directly, use
get_selected_G()/get_selected_Z() – they
return the same information as a named vector and auto-detect the model
type, so the same call works unchanged if fit_early were
swapped for a parallel or serial fit later in a script.
## [1] "res_Beta" "res_Mu" "res_Sigma"
## [4] "res_Gamma" "K" "var.names"
## [7] "init_omic.data.model" "likelihood" "inclusion.p"
## [10] "family" "select" "useY"
## [13] "Z" "init_impute" "init_par"
## [16] "Rho" "outcome_penalty" "Beta_ridge"
## [19] "outcome_method" "missing_summary" "em_control"
## likelihood: -702.3612
## selected G: 6 of 6
## selected Z: 8 of 8
At Rho_G = Rho_Z_Mu = 0 nothing is actually penalized
out, so every exposure and every omics feature is reported “selected”
here – the counts become informative once a positive penalty is applied,
as in the 3-model tutorials’ screening step.
Parallel integration fits a separate cluster variable per omics layer, jointly, rather than pooling the layers into one. Use this when the layers plausibly reflect different underlying processes – e.g. a metabolomic subtype and a methylation subtype need not coincide – and you want each to be discovered on its own terms rather than forced into a single joint cluster.
set.seed(102)
fit_parallel <- estimate_lucid(
lucid_model = "parallel",
G = d$G,
Z = Z_parallel_miss,
Y = d$Y_normal,
CoG = d$CoG,
CoY = d$CoY,
family = "normal",
K = c(2, 2),
Rho_G = 0,
Rho_Z_Mu = 0,
Rho_Z_Cov = 0,
max_itr = 8,
max_tot.itr = 30,
tol = 1e-2,
seed = 102,
verbose = FALSE
)## Fitting LUCID parallel model (2 layers)...
## Finished LUCID parallel model.
## [1] "lucid_parallel"
Two fields differ from the early fit above: N (sample
size) is present here but not for early, and z (the joint
E-step responsibility array across layers, before it is marginalized
into inclusion.p) appears only for parallel.
get_selected_G() takes an optional layer
argument here, since a parallel fit can select a different exposure
subset per layer.
## [1] "res_Beta" "res_Mu" "res_Sigma"
## [4] "res_Gamma" "K" "N"
## [7] "var.names" "init_omic.data.model" "likelihood"
## [10] "inclusion.p" "family" "select"
## [13] "useY" "Z" "z"
## [16] "init_impute" "init_par" "Rho"
## [19] "outcome_penalty" "Beta_ridge" "outcome_method"
## [22] "missing_summary" "em_control"
## N: 80
cat("selected G per layer:", paste(sapply(seq_along(fit_parallel$K), function(i)
sum(get_selected_G(fit_parallel, layer = i))),
collapse = ", "), "\n")## selected G per layer: 6, 6
sel_z_parallel <- get_selected_Z(fit_parallel)
cat("selected Z per layer:", paste(sapply(sel_z_parallel, sum), collapse = ", "), "\n")## selected Z per layer: 4, 4
get_selected_Z() returns a list here, one logical vector
per layer, since “which omics features are selected” is itself a
per-layer question for a parallel fit.
Serial integration chains stages together: stage 1’s cluster assignment becomes (part of) stage 2’s input, and so on. It suits a mediation-like hypothesis – e.g. exposures act on an early biological layer, which in turn shapes a later one, which in turn shapes the outcome. Any stage can itself be early or parallel; the fit below mixes a parallel first stage (two omics layers) with an early second stage (one layer), which is the most general configuration the package supports.
set.seed(103)
fit_serial <- estimate_lucid(
lucid_model = "serial",
G = d$G,
Z = Z_serial_miss,
Y = d$Y_normal,
CoG = d$CoG,
CoY = d$CoY,
family = "normal",
K = list(list(2, 2), 2),
Rho_G = 0,
Rho_Z_Mu = 0,
Rho_Z_Cov = 0,
max_itr = 8,
max_tot.itr = 36,
tol = 1e-2,
seed = 103,
verbose = FALSE
)## Fitting LUCID serial model (2 stages)...
## Stage 1/2 (parallel) finished: log-likelihood = -631.960.
## Stage 2/2 (early) finished: log-likelihood = -390.946.
## Finished LUCID serial model.
## [1] "lucid_serial"
## [1] 2
Serial adds submodel (the fitted stage models, each a
complete early_lucid/lucid_parallel object)
and res_Delta (between-stage transition coefficients).
likelihood and select are present, same as
early/parallel, but are aggregates: likelihood sums each
stage’s own log-likelihood (no single joint EM loop exists to report one
from), and select is stage 1’s own selection only – the one
stage whose G is the cohort’s real exposures, not a
previous stage’s cluster probabilities. get_selected_G() on
a serial fit always returns stage 1’s selection for the same reason;
get_selected_Z() returns a list, one element per stage,
shaped like whatever that stage’s own architecture is (a vector for an
early stage, a list of layers for a parallel stage).
## [1] "res_Beta" "res_Mu" "res_Sigma"
## [4] "res_Delta" "res_Gamma" "K"
## [7] "N" "var.names" "init_omic.data.model"
## [10] "inclusion.p" "family" "useY"
## [13] "Z" "init_impute" "init_par"
## [16] "submodel" "missing_summary" "Rho"
## [19] "outcome_penalty" "Beta_ridge" "outcome_method"
## [22] "em_control" "likelihood" "select"
## top-level likelihood (sum over stages): -1022.906
cat("top-level select is stage 1's select:",
identical(fit_serial$select, fit_serial$submodel[[1]]$select), "\n")## top-level select is stage 1's select: TRUE
sel_z_serial <- get_selected_Z(fit_serial)
cat("stage 1 (parallel) selected Z per layer:",
paste(sapply(sel_z_serial[[1]], sum), collapse = ", "), "\n")## stage 1 (parallel) selected Z per layer: 4, 4
## stage 2 (early) selected Z: 4
verbose = TRUE)verbose = TRUE prints one line per EM iteration – the
current log-likelihood and, where relevant, the change since the last
iteration – which is the fastest way to confirm a fit is actually
converging (steadily increasing, then flattening) rather than diverging
or oscillating. The fits below are intentionally lightweight (a
30-subject subsample, tiny iteration caps) and only serve to show what
that log looks like for each architecture.
n_demo <- 30
G_demo <- d$G[1:n_demo, , drop = FALSE]
Y_demo <- d$Y_normal[1:n_demo]
CoG_demo <- d$CoG[1:n_demo, , drop = FALSE]
CoY_demo <- d$CoY[1:n_demo, , drop = FALSE]
Z_early_demo <- d$Z_early[1:n_demo, , drop = FALSE]
Z_parallel_demo <- lapply(d$Z_parallel, function(z) z[1:n_demo, , drop = FALSE])
Z_serial_demo <- list(
lapply(d$Z_parallel, function(z) z[1:n_demo, , drop = FALSE]),
d$Z3[1:n_demo, , drop = FALSE]
)
set.seed(111)
fit_early_verbose <- estimate_lucid(
lucid_model = "early",
G = G_demo,
Z = Z_early_demo,
Y = Y_demo,
CoG = CoG_demo,
CoY = CoY_demo,
family = "normal",
K = 2,
Rho_G = 0,
Rho_Z_Mu = 0,
Rho_Z_Cov = 0,
max_itr = 2,
max_tot.itr = 8,
tol = 1e-2,
seed = 111,
verbose = TRUE
)## Initialize LUCID with mclust based on inclusion probabilities given by mclust
## Fitting Early Integration LUCID model (K = 2, Rho_G = 0, Rho_Z_Mu = 0, Rho_Z_Cov = 0)
## iteration 1 : E-step finished.
## iteration 1: log-likelihood = -286.058
## iteration 2 : E-step finished.
## iteration 2: log-likelihood = -260.750
## iteration 3 : E-step finished.
## iteration 3: log-likelihood = -257.802
## Finished LUCID early model: log-likelihood = -257.802.
set.seed(112)
fit_parallel_verbose <- estimate_lucid(
lucid_model = "parallel",
G = G_demo,
Z = Z_parallel_demo,
Y = Y_demo,
CoG = CoG_demo,
CoY = CoY_demo,
family = "normal",
K = c(2, 2),
Rho_G = 0,
Rho_Z_Mu = 0,
Rho_Z_Cov = 0,
max_itr = 2,
max_tot.itr = 8,
tol = 1e-2,
seed = 112,
verbose = TRUE
)## Fitting LUCID in Parallel model (K = 2, Rho_G = 0, Rho_Z_Mu = 0, Rho_Z_Cov = 0) (K = 2, Rho_G = 0, Rho_Z_Mu = 0, Rho_Z_Cov = 0)
## iteration 1 : E-step finished.
## iteration 1: log-likelihood = -258.776
## iteration 2 : E-step finished.
## iteration 2: log-likelihood = -257.741
## Finished LUCID parallel model: log-likelihood = -257.741.
set.seed(113)
fit_serial_verbose <- estimate_lucid(
lucid_model = "serial",
G = G_demo,
Z = Z_serial_demo,
Y = Y_demo,
CoG = CoG_demo,
CoY = CoY_demo,
family = "normal",
K = list(list(2, 2), 2),
Rho_G = 0,
Rho_Z_Mu = 0,
Rho_Z_Cov = 0,
max_itr = 2,
max_tot.itr = 10,
tol = 1e-2,
seed = 113,
verbose = TRUE
)## Fitting LUCID serial model (Stage 1/2)...
## Fitting LUCID in Parallel model (K = 2, Rho_G = 0, Rho_Z_Mu = 0, Rho_Z_Cov = 0) (K = 2, Rho_G = 0, Rho_Z_Mu = 0, Rho_Z_Cov = 0)
## iteration 1 : E-step finished.
## iteration 1: log-likelihood = -224.109
## iteration 2 : E-step finished.
## iteration 2: log-likelihood = -223.561
## Finished LUCID parallel model: log-likelihood = -223.561.
##
## Fitting LUCID serial model (Stage 2/2)...
## Initialize LUCID with mclust based on inclusion probabilities given by mclust
## Fitting Early Integration LUCID model (K = 2, Rho_G = 0, Rho_Z_Mu = 0, Rho_Z_Cov = 0)
## iteration 1 : E-step finished.
## iteration 1: log-likelihood = -168.313
## iteration 2 : E-step finished.
## iteration 2: log-likelihood = -160.625
## iteration 3 : E-step finished.
## iteration 3: log-likelihood = -152.721
## Finished LUCID early model: log-likelihood = -152.721.
##
## Success: LUCID serial model constructed!
tune_lucid() and
lucid()Choosing K and the penalty strengths by hand, as section
7 did, only works when you already have a good guess.
tune_lucid() instead fits a whole grid of
K/Rho_* combinations and reports each one’s
BIC, so the combination that best balances fit against model complexity
can be selected systematically rather than by trial and error.
lucid() goes one step further: it runs the same tuning
search, picks the BIC-best candidate, and – importantly – refits
that winner at zero penalty, so the returned model’s
coefficients are not shrunk by the same penalty that was used only to
decide which features to keep. That two-step logic (penalized search for
selection, zero-penalty refit for estimation) is worth remembering; the
3-model tutorials walk through doing it by hand for cases where more
control over the refit is needed than lucid()’s default
gives.
As of 3.3.0 that refit applies to all three integration
strategies (previously only to early, so a penalized parallel
or serial fit returned shrunk coefficients), and
tune_lucid() accepts a penalty vector for
serial models too (previously an error). Three fields on the returned
object record the outcome:
| Field | Meaning |
|---|---|
fit$Rho |
the penalty that was tuned – what selected the features |
fit$Rho_fit |
the penalty the returned estimates were produced
under; zero after a selection refit. boot_lucid() reads
this one |
fit$selection |
what the penalty dropped, in the original feature
space (FALSE = dropped), plus
degenerate_G/degenerate_Z if nothing survived
and the model was refit on everything |
get_selected_G()/get_selected_Z() read
fit$selection when it is present, so they answer in the
original feature space. (Before 3.3.0 they read fit$select,
which after the refit describes the reduced dimensions and is
all TRUE – so they reported “nothing was dropped” on
exactly the fits where something was.)
One consequence worth knowing: because the refit is on the reduced
feature set, summary(fit)$BIC is computed on those reduced
dimensions and so need not equal the BIC in the tuning
table that selected the candidate.
tune_lucid() with a small early-model gridset.seed(104)
tune_early <- tune_lucid(
G = d$G,
Z = d$Z_early,
Y = d$Y_normal,
CoG = d$CoG,
CoY = d$CoY,
family = "normal",
lucid_model = "early",
K = 2:3,
Rho_G = 0,
Rho_Z_Mu = 0,
Rho_Z_Cov = 0,
max_itr = 6,
max_tot.itr = 24,
seed = 104
)## Fitting LUCID early model (K = 2)...
## Finished LUCID early model.
## Fitting LUCID early model (K = 3)...
## Finished LUCID early model.
##
## ====================================================
## LUCID Early Integration: Model Summary
## ====================================================
##
## Model specification
## Family : normal
## Number of observations : 80
## Number of clusters (K) : 2
##
## Missing-data profile
## Listwise missing rows : 0 / 80 (0.0%)
## Sporadic missing rows : 0 / 80 (0.0%)
## Missing cells total : 0 / 640 (0.0%)
##
## Feature selection overview
## G features selected : 6 / 6 (100.0%)
## Z features selected : 8 / 8 (100.0%)
##
## Model fit statistics
## Log-likelihood : -733.82
## BIC : 1918.98
## basis: Eq 13, unstructured covariance count; not comparable across lucid_model
## Number of parameters : 103
##
## Regularization
## Rho_G : 0.000
## Rho_Z_Mu : 0.000
## Rho_Z_Cov : 0.000
##
## Detailed parameter estimates
## (1) Y (continuous outcome): cluster 1 mean (intercept), mean differences for other clusters, and covariate effects
## Gamma
## (Intercept) 0.001864201
## cluster2 0.894364324
## cov_g1 0.469363517
## cov_g2 0.574698106
## Residual SD by cluster : 0.6381, 0.9585
##
## (2) Z: mean of omics data for each latent cluster
## mu_cluster1 mu_cluster2
## Z1_f1 -0.43849123 0.9508372
## Z1_f2 -0.22736274 0.9424099
## Z1_f3 -0.13296966 0.6620847
## Z1_f4 -0.01649872 0.4805004
## Z2_f1 0.27351010 -0.9466143
## Z2_f2 0.16616391 -0.8051346
## Z2_f3 -0.05454598 -0.6658741
## Z2_f4 -0.07297551 -0.3977560
##
## (3) E: intercept and odds ratio of being assigned to each latent cluster for each exposure
## beta OR
## (Intercept).cluster2 0.9447731581 2.5722298
## G1.cluster2 2.0032574258 7.4131646
## G2.cluster2 -1.7585297952 0.1722980
## G3.cluster2 0.2981999435 1.3474312
## G4.cluster2 0.0917962079 1.0961414
## G5.cluster2 -0.2915418611 0.7471107
## G6.cluster2 -0.0002328038 0.9997672
## cov_g1.cluster2 0.2045922402 1.2270246
## cov_g2.cluster2 0.6585863478 1.9320591
##
## ====================================================
## LUCID Early Integration: Model Summary
## ====================================================
##
## Model specification
## Family : normal
## Number of observations : 80
## Number of clusters (K) : 3
##
## Missing-data profile
## Listwise missing rows : 0 / 80 (0.0%)
## Sporadic missing rows : 0 / 80 (0.0%)
## Missing cells total : 0 / 640 (0.0%)
##
## Feature selection overview
## G features selected : 6 / 6 (100.0%)
## Z features selected : 8 / 8 (100.0%)
##
## Model fit statistics
## Log-likelihood : -687.20
## BIC : 2066.77
## basis: Eq 13, unstructured covariance count; not comparable across lucid_model
## Number of parameters : 158
##
## Regularization
## Rho_G : 0.000
## Rho_Z_Mu : 0.000
## Rho_Z_Cov : 0.000
##
## Detailed parameter estimates
## (1) Y (continuous outcome): cluster 1 mean (intercept), mean differences for other clusters, and covariate effects
## Gamma
## (Intercept) -0.09081605
## cluster2 0.79148449
## cluster3 1.12610459
## cov_g1 0.61118871
## cov_g2 0.60327058
## Residual SD by cluster : 0.7182, 0.6096, 0.8504
##
## (2) Z: mean of omics data for each latent cluster
## mu_cluster1 mu_cluster2 mu_cluster3
## Z1_f1 -0.07757259 -0.8723850 1.1876097
## Z1_f2 -0.28201214 0.3704553 1.1416436
## Z1_f3 -0.05472350 -0.2813651 0.8758094
## Z1_f4 -0.05279801 0.1771612 0.5956789
## Z2_f1 0.35483942 -0.1850609 -1.2280825
## Z2_f2 -0.03123260 0.4625149 -1.0156029
## Z2_f3 -0.10710265 -0.1171564 -0.7802257
## Z2_f4 -0.08213645 0.0229832 -0.5159489
##
## (3) E: intercept and odds ratio of being assigned to each latent cluster for each exposure
## beta OR
## (Intercept).cluster2 -4.02802006 0.017809557
## G1.cluster2 4.14245936 62.957466520
## G2.cluster2 -1.37650907 0.252458331
## G3.cluster2 0.25165997 1.286158630
## G4.cluster2 1.24833305 3.484529565
## G5.cluster2 -0.36033448 0.697443006
## G6.cluster2 -2.12293988 0.119679268
## cov_g1.cluster2 -5.83563816 0.002921558
## cov_g2.cluster2 0.99847574 2.714141609
## (Intercept).cluster3 0.34136913 1.406872469
## G1.cluster3 2.71326662 15.078450765
## G2.cluster3 -1.36498903 0.255383477
## G3.cluster3 0.26513079 1.303601462
## G4.cluster3 -0.42711146 0.652390831
## G5.cluster3 0.01738098 1.017532906
## G6.cluster3 -0.27620462 0.758657677
## cov_g1.cluster3 -1.35887740 0.256949067
## cov_g2.cluster3 1.35070559 3.860148250
## K Rho_G Rho_Z_Mu Rho_Z_Cov BIC
## 1 2 0 0 0 1918.984
## 2 3 0 0 0 2066.766
tune_list has one row per grid candidate, with its
fitted K/penalty combination and its BIC; the lowest BIC in
this table is the candidate lucid() (below) would have
selected automatically.
The element names differ by model type –
tune_list/res_model/best_model
for early,
tune_K/model_list/model_opt for
parallel and serial – and a serial table now carries named
K, Rho_G, Rho_Z_Mu,
Rho_Z_Cov and BIC columns (it used to be an
unnamed one-column list-matrix with no penalty columns at all).
A note on reading those BIC values: the covariance contribution is
charged as the unconstrained K*M*(M+1)/2
regardless of the mclust geometry actually fitted, which
inflates BIC and biases K selection towards smaller
K. The default is kept so previously reported numbers
reproduce; pass summary(fit, geometry_df = TRUE) (or set
options(LUCIDus.geometry_df = TRUE)) for the geometry-aware
count. ?summary_lucid lists the full set of caveats,
including that Rho_Z_Cov earns no degrees-of-freedom credit
and that BIC is not comparable across lucid_model.
lucid() wrapper (auto-tune over K for early
model)set.seed(105)
fit_lucid_wrapper <- lucid(
G = d$G,
Z = d$Z_early,
Y = d$Y_normal,
CoG = d$CoG,
CoY = d$CoY,
family = "normal",
lucid_model = "early",
K = 2:3,
Rho_G = 0,
Rho_Z_Mu = 0,
Rho_Z_Cov = 0,
max_itr = 6,
max_tot.itr = 24,
seed = 105
)
class(fit_lucid_wrapper)## [1] "early_lucid"
fit_lucid_wrapper is a complete early_lucid
object – the same class estimate_lucid() would have
returned had K = 2:3’s BIC-winner been fit directly – so it
works with every function in this guide (summary(),
predict_lucid(), the get_*() extractors)
exactly like any other fit.
summary()summary() is the primary way to read a fitted model’s
results without digging through its raw list structure. For every model
type it prints, in order: the model specification (family, sample size,
K); a feature- selection overview (how many exposures/omics
features survived, if a penalty was used); the
G -> cluster coefficients (with odds ratios); the
cluster-specific omics means; and the cluster -> Y
coefficients. When a boot.se/bootstrap object is supplied
(section 11), every one of those coefficient tables additionally gets a
sig column marking rows whose 95%-normal-theory confidence
interval excludes 0 with "*" – a quick visual scan for
which effects are distinguishable from no effect at all, without reading
every interval by eye.
##
## ====================================================
## LUCID Early Integration: Model Summary
## ====================================================
##
## Model specification
## Family : normal
## Number of observations : 80
## Number of clusters (K) : 2
##
## Missing-data profile
## Listwise missing rows : 1 / 80 (1.2%)
## Sporadic missing rows : 4 / 80 (5.0%)
## Missing cells total : 12 / 640 (1.9%)
##
## Feature selection overview
## G features selected : 6 / 6 (100.0%)
## Z features selected : 8 / 8 (100.0%)
##
## Model fit statistics
## Log-likelihood : -702.36
## BIC : 1856.07
## basis: Eq 13, unstructured covariance count; not comparable across lucid_model
## Number of parameters : 103
##
## Regularization
## Rho_G : 0.000
## Rho_Z_Mu : 0.000
## Rho_Z_Cov : 0.000
##
## Detailed parameter estimates
## (1) Y (continuous outcome): cluster 1 mean (intercept), mean differences for other clusters, and covariate effects
## Gamma
## (Intercept) 0.05567342
## cluster2 1.03532157
## cov_g1 0.48024242
## cov_g2 0.62039164
## Residual SD by cluster : 0.7525, 0.8445
##
## (2) Z: mean of omics data for each latent cluster
## mu_cluster1 mu_cluster2
## Z1_f1 -0.290388642 1.1687228
## Z1_f2 -0.111350707 1.1301123
## Z1_f3 -0.115921061 0.8831158
## Z1_f4 0.004120712 0.6190098
## Z2_f1 0.211706887 -1.1802017
## Z2_f2 0.105075881 -1.0016956
## Z2_f3 -0.106857145 -0.7835522
## Z2_f4 -0.051897976 -0.4862203
##
## (3) E: intercept and odds ratio of being assigned to each latent cluster for each exposure
## beta OR
## (Intercept).cluster2 -0.07142331 0.9310677
## G1.cluster2 1.97169150 7.1828160
## G2.cluster2 -1.11084275 0.3292813
## G3.cluster2 0.22713093 1.2549942
## G4.cluster2 -0.29609014 0.7437204
## G5.cluster2 0.01837636 1.0185462
## G6.cluster2 0.05082562 1.0521394
## cov_g1.cluster2 -0.46644062 0.6272309
## cov_g2.cluster2 0.74313113 2.1025084
##
## ====================================================
## LUCID Parallel: Model Summary
## ====================================================
##
## Model specification
## Family : gaussian
## Number of observations : 80
## Clusters per layer : 2, 2
##
## Missing-data profile by layer
## Layer 1 listwise rows : 1 / 80 (1.2%)
## Layer 1 sporadic rows : 0 / 80 (0.0%)
## Layer 1 missing cells : 4 / 320 (1.2%)
## Layer 2 listwise rows : 0 / 80 (0.0%)
## Layer 2 sporadic rows : 1 / 80 (1.2%)
## Layer 2 missing cells : 1 / 320 (0.3%)
##
## Feature selection overview
## G features selected : 6 / 6 (100.0%)
## G features by layer
## Layer 1 : 6 / 6 (100.0%)
## Layer 2 : 6 / 6 (100.0%)
## Z features
## Layer 1 selected : 4 / 4 (100.0%)
## Layer 1 multi-cluster: 4
## Layer 2 selected : 4 / 4 (100.0%)
## Layer 2 multi-cluster: 4
##
## Model fit statistics
## Log-likelihood : -726.71
## BIC : 1803.98
## basis: Eq 13, unstructured covariance count; not comparable across lucid_model
## Number of parameters : 80
##
## Regularization
## Rho_G : 0.000
## Rho_Z_Mu : 0.000
## Rho_Z_Cov : 0.000
##
## Detailed parameter estimates
## (1) Y (continuous outcome): intercept, effects of each non-reference latent cluster for each layer of Y (and effect of covariates if included)
## Gamma
## (Intercept) 0.01945178
## Layer1_LC2 0.46267114
## Layer2_LC2 0.77517484
## cov_g1 0.45826600
## cov_g2 0.58840649
## Residual SD : 0.7739
##
## (2) Z: mean of omics data for each latent cluster of each layer
## Layer 1
##
## mu_cluster1 mu_cluster2
## Z1_f1 -0.3852458 1.1760956
## Z1_f2 -0.1181646 1.0594933
## Z1_f3 -0.1446030 0.8451872
## Z1_f4 0.0185120 0.5653166
##
## Layer 2
##
## mu_cluster1 mu_cluster2
## Z2_f1 0.12093856 -1.436718
## Z2_f2 -0.04046812 -1.043621
## Z2_f3 -0.16046704 -0.860628
## Z2_f4 -0.15526542 -0.456380
##
## (3) E: intercept and odds ratio of being assigned to each latent cluster for each exposure for each layer
## Layer 1
##
## beta OR
## (Intercept).cluster2 0.15820656 1.1714081
## G1.cluster2 2.50956420 12.2995687
## G2.cluster2 -1.27778168 0.2786548
## G3.cluster2 0.45649996 1.5785394
## G4.cluster2 -0.51132108 0.5997028
## G5.cluster2 0.06175850 1.0637054
## G6.cluster2 0.02056324 1.0207761
## cov_g1.cluster2 -0.16984212 0.8437980
## cov_g2.cluster2 1.23499685 3.4383677
##
## Layer 2
##
## beta OR
## (Intercept).cluster2 -0.7947554 0.4516917
## G1.cluster2 3.6348439 37.8959375
## G2.cluster2 -1.8647494 0.1549350
## G3.cluster2 0.1335404 1.1428675
## G4.cluster2 -0.3763982 0.6863290
## G5.cluster2 -0.4851093 0.6156299
## G6.cluster2 0.5161508 1.6755657
## cov_g1.cluster2 -2.0178137 0.1329458
## cov_g2.cluster2 1.3890824 4.0111678
##
## ====================================================
## LUCID Serial: Model Summary
## ====================================================
##
## Model specification
## Family : normal
## Number of observations : 80
## Number of stages : 2
## Stage 1 : parallel (K = 2,2)
## Stage 2 : early (K = 2)
##
## Missing-data profile by stage
## Stage 1
## Layer 1 listwise/sporadic rows : 1 / 0
## Layer 2 listwise/sporadic rows : 0 / 1
## Stage 2
## Listwise rows : 1
## Sporadic rows : 0
##
## Model fit statistics
## Log-likelihood : -1022.91
## BIC : 2532.22
## basis: Eq 26 (sum over stages), unstructured covariance count; not comparable across lucid_model
## Number of parameters : 111
##
## Regularization
## Rho_G : 0.000
## Rho_Z_Mu : 0.000
## Rho_Z_Cov : 0.000
##
## Stage-wise detailed parameter estimates
##
## --- Stage 1 (parallel) ---
##
## ====================================================
## LUCID Parallel: Model Summary
## ====================================================
##
## Model specification
## Family : gaussian
## Number of observations : 80
## Clusters per layer : 2, 2
##
## Missing-data profile by layer
## Layer 1 listwise rows : 1 / 80 (1.2%)
## Layer 1 sporadic rows : 0 / 80 (0.0%)
## Layer 1 missing cells : 4 / 320 (1.2%)
## Layer 2 listwise rows : 0 / 80 (0.0%)
## Layer 2 sporadic rows : 1 / 80 (1.2%)
## Layer 2 missing cells : 1 / 320 (0.3%)
##
## Feature selection overview
## G features selected : 6 / 6 (100.0%)
## G features by layer
## Layer 1 : 6 / 6 (100.0%)
## Layer 2 : 6 / 6 (100.0%)
## Z features
## Layer 1 selected : 4 / 4 (100.0%)
## Layer 1 multi-cluster: 4
## Layer 2 selected : 4 / 4 (100.0%)
## Layer 2 multi-cluster: 4
##
## Model fit statistics
## Log-likelihood : -631.96
## BIC : 1588.19
## Number of parameters : 74
##
## Regularization
## Rho_G : 0.000
## Rho_Z_Mu : 0.000
## Rho_Z_Cov : 0.000
##
## Detailed parameter estimates
## (1) Z: mean of omics data for each latent cluster of each layer
## Layer 1
##
## mu_cluster1 mu_cluster2
## Z1_f1 -0.38046988 1.1929851
## Z1_f2 -0.10181098 1.0584293
## Z1_f3 -0.14294669 0.8573785
## Z1_f4 0.03526335 0.5549091
##
## Layer 2
##
## mu_cluster1 mu_cluster2
## Z2_f1 0.150458987 -1.3743872
## Z2_f2 -0.009567255 -1.0211819
## Z2_f3 -0.160033139 -0.8129038
## Z2_f4 -0.142609516 -0.4550003
##
## (2) E: intercept and odds ratio of being assigned to each latent cluster for each exposure for each layer
## Layer 1
##
## beta OR
## (Intercept).cluster2 0.130061269 1.1388982
## G1.cluster2 2.706506620 14.9768641
## G2.cluster2 -1.290954666 0.2750081
## G3.cluster2 0.613889309 1.8476033
## G4.cluster2 -0.646452678 0.5239009
## G5.cluster2 0.051983110 1.0533580
## G6.cluster2 0.006638325 1.0066604
## cov_g1.cluster2 -0.186396587 0.8299444
## cov_g2.cluster2 1.516246541 4.5550957
##
## Layer 2
##
## beta OR
## (Intercept).cluster2 -0.5527188 0.57538331
## G1.cluster2 4.9490598 141.04229771
## G2.cluster2 -1.7459959 0.17447115
## G3.cluster2 0.3598919 1.43317450
## G4.cluster2 -0.1911459 0.82601207
## G5.cluster2 -0.4604310 0.63101164
## G6.cluster2 0.5068510 1.66005546
## cov_g1.cluster2 -2.9785375 0.05086717
## cov_g2.cluster2 1.2737776 3.57432963
##
##
## --- Stage 2 (early) ---
##
## ====================================================
## LUCID Early Integration: Model Summary
## ====================================================
##
## Model specification
## Family : normal
## Number of observations : 80
## Number of clusters (K) : 2
##
## Missing-data profile
## Listwise missing rows : 1 / 80 (1.2%)
## Sporadic missing rows : 0 / 80 (0.0%)
## Missing cells total : 4 / 320 (1.2%)
##
## Feature selection overview
## G features selected : 2 / 2 (100.0%)
## Z features selected : 4 / 4 (100.0%)
##
## Model fit statistics
## Log-likelihood : -390.95
## BIC : 944.03
## Number of parameters : 37
##
## Regularization
## Rho_G : 0.000
## Rho_Z_Mu : 0.000
## Rho_Z_Cov : 0.000
##
## Detailed parameter estimates
## (1) Y (continuous outcome): cluster 1 mean (intercept), mean differences for other clusters, and covariate effects
## Gamma
## (Intercept) -0.1358411
## cluster2 1.0875192
## cov_g1 0.4722009
## cov_g2 0.6760363
## Residual SD by cluster : 0.7328, 0.8273
##
## (2) Z: mean of omics data for each latent cluster
## mu_cluster1 mu_cluster2
## Z3_f1 -0.33693986 0.7195307
## Z3_f2 0.14972098 0.4272420
## Z3_f3 0.24102083 -0.7401002
## Z3_f4 -0.08892871 -0.3705079
##
## (3) E: intercept and odds ratio of being assigned to each latent cluster for each cluster from the previous serial stage
## beta OR
## (Intercept).cluster2 -1.932055 1.448502e-01
## Stage1.Layer1.cluster2.cluster2 8.137483 3.420297e+03
## Stage1.Layer2.cluster2.cluster2 46.510763 1.582587e+20
At Rho_* = 0 the selection overview above reports
everything selected (as noted in section 7); with a positive penalty,
this is the table that shows how much was screened out and at what
rate.
predict_lucid()predict_lucid() runs a fitted model’s E-step on new (or
the same) G/Z data to obtain posterior cluster
probabilities and, from those, a predicted outcome. It is what you use
to score subjects who were not part of the fitting sample, or to
double-check a model’s assignments on its own training data.
# Use lightweight no-covariate fits for robust prediction demo.
set.seed(205)
fit_early_pred <- estimate_lucid(
lucid_model = "early",
G = d$G,
Z = d$Z_early,
Y = d$Y_normal,
family = "normal",
K = 2,
max_itr = 6,
max_tot.itr = 20,
tol = 1e-2,
seed = 205
)## Fitting LUCID early model (K = 2)...
## Finished LUCID early model.
set.seed(206)
fit_parallel_pred <- estimate_lucid(
lucid_model = "parallel",
G = d$G,
Z = d$Z_parallel,
Y = d$Y_normal,
family = "normal",
K = c(2, 2),
max_itr = 6,
max_tot.itr = 20,
tol = 1e-2,
seed = 206
)## Fitting LUCID parallel model (2 layers)...
## Finished LUCID parallel model.
set.seed(207)
fit_serial_pred <- estimate_lucid(
lucid_model = "serial",
G = d$G,
Z = d$Z_serial_mixed,
Y = d$Y_normal,
family = "normal",
K = list(list(2, 2), 2),
max_itr = 6,
max_tot.itr = 24,
tol = 1e-2,
seed = 207
)## Fitting LUCID serial model (2 stages)...
## Stage 1/2 (parallel) finished: log-likelihood = -636.630.
## Stage 2/2 (early) finished: log-likelihood = -389.606.
## Finished LUCID serial model.
pred_early <- predict_lucid(
model = fit_early_pred,
G = d$G,
Z = d$Z_early,
Y = d$Y_normal
)
pred_parallel <- predict_lucid(
model = fit_parallel_pred,
G = d$G,
Z = d$Z_parallel,
Y = d$Y_normal
)
pred_serial <- predict_lucid(
model = fit_serial_pred,
G = d$G,
Z = d$Z_serial_mixed,
Y = d$Y_normal
)
# Cluster assignment. pred.x is a vector for early and a list -- by layer for
# parallel, by stage for serial -- so the blocks are summarised in one place.
# pred.x nests: a vector for early, a list by layer for parallel, and for
# serial a list by stage whose elements are themselves lists when that stage is
# a parallel submodel. Flatten to the leaves so each cluster variable is counted
# on its own -- pooling a parallel stage's layers would report twice as many
# assignments as there are subjects.
flatten_blocks <- function(x, path = "") {
if (!is.list(x)) return(stats::setNames(list(as.numeric(x)), path))
out <- list()
for (i in seq_along(x)) {
nm <- if (nzchar(path)) paste0(path, ".", i) else as.character(i)
out <- c(out, flatten_blocks(x[[i]], nm))
}
out
}
cluster_sizes <- function(pred_x, label) {
blocks <- flatten_blocks(pred_x)
nms <- names(blocks)
# index by position: the single block of an early model is named "", and
# blocks[[""]] does not select anything.
do.call(rbind, lapply(seq_along(blocks), function(i) {
tb <- table(factor(blocks[[i]]))
data.frame(model = label,
block = if (!nzchar(nms[i])) "-" else nms[i],
cluster = names(tb), n = as.integer(tb), row.names = NULL)
}))
}
rbind(
cluster_sizes(pred_early$pred.x, "early"),
cluster_sizes(pred_parallel$pred.x, "parallel"),
cluster_sizes(pred_serial$pred.x, "serial")
)## model block cluster n
## 1 early - 1 43
## 2 early - 2 37
## 3 parallel 1 1 41
## 4 parallel 1 2 39
## 5 parallel 2 1 52
## 6 parallel 2 2 28
## 7 serial 1.1 1 41
## 8 serial 1.1 2 39
## 9 serial 1.2 1 49
## 10 serial 1.2 2 31
## 11 serial 2 1 41
## 12 serial 2 2 39
The table above reports how many subjects fall in each cluster, per
model and (for parallel/serial) per layer/stage block. Roughly balanced
counts here are expected for this simulation’s roughly 50/50 latent
split; a wildly unbalanced split can be a sign that K is
larger than the data actually supports.
predict_lucid()’s pred.x above required
re-running the E-step on G/ Z. When the same
fitted-model hard assignment is wanted directly, without supplying data
again, get_cluster_assignment() reads it straight off the
fitted object’s own posterior (inclusion.p):
## [1] TRUE
The two agree here because pred_early was computed on
the same G/Z the model was fit on.
get_cluster_assignment() is the right tool whenever the
question is simply “what did this fitted model assign its subjects to,”
while predict_lucid() is for scoring genuinely new data or
getting a predicted outcome as well as an assignment.
Predicted outcomes, on the scale of the outcome that was modelled:
outcome_summary <- function(pred_y, label) {
v <- as.numeric(unlist(pred_y))
data.frame(
model = label,
n = length(v),
mean = round(mean(v), 3),
sd = round(stats::sd(v), 3),
min = round(min(v), 3),
median = round(stats::median(v), 3),
max = round(max(v), 3),
row.names = NULL
)
}
rbind(
outcome_summary(pred_early$pred.y, "early"),
outcome_summary(pred_parallel$pred.y, "parallel"),
outcome_summary(pred_serial$pred.y, "serial")
)## model n mean sd min median max
## 1 early 80 0.502 0.673 -0.137 -0.052 1.224
## 2 parallel 80 0.502 0.732 -0.218 0.536 1.443
## 3 serial 80 0.505 0.682 -0.153 -0.135 1.223
The predicted outcome is a posterior-weighted average of the
cluster-specific outcome levels, so its spread is narrower than the
observed outcome’s: it carries no residual variation, only the
between-cluster differences. Comparing its range against
summary(d$Y_normal) shows how much of the outcome the
latent structure accounts for.
rbind(
outcome_summary(pred_early$pred.y, "predicted (early)"),
outcome_summary(d$Y_normal, "observed")
)## model n mean sd min median max
## 1 predicted (early) 80 0.502 0.673 -0.137 -0.052 1.224
## 2 observed 80 0.504 1.186 -2.024 0.306 3.470
g_computation = TRUE switches to a different question:
instead of scoring observed (G, Z) pairs, it asks what the
outcome distribution would be for a given exposure profile,
marginalizing over the fitted cluster and omics model – a simple causal
“what if this subject’s exposure had been X” calculation built on top of
the fitted parameters. This is why it needs only G (no
Z, no Y) and why it alone returns
pred.z, the implied omics profile under that hypothetical
exposure.
pred_early_g <- predict_lucid(
model = fit_early_pred,
G = d$G,
Z = NULL,
Y = NULL,
g_computation = TRUE
)
pred_parallel_g <- try(
predict_lucid(
model = fit_parallel_pred,
G = d$G,
Z = NULL,
Y = NULL,
g_computation = TRUE
),
silent = TRUE
)
names(pred_early_g)## [1] "inclusion.p" "pred.x" "pred.z" "pred.y"
if (inherits(pred_parallel_g, "try-error")) {
"parallel g_computation returned a try-error on this demo object; code pattern is shown above."
} else {
names(pred_parallel_g)
}## [1] "inclusion.p" "pred.x" "pred.z" "pred.y"
pred_serial_g <- predict_lucid(
model = fit_serial_pred,
G = d$G,
Z = NULL,
Y = NULL,
g_computation = TRUE
)
names(pred_serial_g)## [1] "inclusion.p" "pred.x" "pred.z" "pred.y"
## [1] 2
Z is required for every model type. Only
g_computation = TRUE relaxes it. Y is always
optional; omitting it makes the prediction unsupervised.
Z |
Y |
g_computation |
Result |
|---|---|---|---|
| supplied | supplied | FALSE |
Supervised: outcome informs the posterior |
| supplied | omitted | FALSE |
Unsupervised: clusters from G and Z
only |
| omitted | either | FALSE |
Error naming Z and g_computation |
| omitted | omitted | TRUE |
Counterfactual prediction from G alone |
The posterior is formed from the exposure, omics and outcome
likelihood terms. Dropping Y removes one term and leaves a
well-defined posterior over the rest. Dropping Z removes
the term the clusters are defined by, leaving nothing to condition on.
g_computation = TRUE is a separate estimator that uses only
the exposure path, which is why it accepts Z = NULL and why
it alone returns pred.z; supplied Z and
Y are ignored in that mode.
Returned components, and their shape by model type:
| Component | Meaning | early | parallel | serial |
|---|---|---|---|---|
inclusion.p |
Posterior cluster probabilities | N x K matrix |
list by layer | list by stage |
pred.x |
Cluster labels, 1..K since 3.1.0 |
vector | list by layer | list by stage |
pred.y |
Predicted outcome | vector | vector | vector |
pred.z |
Implied omics profile, g_computation only |
matrix | list by layer | list by stage |
Reusing the fits from 10.1, with no refitting:
pred_unsup <- predict_lucid(
model = fit_early_pred,
G = d$G,
Z = d$Z_early
)
missing_z <- try(
predict_lucid(
model = fit_early_pred,
G = d$G,
Z = NULL,
Y = d$Y_normal
),
silent = TRUE
)
data.frame(
mode = c("Y omitted (unsupervised)", "Z omitted, no g-computation"),
result = c(
paste(names(pred_unsup), collapse = ", "),
if (inherits(missing_z, "try-error")) "error, as documented" else "unexpectedly succeeded"
)
)## mode result
## 1 Y omitted (unsupervised) inclusion.p, pred.x, pred.y
## 2 Z omitted, no g-computation error, as documented
## Input data 'Z' is required for prediction. Omit it only with g_computation = TRUE, which predicts from the exposures alone.
A serial model must have at least two stages to be predicted. A single-stage serial model is an equivalent early or parallel model and should be fitted as one; prediction declines it with a message to that effect.
boot_lucid()Point estimates from estimate_lucid() come with no
standard errors – boot_lucid() supplies them by
nonparametric bootstrap: it resamples subjects with replacement, refits
the model on each resample, and forms confidence intervals from the
resulting distribution of estimates. Because that
resampling-and-refitting only makes sense for stable, unpenalized
estimates, boot_lucid() is meant to be run on a
zero-penalty refit (the model whose coefficients are not shrunk by a
selection penalty), not on the penalized screening fit itself – the
3-model tutorials’ screen-then-refit workflow produces exactly that kind
of model. This guide bootstraps
fit_early/fit_parallel/fit_serial
directly since they were already fit at Rho_* = 0.
A lucid() fit made with a penalty is already
such a model – it was refit unpenalized on the survivors – so it
bootstraps directly, and the data is narrowed to those features
automatically so every replicate matches the point estimates. This
matters: before 3.3.0 boot_lucid() read
fit$Rho (the tuned penalty), concluded the model was
penalized, and silently refit it at zero penalty on the
full feature set, so the intervals described a
different model than the printed estimates.
Runtime note: this section uses small R for tutorial
speed; a real analysis needs enough bootstrap replicates (typically
several hundred) for the resulting intervals to be stable.
set.seed(106)
boot_early <- boot_lucid(
G = d$G,
Z = Z_early_miss,
Y = d$Y_normal,
CoG = d$CoG,
CoY = d$CoY,
model = fit_early,
R = 2,
conf = 0.9
)
boot_parallel <- boot_lucid(
G = d$G,
Z = Z_parallel_miss,
Y = d$Y_normal,
CoG = d$CoG,
CoY = d$CoY,
model = fit_parallel,
R = 2,
conf = 0.9
)
boot_serial <- boot_lucid(
G = d$G,
Z = Z_serial_miss,
Y = d$Y_normal,
CoG = d$CoG,
CoY = d$CoY,
model = fit_serial,
R = 2,
conf = 0.9
)
summary(fit_early, boot.se = boot_early)##
## ====================================================
## LUCID Early Integration: Model Summary
## ====================================================
##
## Model specification
## Family : normal
## Number of observations : 80
## Number of clusters (K) : 2
##
## Missing-data profile
## Listwise missing rows : 1 / 80 (1.2%)
## Sporadic missing rows : 4 / 80 (5.0%)
## Missing cells total : 12 / 640 (1.9%)
##
## Feature selection overview
## G features selected : 6 / 6 (100.0%)
## Z features selected : 8 / 8 (100.0%)
##
## Model fit statistics
## Log-likelihood : -702.36
## BIC : 1856.07
## basis: Eq 13, unstructured covariance count; not comparable across lucid_model
## Number of parameters : 103
##
## Regularization
## Rho_G : 0.000
## Rho_Z_Mu : 0.000
## Rho_Z_Cov : 0.000
##
## Detailed parameter estimates
## Bootstrap 90% confidence limits (normal-theory, bias-corrected: centred on
## 2*t0 - mean(t), so they need not bracket `estimate`). `sig` is assessed on
## the coefficient scale (null = 0); "NA" means no interval could be formed.
## Where an OR column is shown it is exp() of each coefficient column, so the
## intercept row is a baseline odds, not an odds ratio.
## (1) Y (continuous outcome): cluster 1 mean (intercept), mean differences for other clusters, and covariate effects
## Gamma norm_lower norm_upper sig
## (Intercept) 0.05567342 -0.02767153 0.1291417
## cluster2 1.03532157 0.76478784 1.3066863 *
## cov_g1 0.48024242 0.35261041 0.4759291 *
## cov_g2 0.62039164 0.50929553 0.8351446 *
## Residual SD by cluster : 0.7525, 0.8445
##
## (2) Z: mean of omics data for each latent cluster
## estimate norm_lower norm_upper sig
## Z1_f1.cluster1 -0.290388642 -0.72538679 0.065370704
## Z1_f2.cluster1 -0.111350707 -0.20769805 0.107375641
## Z1_f3.cluster1 -0.115921061 -0.20873439 0.122304148
## Z1_f4.cluster1 0.004120712 0.04041651 0.051099140 *
## Z2_f1.cluster1 0.211706887 0.09713623 0.243479930 *
## Z2_f2.cluster1 0.105075881 -0.05310132 0.148280339
## Z2_f3.cluster1 -0.106857145 -0.14567432 -0.001818761 *
## Z2_f4.cluster1 -0.051897976 -0.03631681 -0.001059684 *
## Z1_f1.cluster2 1.168722763 1.16977682 1.170071420 *
## Z1_f2.cluster2 1.130112251 0.87138891 1.366162976 *
## Z1_f3.cluster2 0.883115835 0.84265870 0.876311334 *
## Z1_f4.cluster2 0.619009787 0.62110712 0.763094794 *
## Z2_f1.cluster2 -1.180201740 -1.50105519 -0.771826056 *
## Z2_f2.cluster2 -1.001695642 -0.97507281 -0.897983247 *
## Z2_f3.cluster2 -0.783552235 -0.76035534 -0.581449449 *
## Z2_f4.cluster2 -0.486220343 -0.53545454 -0.399713096 *
##
## (3) E: cluster-assignment coefficients (log-odds scale) for each exposure, with bootstrap interval and the odds ratio (exp of each column). `sig` marks intervals excluding the null.
## estimate norm_lower norm_upper OR OR_lower
## (Intercept).cluster2 -0.07142331 -0.48642915 -0.08886796 0.9310677 0.61481790
## G1.cluster2 1.97169150 0.53753120 4.75890411 7.1828160 1.71177561
## G2.cluster2 -1.11084275 -2.40804744 1.03751658 0.3292813 0.08999084
## G3.cluster2 0.22713093 -1.95223510 1.94609710 1.2549942 0.14195643
## G4.cluster2 -0.29609014 -0.63009600 1.34651333 0.7437204 0.53254068
## G5.cluster2 0.01837636 -0.06007684 0.44532352 1.0185462 0.94169218
## G6.cluster2 0.05082562 -0.94151484 0.26313069 1.0521394 0.39003654
## cov_g1.cluster2 -0.46644062 -3.78310992 2.15832433 0.6272309 0.02275182
## cov_g2.cluster2 0.74313113 -4.46982833 5.21927321 2.1025084 0.01144928
## OR_upper sig
## (Intercept).cluster2 0.9149664 *
## G1.cluster2 116.6180557 *
## G2.cluster2 2.8221996
## G3.cluster2 7.0013088
## G4.cluster2 3.8439994
## G5.cluster2 1.5609951
## G6.cluster2 1.3009967
## cov_g1.cluster2 8.6566199
## cov_g2.cluster2 184.7998250
##
## ====================================================
## LUCID Parallel: Model Summary
## ====================================================
##
## Model specification
## Family : gaussian
## Number of observations : 80
## Clusters per layer : 2, 2
##
## Missing-data profile by layer
## Layer 1 listwise rows : 1 / 80 (1.2%)
## Layer 1 sporadic rows : 0 / 80 (0.0%)
## Layer 1 missing cells : 4 / 320 (1.2%)
## Layer 2 listwise rows : 0 / 80 (0.0%)
## Layer 2 sporadic rows : 1 / 80 (1.2%)
## Layer 2 missing cells : 1 / 320 (0.3%)
##
## Feature selection overview
## G features selected : 6 / 6 (100.0%)
## G features by layer
## Layer 1 : 6 / 6 (100.0%)
## Layer 2 : 6 / 6 (100.0%)
## Z features
## Layer 1 selected : 4 / 4 (100.0%)
## Layer 1 multi-cluster: 4
## Layer 2 selected : 4 / 4 (100.0%)
## Layer 2 multi-cluster: 4
##
## Model fit statistics
## Log-likelihood : -726.71
## BIC : 1803.98
## basis: Eq 13, unstructured covariance count; not comparable across lucid_model
## Number of parameters : 80
##
## Regularization
## Rho_G : 0.000
## Rho_Z_Mu : 0.000
## Rho_Z_Cov : 0.000
##
## Detailed parameter estimates
## Bootstrap 90% confidence limits (normal-theory, bias-corrected: centred on
## 2*t0 - mean(t), so they need not bracket `estimate`). `sig` is assessed on
## the coefficient scale (null = 0); "NA" means no interval could be formed.
## Where an OR column is shown it is exp() of each coefficient column, so the
## intercept row is a baseline odds, not an odds ratio.
## (1) Y (continuous outcome): intercept, effects of each non-reference latent cluster for each layer of Y (and effect of covariates if included)
## Gamma norm_lower norm_upper sig
## (Intercept) 0.01945178 -0.7621469 0.6730703
## Layer1_LC2 0.46267114 -0.9092441 2.0548601
## Layer2_LC2 0.77517484 0.5459452 0.9108488 *
## cov_g1 0.45826600 0.2592211 0.7354129 *
## cov_g2 0.58840649 0.3959531 0.8923787 *
## Residual SD : 0.7739
##
## (2) Z: mean of omics data for each latent cluster of each layer
## Layer 1
##
## estimate norm_lower norm_upper sig
## Layer1.Z1_f1.cluster1 -0.3852458 -0.57183886 -0.21862465 *
## Layer1.Z1_f2.cluster1 -0.1181646 -0.14782075 0.06622847
## Layer1.Z1_f3.cluster1 -0.1446030 -0.38815334 0.11118125
## Layer1.Z1_f4.cluster1 0.0185120 -0.09661528 0.17165957
## Layer1.Z1_f1.cluster2 1.1760956 1.21368582 1.32549518 *
## Layer1.Z1_f2.cluster2 1.0594933 0.85219498 1.26344968 *
## Layer1.Z1_f3.cluster2 0.8451872 0.57904913 1.13771298 *
## Layer1.Z1_f4.cluster2 0.5653166 0.19548661 1.04027057 *
##
## Layer 2
##
## estimate norm_lower norm_upper sig
## Layer2.Z2_f1.cluster1 0.12093856 -0.2892506 0.13223446
## Layer2.Z2_f2.cluster1 -0.04046812 -0.1687842 -0.06856747 *
## Layer2.Z2_f3.cluster1 -0.16046704 -0.2577005 0.12525747
## Layer2.Z2_f4.cluster1 -0.15526542 -0.2051852 -0.07223059 *
## Layer2.Z2_f1.cluster2 -1.43671758 -1.7729729 -0.71709836 *
## Layer2.Z2_f2.cluster2 -1.04362068 -1.2954995 -0.85887534 *
## Layer2.Z2_f3.cluster2 -0.86062799 -1.1449073 -0.60923687 *
## Layer2.Z2_f4.cluster2 -0.45638004 -0.5511173 -0.32127833 *
##
## (3) E: cluster-assignment coefficients (log-odds scale) for each exposure for each layer, with bootstrap interval and the odds ratio (exp of each column). `sig` marks intervals excluding the null.
## Layer 1
##
## estimate norm_lower norm_upper OR OR_lower
## (Intercept).cluster2 0.15820656 -1.6436591 1.2637006 1.1714081 1.932716e-01
## G1.cluster2 2.50956420 0.2029954 1.9953703 12.2995687 1.225067e+00
## G2.cluster2 -1.27778168 -3.5171927 2.8288587 0.2786548 2.968265e-02
## G3.cluster2 0.45649996 -4.0719800 4.3847274 1.5785394 1.704361e-02
## G4.cluster2 -0.51132108 -3.4982689 4.8448485 0.5997028 3.024970e-02
## G5.cluster2 0.06175850 -0.5274395 -0.1679325 1.0637054 5.901140e-01
## G6.cluster2 0.02056324 -0.2259809 1.9945257 1.0207761 7.977333e-01
## cov_g1.cluster2 -0.16984212 -3.0217480 1.8379466 0.8437980 4.871599e-02
## cov_g2.cluster2 1.23499685 -10.0589370 8.0717113 3.4383677 4.280152e-05
## OR_upper sig
## (Intercept).cluster2 3.5384919
## G1.cluster2 7.3549263 *
## G2.cluster2 16.9261316
## G3.cluster2 80.2163560
## G4.cluster2 127.0840258
## G5.cluster2 0.8454109 *
## G6.cluster2 7.3487165
## cov_g1.cluster2 6.2836220
## cov_g2.cluster2 3202.5777513
##
## Layer 2
##
## estimate norm_lower norm_upper OR OR_lower
## (Intercept).cluster2 -0.7947554 -3.7883131 5.567027 0.4516917 2.263375e-02
## G1.cluster2 3.6348439 -46.4718591 25.546225 37.8959375 6.569435e-21
## G2.cluster2 -1.8647494 -3.6033610 0.550273 0.1549350 2.723204e-02
## G3.cluster2 0.1335404 -3.4787211 1.406748 1.1428675 3.084684e-02
## G4.cluster2 -0.3763982 -0.9654839 1.926032 0.6863290 3.807989e-01
## G5.cluster2 -0.4851093 -2.4974672 3.477081 0.6156299 8.229317e-02
## G6.cluster2 0.5161508 0.6357333 1.845625 1.6755657 1.888406e+00
## cov_g1.cluster2 -2.0178137 -18.8915900 37.494482 0.1329458 6.244343e-09
## cov_g2.cluster2 1.3890824 -15.9286679 8.926917 4.0111678 1.208558e-07
## OR_upper sig
## (Intercept).cluster2 2.616550e+02
## G1.cluster2 1.243325e+11
## G2.cluster2 1.733726e+00
## G3.cluster2 4.082655e+00
## G4.cluster2 6.862225e+00
## G5.cluster2 3.236512e+01
## G6.cluster2 6.332055e+00 *
## cov_g1.cluster2 1.921527e+16
## cov_g2.cluster2 7.532010e+03
##
## ====================================================
## LUCID Serial: Model Summary
## ====================================================
##
## Model specification
## Family : normal
## Number of observations : 80
## Number of stages : 2
## Stage 1 : parallel (K = 2,2)
## Stage 2 : early (K = 2)
##
## Missing-data profile by stage
## Stage 1
## Layer 1 listwise/sporadic rows : 1 / 0
## Layer 2 listwise/sporadic rows : 0 / 1
## Stage 2
## Listwise rows : 1
## Sporadic rows : 0
##
## Model fit statistics
## Log-likelihood : -1022.91
## BIC : 2532.22
## basis: Eq 26 (sum over stages), unstructured covariance count; not comparable across lucid_model
## Number of parameters : 111
##
## Regularization
## Rho_G : 0.000
## Rho_Z_Mu : 0.000
## Rho_Z_Cov : 0.000
##
## Stage-wise detailed parameter estimates
## Bootstrap 90% confidence limits (normal-theory, bias-corrected: centred on
## 2*t0 - mean(t), so they need not bracket `estimate`). `sig` is assessed on
## the coefficient scale (null = 0); "NA" means no interval could be formed.
## Where an OR column is shown it is exp() of each coefficient column, so the
## intercept row is a baseline odds, not an odds ratio.
##
## --- Stage 1 (parallel) ---
##
## ====================================================
## LUCID Parallel: Model Summary
## ====================================================
##
## Model specification
## Family : gaussian
## Number of observations : 80
## Clusters per layer : 2, 2
##
## Missing-data profile by layer
## Layer 1 listwise rows : 1 / 80 (1.2%)
## Layer 1 sporadic rows : 0 / 80 (0.0%)
## Layer 1 missing cells : 4 / 320 (1.2%)
## Layer 2 listwise rows : 0 / 80 (0.0%)
## Layer 2 sporadic rows : 1 / 80 (1.2%)
## Layer 2 missing cells : 1 / 320 (0.3%)
##
## Feature selection overview
## G features selected : 6 / 6 (100.0%)
## G features by layer
## Layer 1 : 6 / 6 (100.0%)
## Layer 2 : 6 / 6 (100.0%)
## Z features
## Layer 1 selected : 4 / 4 (100.0%)
## Layer 1 multi-cluster: 4
## Layer 2 selected : 4 / 4 (100.0%)
## Layer 2 multi-cluster: 4
##
## Model fit statistics
## Log-likelihood : -631.96
## BIC : 1588.19
## Number of parameters : 74
##
## Regularization
## Rho_G : 0.000
## Rho_Z_Mu : 0.000
## Rho_Z_Cov : 0.000
##
## Detailed parameter estimates
## (1) Z: mean of omics data for each latent cluster of each layer
## Layer 1
##
## estimate norm_lower norm_upper sig
## Layer1.Z1_f1.cluster1 -0.38046988 -0.41062689 -0.36019609 *
## Layer1.Z1_f2.cluster1 -0.10181098 -0.50106883 0.10318400
## Layer1.Z1_f3.cluster1 -0.14294669 -0.16752738 -0.03568906 *
## Layer1.Z1_f4.cluster1 0.03526335 0.02905515 0.05484416 *
## Layer1.Z1_f1.cluster2 1.19298510 0.98980747 1.46792254 *
## Layer1.Z1_f2.cluster2 1.05842930 0.95268561 1.08826584 *
## Layer1.Z1_f3.cluster2 0.85737849 0.62892953 1.10946303 *
## Layer1.Z1_f4.cluster2 0.55490911 0.63445358 0.73316140 *
##
## Layer 2
##
## estimate norm_lower norm_upper sig
## Layer2.Z2_f1.cluster1 0.150458987 -0.1316092 0.72784359
## Layer2.Z2_f2.cluster1 -0.009567255 -0.1068988 0.26699383
## Layer2.Z2_f3.cluster1 -0.160033139 -0.2447791 -0.08734598 *
## Layer2.Z2_f4.cluster1 -0.142609516 -0.1999152 0.01457289
## Layer2.Z2_f1.cluster2 -1.374387212 -1.5202742 -1.14150204 *
## Layer2.Z2_f2.cluster2 -1.021181902 -1.3653216 -0.67394818 *
## Layer2.Z2_f3.cluster2 -0.812903809 -1.0899497 -0.36089382 *
## Layer2.Z2_f4.cluster2 -0.455000299 -0.5914102 -0.28106789 *
##
## (2) E: cluster-assignment coefficients (log-odds scale) for each exposure for each layer, with bootstrap interval and the odds ratio (exp of each column). `sig` marks intervals excluding the null.
## Layer 1
##
## estimate norm_lower norm_upper OR
## (Intercept).cluster2 0.130061269 0.097253268 0.51586178 1.1388982
## G1.cluster2 2.706506620 0.458612881 5.03092675 14.9768641
## G2.cluster2 -1.290954666 -1.009598168 -0.30826503 0.2750081
## G3.cluster2 0.613889309 -1.058274195 2.34000801 1.8476033
## G4.cluster2 -0.646452678 -3.592506778 2.42071326 0.5239009
## G5.cluster2 0.051983110 0.008308136 0.04670825 1.0533580
## G6.cluster2 0.006638325 -1.570324434 1.26818133 1.0066604
## cov_g1.cluster2 -0.186396587 -1.615699286 1.12947821 0.8299444
## cov_g2.cluster2 1.516246541 -2.252476789 5.72568271 4.5550957
## OR_lower OR_upper sig
## (Intercept).cluster2 1.10213948 1.6750814 *
## G1.cluster2 1.58187821 153.0748085 *
## G2.cluster2 0.36436536 0.7347206 *
## G3.cluster2 0.34705424 10.3813198
## G4.cluster2 0.02752923 11.2538833
## G5.cluster2 1.00834274 1.0478163 *
## G6.cluster2 0.20797770 3.5543824
## cov_g1.cluster2 0.19875164 3.0940416
## cov_g2.cluster2 0.10513850 306.6425426
##
## Layer 2
##
## estimate norm_lower norm_upper OR OR_lower
## (Intercept).cluster2 -0.5527188 -1.4366158 2.2229358 0.57538331 2.377309e-01
## G1.cluster2 4.9490598 -5.4001014 12.5565331 141.04229771 4.516123e-03
## G2.cluster2 -1.7459959 -2.7100848 0.3459242 0.17447115 6.653117e-02
## G3.cluster2 0.3598919 -0.6897807 1.7277128 1.43317450 5.016861e-01
## G4.cluster2 -0.1911459 -2.8359187 3.7000418 0.82601207 5.866460e-02
## G5.cluster2 -0.4604310 -0.2176457 0.3952315 0.63101164 8.044104e-01
## G6.cluster2 0.5068510 -2.6333238 2.8635678 1.66005546 7.183929e-02
## cov_g1.cluster2 -2.9785375 -9.5117543 6.0462256 0.05086717 7.397715e-05
## cov_g2.cluster2 1.2737776 -3.9151321 4.5656454 3.57432963 1.993792e-02
## OR_upper sig
## (Intercept).cluster2 9.234401e+00
## G1.cluster2 2.839442e+05
## G2.cluster2 1.413296e+00
## G3.cluster2 5.627767e+00
## G4.cluster2 4.044900e+01
## G5.cluster2 1.484728e+00
## G6.cluster2 1.752394e+01
## cov_g1.cluster2 4.225153e+02
## cov_g2.cluster2 9.612461e+01
##
##
## --- Stage 2 (early) ---
##
## ====================================================
## LUCID Early Integration: Model Summary
## ====================================================
##
## Model specification
## Family : normal
## Number of observations : 80
## Number of clusters (K) : 2
##
## Missing-data profile
## Listwise missing rows : 1 / 80 (1.2%)
## Sporadic missing rows : 0 / 80 (0.0%)
## Missing cells total : 4 / 320 (1.2%)
##
## Feature selection overview
## G features selected : 2 / 2 (100.0%)
## Z features selected : 4 / 4 (100.0%)
##
## Model fit statistics
## Log-likelihood : -390.95
## BIC : 944.03
## Number of parameters : 37
##
## Regularization
## Rho_G : 0.000
## Rho_Z_Mu : 0.000
## Rho_Z_Cov : 0.000
##
## Detailed parameter estimates
## (1) Y (continuous outcome): cluster 1 mean (intercept), mean differences for other clusters, and covariate effects
## Gamma norm_lower norm_upper sig
## (Intercept) -0.1358411 -0.4638944 0.0324805
## cluster2 1.0875192 0.6138674 1.4129291 *
## cov_g1 0.4722009 0.4254216 0.6121939 *
## cov_g2 0.6760363 0.5859255 0.7217071 *
## Residual SD by cluster : 0.7328, 0.8273
##
## (2) Z: mean of omics data for each latent cluster
## estimate norm_lower norm_upper sig
## Z3_f1.cluster1 -0.33693986 -0.55437826 -0.42210253 *
## Z3_f2.cluster1 0.14972098 0.22930544 0.34410429 *
## Z3_f3.cluster1 0.24102083 0.09131234 0.73388829 *
## Z3_f4.cluster1 -0.08892871 -0.30307323 0.07962283
## Z3_f1.cluster2 0.71953073 0.51898587 0.89760960 *
## Z3_f2.cluster2 0.42724196 -0.02233699 0.50859045
## Z3_f3.cluster2 -0.74010024 -1.11665819 -0.20568073 *
## Z3_f4.cluster2 -0.37050787 -0.61049882 -0.05324667 *
##
## (3) E: cluster-assignment coefficients (log-odds scale) for each cluster from the previous serial stage, with bootstrap interval and the odds ratio (exp of each column). `sig` marks intervals excluding the null.
## estimate norm_lower norm_upper OR
## (Intercept).cluster2 -1.932055 1.205754 2.460671 1.448502e-01
## Stage1.Layer1.cluster2.cluster2 8.137483 -10.577640 9.760548 3.420297e+03
## Stage1.Layer2.cluster2.cluster2 46.510763 53.907467 101.687329 1.582587e+20
## OR_lower OR_upper sig
## (Intercept).cluster2 3.339276e+00 1.171267e+01 *
## Stage1.Layer1.cluster2.cluster2 2.547940e-05 1.733613e+04
## Stage1.Layer2.cluster2.cluster2 2.580568e+23 1.452934e+44 *
Each coefficient table above now shows a normal-theory confidence
interval alongside the point estimate, plus the sig column
described in section 9. With only R = 2 replicates here the
interval is not meaningful – this chunk exists to show the output
format, not to draw real conclusions; a real bootstrap needs
R in the hundreds.
A real bootstrap needs hundreds of replicates, and each replicate is
a complete, independent model refit – so the work parallelizes almost
perfectly. boot_lucid() and tune_lucid() both
take a parallel argument ("no", the default;
"multicore"; or "snow") plus
ncpus. "multicore" forks the current session
and is the fastest option on macOS and Linux; "snow" starts
a socket cluster and also works on Windows. Nothing about the serial
default changes – parallel = "no" is exactly the behaviour
shown in every chunk above.
tune_lucid() fits each grid point from a fixed
seed, so its result is identical whichever backend you pick
– only the wall-clock time differs. A parallel bootstrap instead draws
its replicate resamples from parallel random-number streams, so a
reproducible parallel bootstrap needs the "L'Ecuyer-CMRG"
generator and a seed set before the call; the chunk below
switches to it and restores the default afterwards.
The chunks in this section are shown but not run when the vignette is built, so that building it never starts worker processes; copy them into your own session to use several cores.
old_kind <- RNGkind("L'Ecuyer-CMRG")
set.seed(106)
boot_early_mc <- boot_lucid(
G = d$G,
Z = Z_early_miss,
Y = d$Y_normal,
CoG = d$CoG,
CoY = d$CoY,
model = fit_early,
R = 30,
conf = 0.9,
parallel = backend,
ncpus = n_cores
)
RNGkind(old_kind[1]) # restore the default generator
summary(fit_early, boot.se = boot_early_mc)R = 30 on two cores runs in a few seconds; scaled up to
R = 500 on, say, eight cores, the same call is roughly
eight times faster than the serial default.
tune_early_mc <- tune_lucid(
G = d$G,
Z = d$Z_early,
Y = d$Y_normal,
CoG = d$CoG,
CoY = d$CoY,
family = "normal",
lucid_model = "early",
K = 2:3,
Rho_G = 0,
Rho_Z_Mu = 0,
Rho_Z_Cov = 0,
max_itr = 6,
max_tot.itr = 24,
seed = 104,
parallel = backend,
ncpus = n_cores
)
tune_early_mc$tune_list
all.equal(tune_early_mc$tune_list, tune_early$tune_list)The tuning table is the same one produced serially in section 8.1 –
the all.equal() line returns TRUE; the
parallel argument changes only how the grid is dispatched,
not what it returns.
Each replicate is warm-started from the fitted model
(boot_init = "reference", the default) and its cluster
labels are aligned to the fit by posterior overlap, including the
stage-to-stage coefficients of a serial model. Every replicate gets its
own seed drawn in advance, so since 3.3.1 set.seed() alone
makes a run reproducible, however many cores it uses. Two outputs tell
you whether the resamples reproduce the same clusters at all:
stability$units: per stage and layer, the adjusted Rand
index of each replicate’s cluster assignment against the fit, and the
spread of the cluster sizes;boot_lucid_table(): a tidy table with percentile
intervals and the share of replicates agreeing in sign with each
estimate.For multi-stage serial models fitted on small samples, a small
Beta_ridge in estimate_lucid() keeps the
stage-to-stage coefficients finite when a cluster is (nearly) perfectly
predicted by the previous stage.
## stage layer cluster ari_mean ari_median prop_ari_below_0.5 size_ref
## 1 1 1 2 0.9037944 0.9037944 0.0 38.92349
## 2 1 2 2 0.6926821 0.6926821 0.5 31.73289
## 3 2 1 2 0.6978767 0.6978767 0.0 45.87313
## size_q025 size_median size_q975
## 1 38.48123 39.78820 41.09516
## 2 26.81477 29.66789 32.52102
## 3 41.10940 42.02719 42.94499
## Stage Layer Block Term Cluster Estimate n_boot CI_low
## 1 Stage1 Layer1 Beta (X ~ G) (Intercept) 2 0.13006127 2 -0.1319140
## 2 Stage1 Layer1 Beta (X ~ G) G1 2 2.70650662 2 1.7345864
## 3 Stage1 Layer1 Beta (X ~ G) G2 2 -1.29095467 2 -2.0661885
## 4 Stage1 Layer1 Beta (X ~ G) G3 2 0.61388931 2 -0.1070105
## 5 Stage1 Layer1 Beta (X ~ G) G4 2 -0.64645268 2 -1.9348957
## 6 Stage1 Layer1 Beta (X ~ G) G5 2 0.05198311 2 0.0686168
## CI_high same_sign CI_excl_0 median norm_lower norm_upper
## 1 0.03904401 0.5 FALSE -0.04643498 0.057156121 0.55595893
## 2 3.60190050 1.0 TRUE 2.66824343 0.020645807 5.46889382
## 3 -1.77976695 1.0 TRUE -1.92297773 -1.076776588 -0.24108661
## 4 1.28083393 0.5 FALSE 0.58691171 -1.383784594 2.66551841
## 5 0.52087854 0.5 FALSE -0.70700860 -4.168493566 2.99670004
## 6 0.08429925 1.0 TRUE 0.07645803 0.004629914 0.05038647
plot()plot() draws a Sankey diagram of the fitted model’s
structure: flows from each exposure, through the latent cluster(s), to
the outcome, with flow width proportional to the estimated association
strength. It is a structural view – what connects to what, and how
strongly – complementary to the omics-profile view in the next section,
which shows what the clusters actually look like in the omics data.
As of 3.3.0 all three integration strategies have a Sankey method (both previously raised “still under development”), sharing one visual language and one set of appearance options:
An omics feature name that occurs in more than one layer or stage is prefixed with its block, so the two remain distinct nodes rather than silently merging into one and pooling their flows.
plot_early <- plot(fit_early)
plot_parallel <- plot(fit_parallel)
# Serial defaults: the chain alone (omics = "none"), with widths scaled within
# block -- a serial model's cluster-to-cluster transition coefficients regress
# on a posterior probability in [0, 1] and so run far larger than the other
# blocks, which on one shared scale would crush everything else to hairlines.
plot_serial <- plot(fit_serial)
# Each strategy has a different topology, so the diagrams differ in size.
vapply(list(early = plot_early, parallel = plot_parallel, serial = plot_serial),
function(p) c(nodes = nrow(p$x$nodes), links = nrow(p$x$links)),
numeric(2))## early parallel serial
## nodes 19 21 15
## links 34 52 42
Early integration – one cluster variable, so one
G -> X -> Z/Y fan:
Parallel integration – one cluster variable per
layer, each fed by the same exposures and each feeding the
shared outcome. Cluster nodes carry their layer name, so
methylome Cluster 2 and miRNA Cluster 2 stay
distinct (a layer’s own name is used when Z is a named
list, otherwise Layer 1, Layer 2, …):
Serial integration – the chain. Read it left to right: exposures into
stage 1’s clusters, then stage 1’s clusters into stage 2’s
clusters (those links are the transition coefficients, the
parameters a serial model exists to estimate), and the final stage’s
clusters into the outcome. The omics features are not drawn by
default, so every column holds one kind of node: drawing each
feature individually would put stage s’s omics in the same
column as stage s+1’s clusters, because a Sankey takes a node’s
column from the longest path into it. Use
omics = "aggregate", "features" or
"per_stage" to bring them in, and
plot_cluster_omic_profile() for the per-feature view
(?plot.lucid_serial):
Node types are the same in all three: exposures (G),
latent clusters (X), omics features (Z) and
the outcome (Y), coloured by type. Link colour is the sign
of the effect and link width its magnitude, subject to the
link_scale caveat above.
plot_cluster_omic_profile()plot() draws the path structure.
plot_cluster_omic_profile() draws what the clusters
actually are: which omics features separate them, and in which
direction. It returns a named list of ggplot objects, one
per omics layer, so a parallel or serial fit gives one figure per layer
rather than one crowded one.
Features are ranked by importance. The default,
"separation", is the spread of the cluster means divided by
the typical within-cluster spread; "range" and
"sd" use the means alone. Only the standardized measure can
distinguish a feature that separates the clusters from one that is
merely noisy.
| Argument | Effect |
|---|---|
type |
"heatmap" (default) or "bar" |
top_n |
Features per panel, default 10; a layer with fewer shows all |
importance |
"separation" (default), "range",
"sd" |
layer_names |
Subtitles; defaults to the names of the omics list |
layer_colors |
One hue per layer |
scale |
TRUE (default) fills with a per-feature z-score;
FALSE with the cluster mean |
## [1] "Omics"
Read the heatmap by row: a feature whose color alternates sharply
between clusters (e.g. dark for cluster 1, light for cluster 2) is one
that strongly distinguishes them; a feature with similar shading across
clusters is barely contributing to the separation despite appearing in
the top-n list.
The bar rendering shows the same features and ordering, with clusters as shades of the layer’s colour:
A parallel fit returns one plot per layer:
## [1] "layer1" "layer2"
A serial fit gives one plot per stage, and one per layer within a stage that is itself a parallel sub-model:
## [1] "Stage 1 - layer1" "Stage 1 - layer2" "Stage 2"
get_top_omics_features()The importance ranking behind every panel above is also available as
plain data, without generating a plot – useful for a report table, or
for feeding the top features into a downstream analysis.
get_top_omics_features() uses the exact same ranking
criterion as plot_cluster_omic_profile() (so its output for
a given top_n matches that plot’s panel ordering), and,
like the other extractors, auto-detects the model type and returns one
named numeric vector per layer/stage.
## $Omics
## Z1_f1 Z2_f1 Z1_f2 Z2_f2 Z1_f3
## 1.729526 1.649868 1.471541 1.311887 1.184186
The names are the features, in descending order of importance score;
the values are the score itself (by default, the between-cluster
separation described above). This is the same top-5 that would appear in
a plot_cluster_omic_profile(fit_early, top_n = 5) panel,
just as a plain vector rather than a figure.
Everything above used a continuous outcome
(family = "normal"). Switching to
family = "binary" changes only the outcome model: the
cluster effects on Y become log-odds (with odds ratios
reported alongside), there is no residual variance to estimate, and
predict_lucid()’s response argument lets you
choose class-label or probability output. This short chunk shows that
fit and a probability-scale prediction.
set.seed(107)
fit_early_binary <- estimate_lucid(
lucid_model = "early",
G = d$G,
Z = d$Z_early,
Y = d$Y_binary,
CoG = d$CoG,
CoY = d$CoY,
family = "binary",
K = 2,
max_itr = 8,
max_tot.itr = 30,
tol = 1e-2,
seed = 107
)## Fitting LUCID early model (K = 2)...
## Finished LUCID early model.
pred_binary_prob <- predict_lucid(
model = fit_early_binary,
G = d$G,
Z = d$Z_early,
Y = d$Y_binary,
CoG = d$CoG,
CoY = d$CoY,
response = FALSE
)
range(pred_binary_prob$pred.y)## [1] 0.1069302 0.9470312
pred.y here is a probability in [0, 1]
because response = FALSE; setting
response = TRUE instead would return hard
0/1 class labels.
max_itr, max_tot.itrRtune_lucid()## R version 4.6.2 (2026-10-29)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 26.04.1 LTS
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.32.so; LAPACK version 3.12.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
## [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
##
## time zone: Etc/UTC
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] plotly_4.12.1 ggplot2_4.0.4 LUCIDus_3.3.1 rmarkdown_2.32
##
## loaded via a namespace (and not attached):
## [1] gtable_0.3.6 shape_1.4.6.1 xfun_0.63
## [4] bslib_0.12.0 formula.tools_1.7.1 htmlwidgets_1.6.4
## [7] lattice_0.23-1 crosstalk_1.2.2 vctrs_0.7.3
## [10] tools_4.6.2 generics_0.1.4 tibble_3.3.1
## [13] pkgconfig_2.0.3 Matrix_1.7-6 data.table_1.18.6.1
## [16] RColorBrewer_1.1-3 S7_1.0.0 lifecycle_1.0.5
## [19] compiler_4.6.2 farver_2.1.2 progress_1.2.3
## [22] data.tree_1.2.0 codetools_0.2-20 htmltools_0.5.9
## [25] sys_3.4.3 glasso_1.11 buildtools_1.0.0
## [28] sass_0.5.0 yaml_2.3.12 glmnet_5.2
## [31] mice_3.20.0 pillar_1.11.1 crayon_1.5.3
## [34] jquerylib_0.1.4 tidyr_1.3.2 cachem_1.1.0
## [37] iterators_1.0.14 rpart_4.1.27 boot_1.3-32
## [40] mclust_6.1.4 foreach_1.5.2 nlme_3.1-172
## [43] tidyselect_1.2.1 digest_0.6.39 stringi_1.8.9
## [46] dplyr_1.2.1 purrr_1.2.2 maketools_1.3.2
## [49] labeling_0.4.3 splines_4.6.2 operator.tools_1.6.3.1
## [52] fastmap_1.2.0 grid_4.6.2 cli_3.6.6
## [55] magrittr_2.0.5 survival_3.8-13 broom_1.0.13
## [58] withr_3.0.3 prettyunits_1.2.0 scales_1.4.0
## [61] backports_1.5.1 httr_1.4.9 logistf_1.26.1
## [64] networkD3_0.4.1 igraph_2.3.4 otel_0.3.0
## [67] nnet_7.3-21 hms_1.1.4 evaluate_1.0.5
## [70] knitr_1.52 viridisLite_0.4.3 mgcv_1.9-5
## [73] rlang_1.3.0 Rcpp_1.1.2 glue_1.8.1
## [76] jsonlite_2.0.0 R6_2.6.1
estimate_lucid()tune_lucid() and
lucid()summary()predict_lucid()boot_lucid()