Skip to contents

Given new features measured on the same samples (for example a second assay), keep the fitted sample activities fixed and estimate effects for the new features. For new samples use project_factor_activity() instead.

Usage

project_factor_features(
  fit,
  query,
  sample_side,
  feature_scale,
  factors = NULL,
  ebnm_fn = NULL,
  maxiter = 200L,
  S = NULL,
  dense_budget_bytes = 256 * 1024^2
)

Arguments

fit

Native reference fit or a view from standardize_factors().

query

Named matrix of the new measurements on the same samples; sample_side says which side holds samples.

sample_side

"rows" or "columns" of query. Required.

feature_scale

Free-text label for what the query values measure. Required.

factors

Optional character factor IDs to keep fixed, in source order. Default all.

ebnm_fn

Optional native prior for the new features. The recorded activity prior is reused; the default new-feature prior is signed point-Laplace.

maxiter

Native iteration limit (default 200).

S

Optional native standard errors; sparse plus S is refused.

dense_budget_bytes

Budget for dense allocations in bytes (default 256 MiB).

Value

List with $fit (native), $representation (view with the new features), $reconstruction (in-sample rmse, mae, fit_r2, correlation; not prediction) and the source basis. Cells are matched by ID; QR initialization rejects rank deficiency.

Details

Feature-specific residual variance is estimated. Native noise/prior hyperparameters may recalibrate. Fixed activities retain their exact values. Sources with an intercept or external offset use an augmented ones/activity basis to estimate new signed point-normal feature offsets. Offsets are kept separate from semantic factors; dependent augmented columns are refused.

Author

Mikhael Manurung; native engine Jason Willwerscheid, Peter Carbonetto, Wei Wang and Matthew Stephens. Conceptual transfer: STARCAT authors.

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, scaling = "raw")
# Six new features measured on the same 24 samples; activities stay fixed.
Y <- tcrossprod(view$activity, matrix(rnorm(12), 6, 2)) + matrix(rnorm(144, sd = 0.2), 24, 6)
dimnames(Y) <- list(rownames(X), paste0("p", 1:6))
projected <- project_factor_features(view, Y, "rows", "simulated_protein",
  ebnm_fn = list(ebnm::ebnm_normal, ebnm::ebnm_point_laplace), maxiter = 20
)
projected$representation$effects
#>            F1          F2
#> p1  2.0253642  0.74951510
#> p2  0.5520542  0.02415655
#> p3 -0.4466845 -1.03471645
#> p4  0.6961645  0.01858439
#> p5  1.6821714  2.08403345
#> p6  1.0307251 -1.15781846
projected$reconstruction
#>             rmse              mae           fit_r2      correlation 
#>        0.1849613        0.1487342        0.9774626        0.9887627 
#> n_scored_entries 
#>      144.0000000