Skip to contents

Compares a complete and a reduced model per subject with a likelihood ratio test, for example to test a factor with several levels at once. Both model tables come from build_model() on the same data.

Usage

lr_test(
  complete_models,
  model_name,
  complete_models_int,
  model_name_int,
  subject_id = "protein_Id",
  path = NULL
)

Arguments

complete_models

table with models (see build model)

model_name

name of model

complete_models_int

reduced model

model_name_int

name of reduced model

subject_id

subject id typically Accession or protein_Id

path

default NULL, set to a directory if you need to write diagnostic plots.

Value

a tibble with one row per subject: subject_id and likelihood_ratio_test.pValue, the p-value of the likelihood ratio test of the reduced against the complete model.

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(), compute_borrowed_variance_limma(), df.residual.rfit_prolfqua(), group_label(), impute_from_model(), impute_refit_singular(), list_facades(), lookup_facade(), 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

data_2Factor <- prolfqua::sim_lfq_data_2factor_config(
 n_proteins = 200,
 with_missing = TRUE,
 weight_missing = 1)
#> `protein_Id`: columns `proteinID`, `idtype2` united with separator '~'.
#> creating sampleName from file_name column
#> setup_analysis: dropped 6 unconfigured columns: average_prot_abundance, sd, group, mean, N, Replicate.
#> setup_analysis: added 1087 rows with NA response for feature and sample combinations absent from the input.

pMerged <- LFQData$new(data_2Factor$data, data_2Factor$config)

pMerged$response()
#> [1] "abundance"
pMerged$factors()
#> # A tibble: 16 × 4
#>    sample  sampleName Treatment Background
#>    <chr>   <chr>      <chr>     <chr>     
#>  1 A_V1    A_V1       A         X         
#>  2 A_V2    A_V2       A         X         
#>  3 A_V3    A_V3       A         X         
#>  4 A_V4    A_V4       A         X         
#>  5 B_V1    B_V1       B         X         
#>  6 B_V2    B_V2       B         X         
#>  7 B_V3    B_V3       B         X         
#>  8 B_V4    B_V4       B         X         
#>  9 C_V1    C_V1       B         Z         
#> 10 C_V2    C_V2       B         Z         
#> 11 C_V3    C_V3       B         Z         
#> 12 C_V4    C_V4       B         Z         
#> 13 Ctrl_V1 Ctrl_V1    A         Z         
#> 14 Ctrl_V2 Ctrl_V2    A         Z         
#> 15 Ctrl_V3 Ctrl_V3    A         Z         
#> 16 Ctrl_V4 Ctrl_V4    A         Z         

formula_condition_and_Batches <-
  prolfqua::strategy_lm("abundance ~ Treatment + Background")
modCB <- prolfqua::build_model(
  pMerged,
  formula_condition_and_Batches)
#> Warning: fit (Model): 12 fits failed (e.g. G01Esv~7982, HAAYQO~5909, LMQBev~7768, N1vPxG~0817, a0UeCf~0004, ...): Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#> See $provenance().
#> fit (Model): 13 singular fits (e.g. Br6sVH~3679, ESsn24~7142, HvIpHG~5437, J4wNKf~3190, OOEm0O~6680, ...): coefficients not estimable or fewer than 2 residual df
#> fit (Model): 925 missing responses dropped (e.g. 0ZHbvZ~4125, 0lCgkE~2864, 0m5WN4~1168, 0vgFfT~5498, 1HZ2jt~5236, ...): NA response (missing observation) left out of the fit
#> See $provenance().

formula_condition <-
  prolfqua::strategy_lm("abundance ~ Treatment")
modC <- prolfqua::build_model(
  pMerged,
  formula_condition)
#> Warning: fit (Model): 8 fits failed (e.g. N1vPxG~0817, a0UeCf~0004, cp9zgr~5124, guMc2e~7211, h9LKdP~0538, ...): Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]): contrasts can be applied only to factors with 2 or more levels
#> See $provenance().
#> fit (Model): 9 singular fits (e.g. Br6sVH~3679, G01Esv~7982, HAAYQO~5909, J4wNKf~3190, ZI2MGy~3165, ...): coefficients not estimable or fewer than 2 residual df
#> fit (Model): 976 missing responses dropped (e.g. 0ZHbvZ~4125, 0lCgkE~2864, 0m5WN4~1168, 0vgFfT~5498, 1HZ2jt~5236, ...): NA response (missing observation) left out of the fit
#> See $provenance().

tmp <- lr_test(modCB$model_df, "modCB", modC$model_df, "modB")
hist(tmp$likelihood_ratio_test.pValue)