Skip to contents

Fit flashier through one call that also records sample orientation, units and the independent unit, so later functions need no repeated declarations. Calling flashier::flash() yourself and then standardize_factors() is equally valid. Uses public flashier fitting calls. max_factors is an upper bound. Priors in a list are in native row/column order, independent of sample_side. A supplied seed restores the caller's RNG state; NULL consumes it. No preprocessing.

Usage

fit_ebmf(
  X,
  sample_side = c("rows", "columns"),
  ebnm_fn = ebnm::ebnm_point_normal,
  S = NULL,
  var_type = 0L,
  max_factors = 50L,
  backfit = FALSE,
  nullcheck = TRUE,
  id_policy = "require",
  feature_scale = "unknown",
  independent_unit = NULL,
  seed = NULL,
  verbose = 1L,
  intercept = c("none", "feature"),
  control = list()
)

Arguments

X

Named numeric matrix or double sparse Matrix; NA is observed missingness. Only dimnames are kept; other attributes are dropped.

sample_side

"rows" or "columns": which side holds samples. Required.

ebnm_fn

Prior family: one ebnm::ebnm_* function for both sides, or a list of two in native row/column order (not sample/feature order). Default ebnm::ebnm_point_normal. Use ebnm_point_exponential for nonnegative sides.

S

Optional known observation standard errors (scalar, vector or matrix). NULL (default) estimates noise from the data.

var_type

Residual variance structure passed to flashier: 0L (default) one constant, 1L per row, 2L per column, c(1L, 2L) both (in that order), NULL none, which requires S. With one constant variance (0L), features measured on larger scales dominate the fit, so use 2L or rescale the features first. No centering is assumed; an intercept is available through intercept.

max_factors

Upper bound on the number of greedily added factors (default 50). The fit can stop earlier.

backfit

Run the native backfit after greedy addition (default FALSE).

nullcheck

Drop factors that do not improve the objective (default TRUE).

id_policy

"require" (default) stops on missing dimnames; "generate" creates them.

feature_scale

Free-text label for what the matrix values measure, e.g. "log1p_normalized_counts". Default "unknown". Recorded, never applied.

independent_unit

Optional free-text description of the biological replicate, e.g. "donor"; recorded, not inferred.

seed

Optional integer; the caller's RNG state is restored afterwards.

verbose

Native flashier verbosity; 0 is silent.

intercept

none (default) or feature. A feature intercept has fixed sample-side ones and a signed native point-normal feature offset. It is excluded from semantic factor IDs; max_factors counts adaptive factors.

control

Optional named list of advanced native settings: S_dim, greedy, backfit, nullcheck lists.

Value

A native flash object with a flashbridge_metadata attribute that records the declarations. Pass it to standardize_factors(). Sparse input with explicit S is unsupported by the audited native engine and refused.

Details

Origin: WRAPPER / call_only. Credits flash; use factor_provenance("fit_ebmf") for audited sources and runtime versions. Input units and basis are retained; display/conditional results do not establish biological replication.

References

Wang W, Stephens M (2021). Empirical Bayes matrix factorization. Journal of Machine Learning Research 22(120).

Willwerscheid J, Carbonetto P, Wang W, Stephens M. flashier: Empirical Bayes Matrix Factorization. R package, https://github.com/willwerscheid/flashier.

Willwerscheid J, Carbonetto P, Stephens M (2025). ebnm: An R package for solving the empirical Bayes normal means problem using a variety of prior families. Journal of Statistical Software 114(3), 1-33. doi:10.18637/jss.v114.i03

Author

Jason Willwerscheid; Peter Carbonetto; Wei Wang; 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)
fit
#> Flash object with 2 factors.
#>   Proportion of variance explained:
#>     Factor 1: 0.508
#>     Factor 2: 0.451
#>   Variational lower bound: -165.987
# A feature intercept, per-column residual variance and a native backfit control.
with_offset <- fit_ebmf(X, "rows",
  max_factors = 2, seed = 4, verbose = 0, backfit = TRUE, intercept = "feature",
  var_type = 2L, control = list(backfit = list(maxiter = 500)),
  id_policy = "require", independent_unit = "sample"
)
# Known noise standard deviations instead of an estimated variance.
known_noise <- fit_ebmf(X, "rows", max_factors = 1, seed = 4, verbose = 0, S = 0.2, var_type = NULL)