Skip to contents

Uses limma's contrasts.fit + eBayes pipeline directly, rather than fitting per-protein lm models and then moderating. Inherits from ContrastsInterface with the same API as Contrasts.

Each protein's contrasts and their unscaled standard errors are computed from the design rows of its own fit (observed samples, with their weights), where contrasts.fit uses one approximation for all proteins. Contrasts a protein cannot estimate, e.g. with an empty group, are NA; the others equal the differences of its fitted group means.

Value

An R6 class generator.

See also

Other modelling: AnovaExtractor, Contrasts, ContrastsComparison, ContrastsDEqMSFacade, ContrastsDEqMSVoomFacade, ContrastsFacadeBase, ContrastsFirth, ContrastsFirthFacade, ContrastsHurdleFacade, ContrastsHurdleNestedFacade, ContrastsLMFacade, ContrastsLMImputeFacade, 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 -> ContrastsLimma

Public fields

model

ModelLimma object

contrasts

named character vector of contrasts

model_name

model name

subject_id

columns with subject_id (proteinID)

p.adjust

function to adjust p-values

contrast_result

cached contrast results

eBayes

logical, apply limma eBayes moderation (default TRUE). Set to FALSE to return raw/unmoderated statistics, e.g. for downstream DEqMS moderation via ContrastsModeratedDEqMS.

Methods

Inherited methods


ContrastsLimma$new()

initialize ContrastsLimma

Usage

ContrastsLimma$new(
  model,
  contrasts,
  p.adjust = prolfqua::adjust_p_values,
  model_name = NULL,
  eBayes = TRUE
)

Arguments

model

a ModelLimma object

contrasts

named character vector of contrasts

p.adjust

function to adjust p-values

model_name

name of the contrast method

eBayes

logical, apply limma eBayes moderation (default TRUE). Set to FALSE to return raw/unmoderated statistics suitable for wrapping with ContrastsModeratedDEqMS.


ContrastsLimma$get_contrast_sides()

get both sides of contrasts

Usage

ContrastsLimma$get_contrast_sides()


ContrastsLimma$get_linfct()

get linear functions from contrasts

Usage

ContrastsLimma$get_linfct(global = TRUE, avg = TRUE)

Arguments

global

ignored; kept for compatibility with Contrasts$get_linfct(global = )

avg

logical, also compute avgAbd linfct


ContrastsLimma$get_contrasts()

get table with contrast estimates via limma pipeline

Usage

ContrastsLimma$get_contrasts(all = FALSE)

Arguments

all

ignored; kept for the ContrastsInterface signature. The result always has the same columns

Returns

data.frame with contrasts


ContrastsLimma$clone()

The objects of this class are cloneable with this method.

Usage

ContrastsLimma$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples


istar <- sim_lfq_data_protein_config(n_proteins = 50)
#> `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 82 rows with NA response for feature and sample combinations absent from the input.
lProt <- LFQData$new(istar$data, istar$config)
lProt$rename_response("transformedIntensity")

strat <- strategy_limma("transformedIntensity ~ group_")
mod_limma <- build_model_limma(lProt, strat)
#> fit (limma): 1 singular fits (e.g. VUnZ6o~1614): coefficients not estimable (Partial NA coefficients)
#> fit (limma): 82 missing responses dropped (e.g. 0EfVhX~7161, 0m5WN4~3543, 7QuTub~5556, 7cbcrd~0495, 9VUkAq~8655, ...): NA response (missing observation) left out of the fit
#> See $provenance().

Contr <- c("dil.b_vs_a" = "group_A - group_Ctrl")
contr_limma <- ContrastsLimma$new(mod_limma, Contr)
res <- contr_limma$get_contrasts()
head(res)
#> # A tibble: 6 × 16
#>   modelName estimate_type protein_Id  contrast     diff      FDR
#>   <chr>     <chr>         <chr>       <chr>       <dbl>    <dbl>
#> 1 limma     observed      0EfVhX~7161 dil.b_vs_a  3.00  0.000699
#> 2 limma     observed      0m5WN4~3543 dil.b_vs_a  0.222 0.835   
#> 3 limma     observed      76k03k~9735 dil.b_vs_a  0.509 0.835   
#> 4 limma     observed      7QuTub~5556 dil.b_vs_a -1.22  0.439   
#> 5 limma     observed      7cbcrd~0495 dil.b_vs_a  1.38  0.547   
#> 6 limma     observed      7soopj~3451 dil.b_vs_a  0.822 0.588   
#> # ℹ 10 more variables: std.error.unmoderated <dbl>, df.unmoderated <dbl>,
#> #   std.error <dbl>, statistic <dbl>, p.value <dbl>, sigma <dbl>, df <dbl>,
#> #   conf.low <dbl>, conf.high <dbl>, avgAbd <dbl>
stopifnot(all(c("diff", "FDR", "p.value", "statistic") %in% colnames(res)))

# Compare with prolfqua's own pipeline
modelFunction <- strategy_lm("transformedIntensity ~ group_")
mod <- build_model(lProt, modelFunction)
#> fit (Model): 1 singular fits (e.g. VUnZ6o~1614): coefficients not estimable or fewer than 2 residual df
#> fit (Model): 82 missing responses dropped (e.g. 0EfVhX~7161, 0m5WN4~3543, 7QuTub~5556, 7cbcrd~0495, 9VUkAq~8655, ...): NA response (missing observation) left out of the fit
#> See $provenance().
contr_prolfqua <- Contrasts$new(mod, Contr)
res_prolfqua <- contr_prolfqua$get_contrasts()

# fold changes should be very similar
merged <- dplyr::inner_join(
  dplyr::select(res, protein_Id, diff_limma = diff),
  dplyr::select(res_prolfqua, protein_Id, diff_prolfqua = diff),
  by = "protein_Id")
stopifnot(cor(merged$diff_limma, merged$diff_prolfqua, use = "complete.obs") > 0.99)

# Plotter works
pl <- contr_limma$get_Plotter()

# to_wide works
wide <- contr_limma$to_wide()
head(wide)
#> # A tibble: 6 × 5
#>   protein_Id  diff.dil.b_vs_a p.value.dil.b_vs_a FDR.dil.b_vs_a
#>   <chr>                 <dbl>              <dbl>          <dbl>
#> 1 0EfVhX~7161           3.00           0.0000143       0.000699
#> 2 0m5WN4~3543           0.222          0.763           0.835   
#> 3 76k03k~9735           0.509          0.455           0.835   
#> 4 7QuTub~5556          -1.22           0.0969          0.439   
#> 5 7cbcrd~0495           1.38           0.151           0.547   
#> 6 7soopj~3451           0.822          0.228           0.588   
#> # ℹ 1 more variable: statistic.dil.b_vs_a <dbl>

# merge_contrasts_results works
Contr2 <- c("dil.b_vs_a" = "group_A - group_Ctrl")
imp <- ContrastsLMImputeFacade$new(lProt, "~ group_", Contr2)$contrast
#> fit (ModelImputed): 1 refit at the limit of detection (e.g. VUnZ6o~1614): fit failed, singular or missing a group; missing responses imputed at the LOD
#> fit (ModelImputed): 73 missing responses dropped (e.g. 0EfVhX~7161, 0m5WN4~3543, 7QuTub~5556, 7cbcrd~0495, 9VUkAq~8655, ...): NA response (missing observation) left out of the fit
#> See $provenance().
merged_res <- merge_contrasts_results(contr_limma, imp)