Requires a common activity basis and all eligible factor rows, never only significant rows. V describes correlated estimation errors across conditions, not true-effect covariance. Small factor counts limit covariance learning.
Usage
shrink_factor_effects(
results,
condition,
method = "mash",
term,
covariances = "canonical",
V = NULL,
independent_conditions = NULL,
control = list()
)Arguments
- results
A coefficient table with attached activity manifest. The model is
estimate ~ N(B, std.error^2 V)per factor. If the table has adfcolumn (as fromtest_factor_association()) the t statistics are converted to z-equivalent standard errors withmashr::mash_set_data(df = ); without it the standard errors are taken as known (df = Inf), which makeslfsrtoo small when they were estimated from few residual df. The choice is recorded inanalysis_metadata$df_source.- condition
Condition column name.
- method
Only mash is supported.
- term
Required comparable term value.
- covariances
canonical or a caller-supplied covariance list.
- V
Optional condition error-correlation matrix.
- independent_conditions
Explicit TRUE when using identity V.
- control
Named public mash settings; outputlevel must retain summaries.
Value
A list with the posterior table, the native fit, the input
estimate matrix Bhat, the input standard errors Shat, Shat_used (the
standard errors mash actually used: z-equivalent SEs for cells with finite
df, otherwise equal to Shat), df (factor by condition matrix of the
table df values, NULL without a df column), the covariances and
analysis_metadata. A finite df with an estimate of exactly 0 is an error.
Details
Origin: WRAPPER / call_only. Credits mashr public API (implementation audit pending); use factor_provenance("shrink_factor_effects") for audited sources and runtime versions. Input units and basis are retained; display/conditional results do not establish biological replication.
Author
Mikhael Manurung; Matthew Stephens; Sarah Urbut; Gao Wang; Yuxin Zou; Peter Carbonetto (mashr); ashr contributors. Full source and dependency credits: https://github.com/mdmanurung/flashier-utils/blob/main/CREDITS.md.
Examples
if (FALSE) {
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)
# Small-row illustration; does not establish covariance/lfsr calibration.
ids <- view$manifest$factor_ids
coefficients <- data.frame(
factor = rep(ids, 2), condition = rep(c("A", "B"), each = length(ids)),
term = "treatment", estimate = seq_len(2 * length(ids)) / 5, std.error = 0.5, basis_id = view$manifest$basis_id
)
attr(coefficients, "analysis_metadata") <- view$manifest
shrink_factor_effects(coefficients, "condition", term = "treatment", independent_conditions = TRUE)$table
}