Skip to contents

Check a backproject_contrast() result against the same contrast estimated directly per feature, e.g. a differential expression table. Both estimates must use the same contrast, covariates, weighting and declared units. Prediction R squared is distinct from squared correlation and can be negative. Regression slope and top-feature overlap are descriptive. slope regresses reconstructed on observed, so noise in the observed table pulls it below 1 even when the reconstruction is exact; calibration_slope regresses observed on reconstructed and is not attenuated that way.

Usage

validate_backprojection(
  reconstructed,
  observed,
  feature_scale,
  contrast = NULL,
  id_col = "feature",
  estimate_col = "estimate",
  top_n = c(20L, 50L, 100L),
  zero_tolerance = 0,
  plot = TRUE
)

Arguments

reconstructed

A backproject_contrast() result, or its $effects table.

observed

Data frame of directly estimated feature effects with the columns named in id_col and estimate_col.

feature_scale

Free-text units shared by both tables; must not be "unknown". Required.

contrast

Optional single contrast label to select from reconstructed.

id_col

Name of the feature ID column in both tables (default "feature").

estimate_col

Name of the numeric effect column (default "estimate").

top_n

Integer vector of top-feature overlap sizes to report (default 20, 50, 100).

zero_tolerance

Effects within this absolute value count as zero for sign agreement (default 0).

plot

Include a scatter plot (default TRUE).

Value

List with $metrics (pearson_correlation, prediction_r2, correlation_squared, slope, intercept, calibration_slope, sign_concordance), $top_n_overlap, $matched_features, $residuals, $plot, $exclusions and $analysis_metadata.

Details

Origin: NEW_ORCHESTRATION / none. Credits new reconstruction diagnostics; no exact upstream function claimed; use factor_provenance("validate_backprojection") for audited sources and runtime versions. Input units and basis are retained; display/conditional results do not establish biological replication.

Author

Mikhael Manurung. 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)
beta <- setNames(rep(1, ncol(view$activity)), colnames(view$activity))
result <- backproject_contrast(view, beta, "coefficients", factor_basis = view$manifest)
# Illustrative same-scale feature vector; not a calibrated statistical truth.
observed <- result$effects[, c("feature", "estimate")]
validate_backprojection(result, observed = observed, feature_scale = "simulated_centered_intensity", plot = FALSE)$metrics
#>                metric value denominator reason
#> 1 pearson_correlation     1          16   <NA>
#> 2       prediction_r2     1          16   <NA>
#> 3 correlation_squared     1          16   <NA>
#> 4               slope     1          16   <NA>
#> 5           intercept     0          16   <NA>
#> 6   calibration_slope     1          16   <NA>
#> 7    sign_concordance     1          16   <NA>
# Smaller top-n overlaps and a nonzero tolerance for near-zero effects.
validate_backprojection(result,
  observed = observed, feature_scale = "simulated_centered_intensity",
  id_col = "feature", estimate_col = "estimate", top_n = c(5L, 10L), zero_tolerance = 1e-8, plot = FALSE
)$top_n_overlap
#>   requested_n effective_n overlap_n overlap_fraction
#> 1           5           5         5                1
#> 2          10          10        10                1