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

mixed_anova(
data,
Y_value,
Fixed_Factor,
Random_Factor,
Df_method = "Kenward-Roger",
SS_method = "II",
...
)

## 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".

Random_Factor

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

Df_method

method for calculating degrees of freedom. Default is Kenward-Roger, can be changed to "Satterthwaite".

SS_method

type of sum of square, default is type II, can be changed to "I", "III", "1" or "2", or others.

...

any additional arguments to pass on to lmer if required.

## Value

ANOVA table of class "anova" and "data.frame".

## 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. This is then passes on the model to anova and provides the ANOVA table with F and P values. It produces a type II sum of squares ANOVA table with Kenward-Roger approximation for degrees of freedom (as implemented in lmerTest) package. It requires a data table, one dependent variable (Y_value), one or more independent variables (Fixed_Factor), and at least one random factor (Random_Factor). These should match names of variables in the long-format data table exactly. This function is related to mixed_model.

More than one fixed factors can be provided as a vector (e.g. c("A", "B")). A full model with interaction term is fitted. This means when Y_value = Y, Fixed_factor = c("A", "B"), Random_factor = "R" are entered as arguments, these are passed on as Y ~ A*B + (1|R) (which is equivalent to Y ~ A + B + A:B + (1|R)). For simplicity, only random intercepts are fitted ((1|R)).

## Examples

#Usage with one fixed (Student) and random factor (Experiment)
mixed_anova(data = data_doubling_time,
Y_value = "Doubling_time",
Fixed_Factor = "Student",
Random_Factor = "Experiment")
#> boundary (singular) fit: see help('isSingular')
#> Type II Analysis of Variance Table with Kenward-Roger's method
#>         Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
#> Student 16.824  1.8694     9    18  0.4725 0.8744

#two fixed factors provided as a vector
mixed_anova(data = data_cholesterol,
Y_value = "Cholesterol",
Fixed_Factor = c("Treatment", "Hospital"),
Random_Factor = "Subject")
#> Type II Analysis of Variance Table with Kenward-Roger's method
#>                     Sum Sq Mean Sq NumDF DenDF F value    Pr(>F)
#> Treatment          1968.38 1968.38     1    20 46.2485 1.301e-06 ***
#> Hospital            131.43   32.86     4    20  0.7720 0.5561366
#> Treatment:Hospital 1482.35  370.59     4    20  8.7072 0.0003066 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1