Rank the features that drive one factor. "largest" orders by effect size
within the factor; "distinctive" orders by the margin to the strongest
competing factor, so shared features drop down the list.
Returns two explicit ranking views when select is both. Cutoff ties are
ordered by feature ID, with signed nonzero eligibility. No biological labels.
Usage
factor_features(
fit,
factor,
representation = NULL,
compare_factors = NULL,
select = "both",
direction = "absolute",
n = 20L
)Arguments
- fit
Native fit or a view from
standardize_factors().- factor
One factor ID, e.g.
"F1". A fit with no biological factors cannot supply a feature selection.- representation
For a native fit: a matched view or
standardize_factors()settings.- compare_factors
Optional character factor IDs that compete for
"distinctive";NULL(default) uses all other factors.- select
"both"(default),"largest"or"distinctive".- direction
"absolute"(default),"positive"or"negative": which effects are eligible.- n
Maximum number of features per selection (default 20).
Value
A data.frame with columns feature, factor, estimate, rank,
direction, selection and basis_id, plus tie-rule metadata attributes.
Details
Origin: NEW_QOL / none. Credits rank_effects; compute_le_effects; use factor_provenance("factor_features") for audited sources and runtime versions. Input units and basis are retained; display/conditional results do not establish biological replication.
Author
Peter Carbonetto; Matthew Stephens. Full source and dependency credits: https://github.com/mdmanurung/flashier-utils/blob/main/CREDITS.md.
Examples
set.seed(3)
X <- tcrossprod(matrix(rnorm(48), 24, 2), matrix(rnorm(32), 16, 2)) +
matrix(rnorm(384, sd = 0.2), 24, 16)
dimnames(X) <- list(paste0("s", 1:24), paste0("g", 1:16))
fit <- fit_ebmf(X, "rows",
max_factors = 2, seed = 4, verbose = 0,
ebnm_fn = list(ebnm::ebnm_normal, ebnm::ebnm_point_laplace),
nullcheck = FALSE, backfit = TRUE, feature_scale = "simulated_centered_intensity"
)
view <- standardize_factors(fit)
factor_features(view, factor = "F1", select = "both", n = 3)
#> feature factor estimate rank selection direction
#> 1 g1 F1 5.827934 1 largest absolute
#> 2 g5 F1 -5.742540 2 largest absolute
#> 3 g9 F1 5.657477 3 largest absolute
#> 4 g1 F1 5.827934 1 distinctive absolute
#> 5 g9 F1 5.657477 2 distinctive absolute
#> 6 g4 F1 5.374776 3 distinctive absolute
#> basis_id
#> 1 fe24c85db06f4fa76955a0e81bafca2568a8335285ab7868bdec3470b3172f17
#> 2 fe24c85db06f4fa76955a0e81bafca2568a8335285ab7868bdec3470b3172f17
#> 3 fe24c85db06f4fa76955a0e81bafca2568a8335285ab7868bdec3470b3172f17
#> 4 fe24c85db06f4fa76955a0e81bafca2568a8335285ab7868bdec3470b3172f17
#> 5 fe24c85db06f4fa76955a0e81bafca2568a8335285ab7868bdec3470b3172f17
#> 6 fe24c85db06f4fa76955a0e81bafca2568a8335285ab7868bdec3470b3172f17
#> distinctiveness
#> 1 NA
#> 2 NA
#> 3 NA
#> 4 5.827934
#> 5 5.657477
#> 6 5.374776