Extract native posterior standard deviations in a matched basis
Source:R/extract.R
factor_uncertainty.RdGet the posterior standard deviation of each activity or effect estimate,
expressed in the coordinates of the view you pass. Needs the native fit.
Native variational uncertainty is conditional on estimated priors. Posterior
SD is not a downstream regression standard error. Missing moments are NA.
Mean-field variational SDs are typically underdispersed. A bare native fit
uses LDF coordinates, as in factor_activity().
Unmeasured reference features have status unavailable and reason
not_in_native_fit; uncertainty is never borrowed from the source fit.
Usage
factor_uncertainty(
fit,
side = c("activity", "effects"),
sample_side = NULL,
representation = NULL,
factors = NULL,
ids = NULL,
include_lfsr = TRUE,
require_uncertainty = FALSE
)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 toscaling = "ldf", so values differ fromfit$L_pm/fit$F_pm; passrepresentation = 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.
- include_lfsr
Also return the native local false sign rate when the prior supplies it (default
TRUE).- require_uncertainty
Stop instead of returning NA when posterior moments are unavailable (default
FALSE).
Details
Origin: WRAPPER / call_only. Credits native posterior moments / public accessors; use factor_provenance("factor_uncertainty") for audited sources and runtime versions. Input units and basis are retained; display/conditional results do not establish biological replication.
See also
factor_intervals() for sampled intervals
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)
factor_uncertainty(fit, side = "activity", factors = "F1", ids = c("s1", "s2"))
#> sample factor estimate
#> 1 s1 F1 -0.01893963
#> 2 s2 F1 -0.10325198
#> basis_id posterior.sd
#> 1 5dad41352e500cc55c297e6ed23a85681ef1aa989180a4b402210a71eb8e1b76 0.01443036
#> 2 5dad41352e500cc55c297e6ed23a85681ef1aa989180a4b402210a71eb8e1b76 0.01443036
#> lfsr uncertainty_type status reason
#> 1 9.466152e-02 conditional_variational_ebmf supported <NA>
#> 2 4.176777e-13 conditional_variational_ebmf supported <NA>