Skip to contents

Draw from flashier's posterior sampler and return intervals and sign probabilities for selected activities or effects, in the coordinates of the view you pass. Needs the native fit. Uses fit$sampler batches with fixed representation multipliers, conditional on empirical priors. Quantiles are exact sample quantiles. Draws do not include rank, optimization or biological resampling uncertainty. Mean-field variational draws are typically underdispersed, so intervals can be too narrow: in one rank-1 simulation intervals for non-null effects covered 0.67 to 0.91 of the true values at nominal 0.95, while effects that were truly zero were excluded at the nominal rate. Each fit is one local optimum, so the intervals are conditional on the optimum reached; refit with another seed to see whether they move. A bare native fit uses LDF coordinates, as in factor_activity(). Selected IDs must be present in the native fit; unmeasured reference features have no native sampler entries and are refused explicitly.

Usage

factor_intervals(
  fit,
  side = c("activity", "effects"),
  sample_side = NULL,
  representation = NULL,
  factors = NULL,
  ids = NULL,
  level = 0.95,
  nsamp = 2000L,
  seed = NULL
)

Arguments

fit

Native flash fit or a view from standardize_factors().

side

"activity" (default) or "effects".

sample_side

"rows" or "columns"; needed only for a bare native fit.

representation

For a native fit: a matched view or a named list of standardize_factors() settings; a bare native fit defaults to scaling = "ldf", so values differ from fit$L_pm/fit$F_pm; pass representation = list(scaling = "raw") for native coordinates.

factors

Optional character factor IDs, e.g. c("F2", "F1"), in the order wanted. Default all.

ids

Optional character sample IDs (activity side) or feature IDs (effects side). Default all.

level

Interval coverage, strictly between zero and one (default 0.95).

nsamp

Number of posterior draws, at least two (default 2000). Interval ends are sample quantiles, so a small nsamp leaves few draws in each tail and the interval comes out too narrow; the function warns when fewer than 5 draws fall in each tail (nsamp * (1 - level) / 2 < 5, under 200 draws at level 0.95). Small values are for speed in examples, not for conclusions.

seed

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

Value

Long table with estimate, posterior.sd, lower, upper, prob_positive and prob_zero for the selected IDs.

Details

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

See also

factor_uncertainty() for closed-form posterior SDs

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)
# nsamp = 200 is for speed; use the default 2000 for conclusions.
factor_intervals(fit, side = "activity", factors = "F1", ids = c("s1", "s2"), nsamp = 200, seed = 9)
#>   sample factor    estimate
#> 1     s1     F1 -0.01893963
#> 2     s2     F1 -0.10325198
#>                                                           basis_id        mean
#> 1 d4c2613c5f78c69a34553f2a13526c81d9c04f6227768918164c7f8d8606ebba -0.01975957
#> 2 d4c2613c5f78c69a34553f2a13526c81d9c04f6227768918164c7f8d8606ebba -0.10288534
#>   posterior.sd      lower        upper prob_positive prob_zero
#> 1   0.01394475 -0.0436875  0.008618425          0.09         0
#> 2   0.01520971 -0.1310896 -0.073795501          0.00         0
#>                     uncertainty_type
#> 1 conditional_variational_ebmf_draws
#> 2 conditional_variational_ebmf_draws