Compute borrowed variance from successful model fits
Source:R/tidyMS_build_model.R
compute_borrowed_variance.RdCompute borrowed variance from successful model fits
Arguments
- model_df
tibble from model_analyse
- method
"sigma" borrows scalar sigma and uses per-protein (X'X)^-1, "vcov" borrows element-wise median of full vcov matrices
- on_misalign
behaviour when donor
vcovmatrices cannot be aligned by coefficient name (method = "vcov"only). "fallback" (default) warns and falls back to the sigma method, preserving the lm behaviour. "fail" borrows from the largest subset sharing the maximal coefficient set without a sigma fallback; backends without an lm-stylesummary(fit)$cov.unscaled(e.g. rfit) must use this because the sigma fallback is not applicable to them.
See also
Other modelling:
AnovaExtractor,
Contrasts,
ContrastsComparison,
ContrastsDEqMSFacade,
ContrastsDEqMSVoomFacade,
ContrastsFacadeBase,
ContrastsFirth,
ContrastsFirthFacade,
ContrastsHurdleFacade,
ContrastsHurdleNestedFacade,
ContrastsLMFacade,
ContrastsLMImputeFacade,
ContrastsLimma,
ContrastsLimmaFacade,
ContrastsLimmaImputeFacade,
ContrastsLimmaVoomFacade,
ContrastsLimmaVoomImputeFacade,
ContrastsLimpaFacade,
ContrastsLimpaNestedFacade,
ContrastsLmerNestedFacade,
ContrastsModerated,
ContrastsModeratedDEqMS,
ContrastsPlotter,
ContrastsRLMFacade,
ContrastsROPECA,
ContrastsROPECANestedFacade,
ContrastsROPECAV2,
ContrastsROPECAV2NestedFacade,
ContrastsRfitFacade,
ContrastsRfitImputeFacade,
ContrastsTable,
INTERNAL_FUNCTIONS_BY_FAMILY,
Model,
ModelFirth,
ModelLimma,
StrategyLM,
StrategyLimma,
StrategyLimpa,
StrategyLmer,
StrategyLogistf,
StrategyRLM,
StrategyRfit,
build_contrast_analysis(),
build_model(),
build_model_glm_protein(),
build_model_impute(),
build_model_limma(),
build_model_limma_impute(),
build_model_limma_voom(),
build_model_limma_voom_impute(),
build_model_limpa(),
compute_borrowed_variance_limma(),
df.residual.rfit_prolfqua(),
group_label(),
impute_from_model(),
impute_refit_singular(),
list_facades(),
lookup_facade(),
lr_test(),
merge_contrasts_results(),
new_imputed_model(),
nobs.rfit_prolfqua(),
pivot_model_contrasts_to_wide(),
prolfqua_analysis_methods,
register_facade(),
sigma.rfit_prolfqua(),
strategy_limma(),
strategy_limpa(),
strategy_logistf(),
vcov.rfit_prolfqua()
Examples
mod <- prolfqua:::.sim_build_models_lm(model = "parallel3", weight_missing = 1)
#> `protein_Id`: columns `proteinID`, `idtype2` united with separator '~'.
#> creating sampleName from file_name column
#> setup_analysis: dropped 5 unconfigured columns: average_prot_abundance, sd, mean, N, Replicate.
#> setup_analysis: added 45 rows with NA response for feature and sample combinations absent from the input.
#> fit (Model): 2 singular fits (e.g. BEJI92~5282, Fl4JiV~8625): coefficients not estimable or fewer than 2 residual df
#> fit (Model): 45 missing responses dropped (e.g. 0EfVhX~0087, 7cbcrd~5725, 9VUkAq~4703, BEJI92~5282, DoWup2~5896, ...): NA response (missing observation) left out of the fit
#> See $provenance().
# Sigma method (default): returns median sigma and df from donors
borrowed_s <- prolfqua:::compute_borrowed_variance(
mod$model_df, method = "sigma")
stopifnot(borrowed_s$method == "sigma")
stopifnot(is.numeric(borrowed_s$sigma) && borrowed_s$sigma > 0)
stopifnot(is.numeric(borrowed_s$df) && borrowed_s$df > 0)
# Vcov method: element-wise median vcov from donors.
# Falls back to sigma if donor models have misaligned coefficient names.
mod_no_missing <- prolfqua:::.sim_build_models_lm(model = "parallel3",
n_proteins = 10, with_missing = FALSE)
#> `protein_Id`: columns `proteinID`, `idtype2` united with separator '~'.
#> creating sampleName from file_name column
#> setup_analysis: dropped 5 unconfigured columns: average_prot_abundance, sd, mean, N, Replicate.
borrowed_v <- prolfqua:::compute_borrowed_variance(
mod_no_missing$model_df, method = "vcov")
stopifnot(borrowed_v$method == "vcov")
stopifnot(is.matrix(borrowed_v$vcov))