Skip to contents

Ask whether the programs of one saved fit are representable by those of another: pairwise loading cosines, bidirectional span and feasible (support- constrained) coverage, residual gene profiles and optional bound validation evidence. No fitting or biological novelty test is performed.

Usage

compare_prior_fits(
  reference,
  target,
  feature_map = NULL,
  min_shared_features = 2L,
  activity_poles = c("observed", "supported"),
  evidence = NULL
)

# S3 method for class 'prior_comparison'
print(x, ...)

# S3 method for class 'prior_comparison'
plot(
  x,
  type = c("similarity", "coverage", "residual"),
  direction = c("reference", "target"),
  factor = NULL,
  ...
)

Arguments

reference, target

Native fits, validated factor representations, GBCD results, or declared lists with named activity/effects matrices, support (activity/effects), feature_scale and optional preprocessing, roles and offset. Matrix inputs are comparison sources, not invented native FLASH fits.

feature_map

Optional one-to-one reference-to-target feature mapping.

min_shared_features

Computational minimum shared features, default two.

activity_poles

observed evaluates directions used by each source's scores; supported evaluates its declared signed/nonnegative score support.

evidence

Optional reference/target lists with exact-basis stability artifacts and explicitly driver-bound paired holdout artifacts. Each entry's source_basis_id is the caller's assertion that the holdout belongs to that source; it is compared with the source's basis id but nothing checks that the holdout's fits were built from the source's recipe (a warning appears when the holdout folds fitted a different factor count, or when the holdout's recorded prior identifiers differ from those recorded in the source). Two holdouts count as paired only when they share the input, folds, masks and scored values (after any transform), score the same folds, units and cohorts, and have no failed fold.

x

A prior_comparison result.

...

Passed through by the print and plot generics; unused.

type

"similarity" (default, cosine tiles with printed values), "coverage" (uncovered loading fraction per source factor and pole) or "residual" (per-feature residual for one source factor).

direction

Source side for coverage/residual: "reference" (default) or "target".

factor

Source factor ID for a residual plot.

Value

A prior_comparison with similarities, bidirectional coverage, residual gene profiles, exclusions, compact manifests and separate evidence states.

Details

Effects are compared after L2 normalization on shared genes. Span coverage allows signed coefficients; feasible coverage constrains target coefficients according to declared activity support. Unknown support and failed solver certification remain unassessed. Residuals are in unit-loading coordinates, not expression variance or absence probabilities. Offsets are reported separately. Equal units do not establish equal fitting inputs.

Origin: NEW_ORCHESTRATION / none. Credits base R linear algebra and stats::optim; use factor_provenance("compare_prior_fits") for audited sources and runtime versions. Input units and basis are retained; coverage describes loading representability, not program usage or biological replication.

See also

factor_replicability() for one-to-one factor matching; factor_holdout() and factor_stability() produce the optional evidence. Tutorial: compare priors.

Author

Mikhael Manurung; R Core Team (linear algebra and stats::optim). Native EBMF: 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"
)
comparison <- compare_prior_fits(fit, fit)
comparison$coverage[, c("source", "factor", "pole", "span_residual", "feasible_residual")]
#>      source factor pole span_residual feasible_residual
#> 1 reference     F1   -1  1.544003e-31      1.544003e-31
#> 2 reference     F1    1  1.544003e-31      1.544003e-31
#> 3 reference     F2   -1  7.233146e-32      7.233146e-32
#> 4 reference     F2    1  7.233146e-32      7.233146e-32
#> 5    target     F1   -1  1.544003e-31      1.544003e-31
#> 6    target     F1    1  1.544003e-31      1.544003e-31
#> 7    target     F2   -1  7.233146e-32      7.233146e-32
#> 8    target     F2    1  7.233146e-32      7.233146e-32