applies contrast computation using lmerTest::contest function
Source:R/tidyMS_contrasts.R
compute_lmer_contrast.Rdapplies contrast computation using lmerTest::contest function
Usage
compute_lmer_contrast(model, linfct, ddf = c("Satterthwaite", "Kenward-Roger"))See also
Other modelling:
AnovaExtractor,
Contrasts,
ContrastsDEqMSFacade,
ContrastsFirth,
ContrastsFirthFacade,
ContrastsLMFacade,
ContrastsLMImputeFacade,
ContrastsLMMissingFacade,
ContrastsLimma,
ContrastsLimmaFacade,
ContrastsLmerFacade,
ContrastsMissing,
ContrastsModerated,
ContrastsModeratedDEqMS,
ContrastsPlotter,
ContrastsRLMFacade,
ContrastsROPECA,
ContrastsROPECAFacade,
ContrastsTable,
INTERNAL_FUNCTIONS_BY_FAMILY,
LR_test(),
Model,
ModelFirth,
ModelLimma,
StrategyLM,
StrategyLimma,
StrategyLmer,
StrategyLogistf,
StrategyRLM,
build_contrast_analysis(),
build_model(),
build_model_glm_peptide(),
build_model_glm_protein(),
build_model_impute(),
build_model_limma(),
build_model_logistf(),
compute_borrowed_variance(),
compute_contrast(),
contrasts_fisher_exact(),
get_anova_df(),
get_complete_model_fit(),
get_p_values_pbeta(),
group_label(),
impute_refit_singular(),
isSingular_lm(),
linfct_all_possible_contrasts(),
linfct_factors_contrasts(),
linfct_from_model(),
linfct_matrix_contrasts(),
merge_contrasts_results(),
model_analyse(),
model_summary(),
moderated_p_deqms(),
moderated_p_deqms_long(),
moderated_p_limma(),
moderated_p_limma_long(),
new_lm_imputed(),
pivot_model_contrasts_2_Wide(),
plot_lmer_peptide_predictions(),
sim_build_models_lm(),
sim_build_models_lmer(),
sim_build_models_logistf(),
sim_make_model_lm(),
sim_make_model_lmer(),
strategy_limma(),
strategy_logistf(),
summary_ROPECA_median_p.scaled()
Examples
mb <- sim_make_model_lmer("interaction")
#> Warning: Unknown or uninitialised column: `nr_peptides`.
#> creating sampleName from fileName column
#> completing cases
#> completing cases done
#> setup done
#> 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: There were 4 warnings in `dplyr::mutate()`.
#> The first warning was:
#> ℹ In argument: `linear_model = purrr::map(data, model_strategy$model_fun, pb =
#> pb)`.
#> ℹ In group 2: `protein_Id = "7cbcrd~5725"`.
#> Caused by warning in `value[[3L]]()`:
#> ! WARN :Error: grouping factors must have > 1 sampled level
#> ℹ Run `dplyr::last_dplyr_warnings()` to see the 3 remaining warnings.
summary(mb)
#> Linear mixed model fit by REML. t-tests use Satterthwaite's method [
#> lmerModLmerTest]
#> Formula: self$formula
#> Data: x
#>
#> REML criterion at convergence: 193.5
#>
#> Scaled residuals:
#> Min 1Q Median 3Q Max
#> -1.69297 -0.80789 0.02554 0.77048 1.74487
#>
#> Random effects:
#> Groups Name Variance Std.Dev.
#> sampleName (Intercept) 0.000 0.000
#> peptide_Id (Intercept) 2.198 1.483
#> Residual 3.403 1.845
#> Number of obs: 48, groups: sampleName, 16; peptide_Id, 3
#>
#> Fixed effects:
#> Estimate Std. Error df t value Pr(>|t|)
#> (Intercept) 16.7976 1.0082 3.1878 16.662 0.00033 ***
#> TreatmentB 5.9436 0.7531 42.0000 7.893 7.91e-10 ***
#> BackgroundZ 9.3826 0.7531 42.0000 12.459 1.07e-15 ***
#> TreatmentB:BackgroundZ -9.3668 1.0650 42.0000 -8.795 4.48e-11 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> Correlation of Fixed Effects:
#> (Intr) TrtmnB BckgrZ
#> TreatmentB -0.373
#> BackgroundZ -0.373 0.500
#> TrtmntB:BcZ 0.264 -0.707 -0.707
#> optimizer (nloptwrap) convergence code: 0 (OK)
#> boundary (singular) fit: see help('isSingular')
#>
linfct <- linfct_from_model(mb)
names(linfct)
#> [1] "linfct_factors" "linfct_interactions"
compute_lmer_contrast(mb, linfct$linfct_factors)
#> # A tibble: 4 × 9
#> lhs estimate std.error df statistic conf.low conf.high p.value sigma
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Backgroun… 19.8 0.935 2.37 21.1 16.3 23.3 9.42e-4 1.84
#> 2 Backgroun… 24.5 0.935 2.37 26.2 21.0 27.9 5.69e-4 1.84
#> 3 TreatmentA 21.5 0.935 2.37 23.0 18.0 25.0 7.74e-4 1.84
#> 4 TreatmentB 22.7 0.935 2.37 24.3 19.3 26.2 6.76e-4 1.84
compute_lmer_contrast(mb, linfct$linfct_interactions)
#> # A tibble: 4 × 9
#> lhs estimate std.error df statistic conf.low conf.high p.value sigma
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Treatment… 16.8 1.01 3.19 16.7 13.7 19.9 3.30e-4 1.84
#> 2 Treatment… 26.2 1.01 3.19 26.0 23.1 29.3 8.08e-5 1.84
#> 3 Treatment… 22.7 1.01 3.19 22.6 19.6 25.8 1.26e-4 1.84
#> 4 Treatment… 22.8 1.01 3.19 22.6 19.7 25.9 1.26e-4 1.84
length(mb@beta)
#> [1] 4
lmerTest::contest(mb, c( 0 ,1 , 0 , 0),joint = FALSE)
#> Estimate Std. Error df t value lower upper Pr(>|t|)
#> 1 5.943641 0.7530708 42 7.892539 4.423882 7.463399 7.909703e-10
summary(mb)
#> Linear mixed model fit by REML. t-tests use Satterthwaite's method [
#> lmerModLmerTest]
#> Formula: self$formula
#> Data: x
#>
#> REML criterion at convergence: 193.5
#>
#> Scaled residuals:
#> Min 1Q Median 3Q Max
#> -1.69297 -0.80789 0.02554 0.77048 1.74487
#>
#> Random effects:
#> Groups Name Variance Std.Dev.
#> sampleName (Intercept) 0.000 0.000
#> peptide_Id (Intercept) 2.198 1.483
#> Residual 3.403 1.845
#> Number of obs: 48, groups: sampleName, 16; peptide_Id, 3
#>
#> Fixed effects:
#> Estimate Std. Error df t value Pr(>|t|)
#> (Intercept) 16.7976 1.0082 3.1878 16.662 0.00033 ***
#> TreatmentB 5.9436 0.7531 42.0000 7.893 7.91e-10 ***
#> BackgroundZ 9.3826 0.7531 42.0000 12.459 1.07e-15 ***
#> TreatmentB:BackgroundZ -9.3668 1.0650 42.0000 -8.795 4.48e-11 ***
#> ---
#> Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> Correlation of Fixed Effects:
#> (Intr) TrtmnB BckgrZ
#> TreatmentB -0.373
#> BackgroundZ -0.373 0.500
#> TrtmntB:BcZ 0.264 -0.707 -0.707
#> optimizer (nloptwrap) convergence code: 0 (OK)
#> boundary (singular) fit: see help('isSingular')
#>