mixed_model_slopes {grafify} | R Documentation |
Model from a linear mixed effects model with varying slopes
Description
One of four related functions for mixed effects analyses (based on lmer
and as_lmerModLmerTest
) to get a linear model for downstream steps, or an ANOVA table.
-
mixed_model
-
mixed_anova
-
mixed_model_slopes
-
mixed_anova_slopes
.
Usage
mixed_model_slopes(
data,
Y_value,
Fixed_Factor,
Slopes_Factor,
Random_Factor,
AvgRF = TRUE,
...
)
Arguments
data |
a data table object, e.g. data.frame or tibble. |
Y_value |
name of column containing quantitative (dependent) variable, provided within "quotes". The following transformations are permitted: "log(Y_value)", "log(Y_value + c)" where c a positive number, "logit(Y_value)" or "logit(Y_value/100)" which may be useful when |
Fixed_Factor |
name(s) of categorical fixed factors (independent variables) provided within quotes (e.g., "A") or as a vector if more than one (e.g., c("A", "B"). If a numeric variable is used, transformations similar to |
Slopes_Factor |
name of factor to allow varying slopes on. One one variable is allowed. |
Random_Factor |
name(s) of random factors to allow random intercepts; to be provided within quotes (e.g., "R") or as a vector when more than one (e.g., c("R1", "R2")). Only one variable is allowed. |
AvgRF |
this is a new argument since v5.0.0. The default |
... |
any additional arguments to pass on to |
Details
These functions require 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. Since v5.0.0, if AvgRF = TRUE
, the response variable is averaged over levels of the fixed and random factors (to collapse replicate observations) and reduce the number of denominator degrees of freedom. If you do not want to do this, set AvgRF = FALSE
.
For more advanced models with slopes and intercept, use mixed_model
or mixed_anova
using the Formula
argument.
Outputs of mixed_model
and mixed_model_slopes
can be used for post-hoc comparisons with posthoc_Pairwise
, posthoc_Levelwise
, posthoc_vsRef
, posthoc_Trends_Pairwise
, posthoc_Trends_Levelwise
and posthoc_Trends_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.
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)
).
In mixed_model_slopes
and mixed_anova_slopes
, the following kind of formula is used: 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
.
Value
This function returns an S4 object of class "lmerModLmerTest".
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")
#get summary
summary(mod)