applies contrast computation using lmerTest::contest function

my_contest(model, linfct, ddf = c("Satterthwaite", "Kenward-Roger"))

Arguments

linfct

linear function

ddf

method to determine denominator degrees of freedom

m

mixed effects model

Examples


mb <- sim_make_model_lmer("interaction")
#> creating sampleName from fileName column
#> Warning: no nr_children column specified in the data, adding column nr_children and setting to 1.
#> completing cases
#> 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.
#> Joining with `by = join_by(protein_Id)`
summary(mb)
#> Linear mixed model fit by REML. t-tests use Satterthwaite's method [
#> lmerModLmerTest]
#> Formula: 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"
my_contest(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
my_contest(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
if(require(multcomp)){
my_glht(mb, linfct$linfct_factors)
my_glht(mb, linfct$linfct_interactions)
}
#> Warning: USE ONLY WITH LM models lmerModLmerTest
#> Warning: USE ONLY WITH LM models lmerModLmerTest
#> # A tibble: 4 × 10
#>   contrast          null.value estimate std.error statistic adj.p.value conf.low
#>   <chr>                  <dbl>    <dbl>     <dbl>     <dbl>       <dbl>    <dbl>
#> 1 TreatmentA:Backg…          0     16.8      1.01      16.7           0     14.8
#> 2 TreatmentA:Backg…          0     26.2      1.01      26.0           0     24.2
#> 3 TreatmentB:Backg…          0     22.7      1.01      22.6           0     20.8
#> 4 TreatmentB:Backg…          0     22.8      1.01      22.6           0     20.8
#> # ℹ 3 more variables: conf.high <dbl>, df <dbl>, sigma <dbl>
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: 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')
#>