Mean, SD and quantiles of each factor's activity within each metadata group,
with sample and unit counts. Descriptive only; use test_factor_association() for
inference. Per-observation weighting is the default; cells are not donor-balanced.
With weights, only means are supported: SD and quantiles are NA and labelled
unavailable. Descriptive SD never estimates uncertainty of the group mean.
Group identity uses metadata tuples, so punctuation cannot merge groups.
A zero-factor fit returns a typed empty summary table.
With an activity_threshold, raw active_n and active_proportion summaries are
added per factor and group using a strict greater-than comparison on the
resolved representation coordinates; with weights, active_weighted_proportion
is added as the weighted mean of the binary active indicator, while
active_n and active_proportion remain raw observation summaries.
Usage
summarize_factor_activity(
fit,
metadata,
by,
id_col = "sample",
unit_col = NULL,
weights = NULL,
na_action = "fail",
activity_threshold = NULL,
activity_direction = c("positive", "negative", "absolute")
)Arguments
- fit
Native fit or a view from
standardize_factors().- metadata
Data frame with one row per sample; sample IDs in
id_col.- by
Name of one or more
metadatacolumns to group by. Factor level order is ignored; levels only define the groups.- id_col
Name of the sample ID column (default
"sample").- unit_col
Optional name of the independent-unit column, e.g. donor; adds an
n_unitscount.- weights
Optional nonnegative numeric vector named by sample ID.
- na_action
"fail"(default) or"omit"; omitted rows are recorded inexclusions.- activity_threshold
Optional single nonnegative finite threshold on the resolved representation coordinates; no display scaling is performed.
- activity_direction
"positive"(default),"negative"or"absolute": which side of the coordinates is compared against the threshold with a strict > operator.
Value
Table with columns group (one per by column), factor, n,
n_units, mean, sd, median, q25, q75, plus active_n,
active_proportion and (with weights) active_weighted_proportion when a
threshold is supplied; no p-values.
Details
Origin: NEW_QOL / none. Credits metadata grouping workflow; use factor_provenance("summarize_factor_activity") for audited sources and runtime versions. Input units and basis are retained; display/conditional results do not establish biological replication.
Author
David Zemmour / Zemmour Lab (ImmGenT workflows). 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)
metadata <- data.frame(
sample = rownames(X), donor = rownames(X),
group = rep(c("A", "B"), each = 12)
)
summarize_factor_activity(view, metadata, "group", unit_col = "donor")
#> group factor n n_units mean sd median q25
#> 1 A F1 12 12 0.08042587 0.1662896 0.07452087 -0.02270012
#> 2 A F2 12 12 -0.03622352 0.2141814 -0.08335829 -0.22579963
#> 3 B F1 12 12 0.05763505 0.2292961 0.05731736 -0.06046495
#> 4 B F2 12 12 -0.08540516 0.1888037 -0.08842041 -0.18767790
#> q75 basis_id
#> 1 0.237289188 53d5a90be811f396108240670481b1d84938f988af26f5ad9375619a755f55c5
#> 2 0.079636759 53d5a90be811f396108240670481b1d84938f988af26f5ad9375619a755f55c5
#> 3 0.238446889 53d5a90be811f396108240670481b1d84938f988af26f5ad9375619a755f55c5
#> 4 -0.004179992 53d5a90be811f396108240670481b1d84938f988af26f5ad9375619a755f55c5
summarize_factor_activity(view, metadata, "group", activity_threshold = 0.5)
#> group factor n n_units mean sd median q25
#> 1 A F1 12 NA 0.08042587 0.1662896 0.07452087 -0.02270012
#> 2 A F2 12 NA -0.03622352 0.2141814 -0.08335829 -0.22579963
#> 3 B F1 12 NA 0.05763505 0.2292961 0.05731736 -0.06046495
#> 4 B F2 12 NA -0.08540516 0.1888037 -0.08842041 -0.18767790
#> q75 active_n active_proportion
#> 1 0.237289188 0 0
#> 2 0.079636759 0 0
#> 3 0.238446889 0 0
#> 4 -0.004179992 0 0
#> basis_id
#> 1 53d5a90be811f396108240670481b1d84938f988af26f5ad9375619a755f55c5
#> 2 53d5a90be811f396108240670481b1d84938f988af26f5ad9375619a755f55c5
#> 3 53d5a90be811f396108240670481b1d84938f988af26f5ad9375619a755f55c5
#> 4 53d5a90be811f396108240670481b1d84938f988af26f5ad9375619a755f55c5