Skip to contents

Turn a native flashier fit into a view: a samples by factors activity matrix and a features by factors effects matrix that share factor columns, plus an offset and a manifest recording your declarations. Most other functions take this view. Uses public flashier LDF normalization, placing D on exactly one side. Raw and LDF views reconstruct the same posterior mean. Anchor orientation requires declared signed support on both sides. No model is refitted. A projected fit retains its declared external offset on measured native axes. Intercept, initialized and projected views carry versioned per-factor support and roles. Ordinary legacy views retain their manifests; homogeneous support is derived from their global constraints without changing the basis hash.

Usage

standardize_factors(
  fit,
  sample_side = NULL,
  scaling = "ldf",
  type = "f",
  d_location = "effects",
  orientation = "as_fit",
  prior_support = NULL,
  feature_scale = NULL,
  preprocessing = NULL,
  independent_unit = NULL
)

Arguments

fit

A native flashier fit with named rows and columns.

sample_side

"rows" or "columns": which side of the fitted matrix holds samples. Required for a bare native fit; fits from fit_ebmf() already record it.

scaling

"ldf" (default), "raw" or "rms". ldf gives unit-norm factors with the scale on the d_location side; raw keeps flashier's own coordinates. rms rescales each activity column to unit root-mean-square and compensates on the effects side, preserving the reconstruction exactly; it is a coordinate change (factor units), not a change to the fitted model or its uncertainty.

type

Native LDF norm used when scaling = "ldf": "f" (default, 2-norm), "o" (1-norm) or "i" (max norm); 2, 1, m are aliases.

d_location

"effects" (default) or "activity": which side absorbs the native scale D under LDF scaling.

orientation

"as_fit" (default) keeps native signs; "anchor_feature" flips each factor so its largest effect is positive, which needs declared signed support on both sides.

prior_support

Optional named character vector, e.g. c(activity = "nonnegative", effects = "signed"); values are "signed", "nonnegative" or "unknown". Required by functions that test signs.

feature_scale

Free-text label for what the matrix values measure, e.g. "log1p_normalized_counts". Recorded, never applied. Optional for a bare fit or an unspecified recorded scale; cannot replace known recorded units.

preprocessing

Optional named preprocessing declaration for a bare fit; cannot replace an existing nonempty declaration.

independent_unit

Optional independent-unit declaration for a bare fit; cannot replace an existing declaration.

Value

A factor_representation list with $activity (samples by factors), $effects (features by factors), $offset (per feature) and $manifest (declarations, scaling and a basis_id hash). Serializable.

Details

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

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)
raw <- standardize_factors(fit, scaling = "raw")
max(abs(tcrossprod(raw$activity, raw$effects) - tcrossprod(view$activity, view$effects)))
#> [1] 4.440892e-16
# Raw scale, D on the activities, each factor oriented by its largest effect.
anchored <- standardize_factors(fit,
  sample_side = "rows", scaling = "raw", d_location = "activity",
  orientation = "anchor_feature", independent_unit = "sample",
  preprocessing = list(transform = "none")
)
anchored$manifest$anchor_features
#> NULL