Skip to contents

Fits the model of model_strategy once per subject (by default per protein) and returns the fits with their status. Failed fits are kept as rows without a model. build_contrast_analysis() calls it for the per-subject backends.

Usage

build_model(
  data,
  model_strategy,
  subject_id = if (inherits(data, "LFQData")) {
     data$subject_id()
 } else {
    
    "protein_Id"
 },
  model_name = model_strategy$model_name
)

Arguments

data

data - a data frame or LFQData object

model_strategy

model strategy object (e.g. from strategy_lmer or strategy_lm)

subject_id

grouping variable

model_name

model name

Value

a object of class Model

See also

strategy_lmer, strategy_lm

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_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()

Examples

D <- prolfqua::sim_lfq_data_peptide_config(n_proteins = 20, weight_missing = 0.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, mean, N, avg_peptide_abd, Replicate.
#> setup_analysis: added 68 rows with NA response for feature and sample combinations absent from the input.
D$data$abundance |> is.na() |> sum()
#> [1] 68
D <- prolfqua::sim_lfq_data_peptide_config(n_proteins = 20, weight_missing = 0.1, seed =3)
#> `protein_Id`: columns `proteinID`, `idtype2` united with separator '~'.
#> creating sampleName from file_name column
#> setup_analysis: dropped 6 unconfigured columns: average_prot_abundance, sd, mean, N, avg_peptide_abd, Replicate.
#> setup_analysis: added 59 rows with NA response for feature and sample combinations absent from the input.
D$data$abundance |> is.na() |> sum()
#> [1] 59
model_name <- "f_condtion_r_peptide"
formula_randomPeptide <-
  strategy_lmer("abundance  ~ group_ + (1 | peptide_Id) + (1 | sampleName)",
   model_name = model_name)


mod <- prolfqua::build_model(
 D$data,
 formula_randomPeptide,
 model_name = model_name,
 subject_id = D$config$hierarchy_keys_depth())
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> Warning: fit (f_condtion_r_peptide): 6 fits failed (e.g. 0GRprF~7339, AZPG26~9461, NNASGK~6205, quTD7H~9280, tCZCHm~5708, ...): Error: grouping factors must have > 1 sampled level
#> See $provenance().
#> fit (f_condtion_r_peptide): 14 singular fits (e.g. 4JK499~3111, 7IZdVV~6818, AoNKbb~3497, CibL2O~2149, EnbuYk~7811, ...): coefficients not estimable or fewer than 2 residual df
#> fit (f_condtion_r_peptide): 54 missing responses dropped (e.g. 4JK499~3111, 7IZdVV~6818, CibL2O~2149, EnbuYk~7811, JnEDsz~4232, ...): NA response (missing observation) left out of the fit
#> See $provenance().
aovtable <- mod$get_anova()

mod <- prolfqua::build_model(
 LFQData$new(D$data, D$config),
 formula_randomPeptide,
 model_name = model_name)
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> boundary (singular) fit: see help('isSingular')
#> Warning: fit (f_condtion_r_peptide): 6 fits failed (e.g. 0GRprF~7339, AZPG26~9461, NNASGK~6205, quTD7H~9280, tCZCHm~5708, ...): Error: grouping factors must have > 1 sampled level
#> See $provenance().
#> fit (f_condtion_r_peptide): 14 singular fits (e.g. 4JK499~3111, 7IZdVV~6818, AoNKbb~3497, CibL2O~2149, EnbuYk~7811, ...): coefficients not estimable or fewer than 2 residual df
#> fit (f_condtion_r_peptide): 54 missing responses dropped (e.g. 4JK499~3111, 7IZdVV~6818, CibL2O~2149, EnbuYk~7811, JnEDsz~4232, ...): NA response (missing observation) left out of the fit
#> See $provenance().
head(mod$get_coefficients())
#> # A tibble: 6 × 9
#> # Groups:   protein_Id [2]
#>   protein_Id  factor      Estimate Std..Error    df t.value Pr...t.. isSingular
#>   <chr>       <chr>          <dbl>      <dbl> <dbl>   <dbl>    <dbl> <lgl>     
#> 1 4JK499~3111 (Intercept)   16.4        0.577 16.0   28.4   3.97e-15 TRUE      
#> 2 4JK499~3111 group_B        2.24       0.849 16.0    2.64  1.78e- 2 TRUE      
#> 3 4JK499~3111 group_Ctrl    -3.90       0.849 16.0   -4.59  3.03e- 4 TRUE      
#> 4 7IZdVV~6818 (Intercept)   24.0        1.69   7.95  14.2   6.19e- 7 TRUE      
#> 5 7IZdVV~6818 group_B        0.703      1.60  50.1    0.439 6.63e- 1 TRUE      
#> 6 7IZdVV~6818 group_Ctrl    -0.758      1.60  50.1   -0.473 6.38e- 1 TRUE      
#> # ℹ 1 more variable: nr_coef <int>