There are four related functions for mixed effects analyses: mixed_model, mixed_anova, mixed_model_slopes, and mixed_anova_slopes.

mixed_model_slopes(
  data,
  Y_value,
  Fixed_Factor,
  Slopes_Factor,
  Random_Factor,
  ...
)

Arguments

data

a data table object, e.g. data.frame or tibble.

Y_value

name of column containing quantitative (dependent) variable, provided within "quotes".

Fixed_Factor

name(s) of categorical fixed factors (independent variables) provided as a vector if more than one or within "quotes".

Slopes_Factor

name of factor to allow varying slopes on.

Random_Factor

name(s) of random factors to allow random intercepts; to be provided as a vector when more than one or within "quotes".

...

any additional arguments to pass on to lmer if required.

Value

This function returns an S4 object of class "lmerModLmerTest".

Details

This function uses lmer to fit a linear mixed effect model and provides the model object, which could be used for post-hoc comparisons. The model object is converted to class lmerModLmerTest object by as_lmerModLmerTest. It requires a data table, one dependent variable (Y_value), one or more independent variables (Fixed_Factor). Exactly one random factor (Random_Factor) and Slope_Factor should be provided. This function is related to mixed_anova_slopes. Output of this function can be used with posthoc_Pairwise, posthoc_Levelwise and posthoc_vsRef, or with emmeans.

More than one fixed factors can be provided as a vector (e.g. c("A", "B")). A full model with interaction term is fitted with one term each for varying slopes and intercepts. This means when Y_value = Y, Fixed_factor = c("A", "B"), Slopes_Factor = "S", Random_factor = "R" are entered as arguments, these are passed on as Y ~ A*B + (S|R) (which is equivalent to Y ~ A + B + A:B + (S|R)). In this experimental implementation, random slopes and intercepts are fitted ((Slopes_Factor|Random_Factor)). Only one term each is allowed for Slopes_Factor and Random_Factor.

Examples

#two fixed factors as a vector, 
#exactly one slope factor and random factor
mod <- mixed_model_slopes(data = data_2w_Tdeath,
Y_value = "PI",
Fixed_Factor = c("Genotype", "Time"),
Slopes_Factor = "Time",
Random_Factor = "Experiment")
#> boundary (singular) fit: see help('isSingular')
#get summary
summary(mod)
#> Linear mixed model fit by REML. t-tests use Satterthwaite's method [
#> lmerModLmerTest]
#> Formula: PI ~ Genotype * Time + (Time | Experiment)
#>    Data: data_2w_Tdeath
#> 
#> REML criterion at convergence: 132.9
#> 
#> Scaled residuals: 
#>      Min       1Q   Median       3Q      Max 
#> -1.74243 -0.50144  0.01573  0.55592  1.88600 
#> 
#> Random effects:
#>  Groups     Name        Variance Std.Dev. Corr
#>  Experiment (Intercept)  7.372   2.715        
#>             Timet300     1.231   1.110    1.00
#>  Residual               24.327   4.932        
#> Number of obs: 24, groups:  Experiment, 6
#> 
#> Fixed effects:
#>                     Estimate Std. Error      df t value Pr(>|t|)    
#> (Intercept)           23.841      2.299  12.624  10.373 1.53e-07 ***
#> GenotypeKO           -16.918      2.848  15.000  -5.941 2.71e-05 ***
#> Timet300              13.563      2.883  14.912   4.704 0.000287 ***
#> GenotypeKO:Timet300  -10.293      4.027  15.000  -2.556 0.021937 *  
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Correlation of Fixed Effects:
#>             (Intr) GntyKO Tmt300
#> GenotypeKO  -0.619              
#> Timet300    -0.536  0.494       
#> GntyKO:T300  0.438 -0.707 -0.698
#> optimizer (nloptwrap) convergence code: 0 (OK)
#> boundary (singular) fit: see help('isSingular')
#>