The extension point for new modelling backends. Every method of build_contrast_analysis is a
facade class that inherits from ContrastsFacadeBase; a package adds a method by writing such a class and
registering it with register_facade (usually from its .onLoad()). The base class provides
the uniform API: get_contrasts() (stamped with the method name), get_missing(),
get_Plotter(), to_wide() and get_config().
A subclass implements initialize(lfqdata, modelstr, contrasts, ...):
call the private
.setup(lfqdata, contrasts, key, modelstr)first; it checks the input shape, the contrasts and the design, stores a copy of the input, and returns the full model formula stringset
self$modelto the fitted model andself$contrastto the contrast object the facade delegates to (e.g.ContrastsModerated)set the private field
.needsto"nested"if the facade takes child-level input (e.g. peptides) and reports parent-level contrasts; the default is"aggregated"
The limma family, lm, deqms and deqms_voom additionally set self$.drop_na_diff <- TRUE
to drop rows whose fold change could not be estimated; get_missing() lists them.
See also
Other modelling:
AnovaExtractor,
Contrasts,
ContrastsComparison,
ContrastsDEqMSFacade,
ContrastsDEqMSVoomFacade,
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(),
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()
Super class
ContrastsInterface -> ContrastsFacadeBase
Public fields
modelfitted model object
contrastinner contrast object the facade delegates to
.lfqdatasnapshot of the input LFQData (used by get_missing)
.contrast_namesnames of the requested contrasts
facade_nameregistry key stamped into the modelName column
.drop_na_diffdrop rows with NA diff (limma family); default FALSE
Methods
ContrastsFacadeBase$get_config()
get the ContrastConfiguration; defaults to
the inner contrast object's configuration
ContrastsFacadeBase$get_Plotter()
get ContrastsPlotter
ContrastsFacadeBase$provenance()
problems and dropped items of this analysis, read from the input data, the aggregated data
(hurdle_nested, limpa_nested) and the model(s), plus the subjects absent from the contrasts
with the reason
ContrastsFacadeBase$.recorded_provenance()
internal: the entries recorded in the input data, the aggregated data and the model(s),
without evaluating contrasts (used by print())
Examples
# a facade: unweighted linear model per protein, moderated contrasts
ContrastsUnweightedLMFacade <- R6::R6Class(
"ContrastsUnweightedLMFacade",
inherit = ContrastsFacadeBase,
public = list(
initialize = function(lfqdata, modelstr, contrasts) {
full_formula <- private$.setup(lfqdata, contrasts, "lm_unweighted", modelstr)
self$model <- build_model(lfqdata, strategy_lm(full_formula))
self$contrast <- ContrastsModerated$new(Contrasts$new(self$model, contrasts))
}
)
)
istar <- sim_lfq_data_protein_config(n_proteins = 10)
#> `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 16 rows with NA response for feature and sample combinations absent from the input.
lfqdata <- LFQData$new(istar$data, istar$config)
facade <- ContrastsUnweightedLMFacade$new(lfqdata, "~ group_", c(AvsCtrl = "group_A - group_Ctrl"))
#> fit (Model): 16 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().
head(facade$get_contrasts())
#> # A tibble: 6 × 16
#> modelName estimate_type protein_Id contrast diff avgAbd
#> <chr> <chr> <chr> <chr> <dbl> <dbl>
#> 1 lm_unweighted observed 0EfVhX~0087 AvsCtrl -2.62 21.1
#> 2 lm_unweighted observed 7cbcrd~5725 AvsCtrl 2.80 20.7
#> 3 lm_unweighted observed 9VUkAq~4703 AvsCtrl 1.67 20.3
#> 4 lm_unweighted observed BEJI92~5282 AvsCtrl 0.424 21.0
#> 5 lm_unweighted observed CGzoYe~2147 AvsCtrl -0.598 30.8
#> 6 lm_unweighted observed Fl4JiV~8625 AvsCtrl -0.0494 21.3
#> # ℹ 10 more variables: std.error.unmoderated <dbl>, df.unmoderated <int>,
#> # std.error <dbl>, statistic <dbl>, df <dbl>, p.value <dbl>, conf.low <dbl>,
#> # conf.high <dbl>, sigma <dbl>, FDR <dbl>
# registered from a package's .onLoad(), build_contrast_analysis() finds the method by name:
# register_facade("lm_unweighted", class = "ContrastsUnweightedLMFacade", needs = "aggregated",
# package = "mypackage")