An integrated function for fitting a multilevel linear regression (also known as hierarchical linear regression).
This function will no longer be updated. Please use the these functions separately instead: model_summary, interaction_plot,and simple_slope.
lme_multilevel_model_summary(
data,
model = NULL,
response_variable = NULL,
random_effect_factors = NULL,
non_random_effect_factors = NULL,
two_way_interaction_factor = NULL,
three_way_interaction_factor = NULL,
family = NULL,
id = NULL,
estimation_method = "REML",
opt_control = "bobyqa",
na.action = stats::na.omit,
model_summary = TRUE,
interaction_plot = TRUE,
y_lim = NULL,
plot_color = FALSE,
digits = 3,
use_package = "lmerTest",
standardize = NULL,
ci_method = "satterthwaite",
simple_slope = FALSE,
assumption_plot = FALSE,
quite = FALSE,
streamline = FALSE,
return_result = FALSE
)data.frame
lme4 model syntax. Support more complicated model structure from lme4. It is not well-tested to ensure accuracy
DV (i.e., outcome variable / response variable). Length of 1. Support dplyr::select() syntax.
random effect factors (level-1 variable for HLM from a HLM perspective) Factors that need to estimate fixed effect and random effect (i.e., random slope / varying slope based on the id). Support dplyr::select() syntax.
non-random effect factors (level-2 variable from a HLM perspective). Factors only need to estimate fixed effect. Support dplyr::select() syntax.
two-way interaction factors. You need to pass 2+ factor. Support dplyr::select() syntax.
three-way interaction factor. You need to pass exactly 3 factors. Specifying three-way interaction factors automatically included all two-way interactions, so please do not specify the two_way_interaction_factor argument. Support dplyr::select() syntax.
a GLM family. It will passed to the family argument in glmer. See ?glmer for possible options.
the nesting variable (e.g. group, time). Length of 1. Support dplyr::select() syntax.
character. ML or REML default is REML.
default is optim for lme and bobyqa for lmerTest.
default is stats::na.omit. Another common option is na.exclude
print model summary. Required to be TRUE if you want assumption_plot.
generate interaction plot. Default is TRUE
the plot's upper and lower limit for the y-axis. Length of 2. Example: c(lower_limit, upper_limit)
If it is set to TRUE (default is FALSE), the interaction plot will plot with color.
number of digits to round to
Default is lmerTest. Only available for linear mixed effect model. Options are nlme, lmerTest, or lme4('lme4 return similar result as lmerTest except the return model)
The method used for standardizing the parameters. Can be NULL (default; no standardization), "refit" (for re-fitting the model on standardized data) or one of "basic", "posthoc", "smart", "pseudo". See 'Details' in parameters::standardize_parameters()
see options in the Mixed model section in ?parameters::model_parameters()
Slope estimate at ± 1 SD and the mean of the moderator. Uses interactions::sim_slope() in the background.
Generate an panel of plots that check major assumptions. It is usually recommended to inspect model assumption violation visually. In the background, it calls performance::check_model().
suppress printing output
print streamlined output.
If it is set to TRUE (default is FALSE), it will return the model, model_summary, and plot (plot if the interaction term is included)
a list of all requested items in the order of model, model_summary, interaction_plot, simple_slope
fit <- lme_multilevel_model_summary(
data = popular,
response_variable = popular,
random_effect_factors = NULL, # you can add random effect predictors here
non_random_effect_factors = c(extrav,texp),
two_way_interaction_factor = NULL, # you can add two-way interaction plot here
id = class,
simple_slope = FALSE, # you can also request simple slope estimate
assumption_plot = FALSE, # you can also request assumption plot
plot_color = FALSE, # you can also request the plot in color
streamline = FALSE # you can change this to get the least amount of info
)
#>
#>
#> Model Summary
#> Model Type = Linear Mixed Effect Model (fitted using lme4 or lmerTest)
#> Outcome = popular
#> Predictors = extrav, texp
#>
#> Model Estimates
#> ───────────────────────────────────────────────────────────────────────────────────────────────────────
#> Parameter Coefficient SE t df Effects Group p 95% CI
#> ───────────────────────────────────────────────────────────────────────────────────────────────────────
#> (Intercept) 1.035 0.208 4.985 238.069 fixed 0.000 *** [0.626, 1.443]
#> extrav 0.504 0.020 24.976 1961.702 fixed 0.000 *** [0.464, 0.543]
#> texp 0.099 0.011 9.385 101.830 fixed 0.000 *** [0.078, 0.120]
#> SD (Intercept) 0.652 NaN NaN NaN random class NaN [NaN, NaN]
#> SD (Observations) 0.965 NaN NaN NaN random Residual NaN [NaN, NaN]
#> ───────────────────────────────────────────────────────────────────────────────────────────────────────
#> *** p < 0.001, ** p < 0.01, * p < 0.05, . p < 0.1
#>
#> Goodness of Fit
#> ────────────────────────────────────────────────────────────────────────────────
#> AIC AICc BIC R²_conditional R²_marginal ICC RMSE σ
#> ────────────────────────────────────────────────────────────────────────────────
#> 5786.188 5786.219 5814.193 0.500 0.272 0.314 0.942 0.965
#> ────────────────────────────────────────────────────────────────────────────────
#>
#> Model Assumption Check
#> OK: Model is converged
#> OK: No singularity is detected
#> Warning: Autocorrelated residuals detected (p < .001).
#> Warning: Non-normality of residuals detected (p = 0.001).
#> OK: No outliers detected.
#> - Based on the following method and threshold: cook (0.839).
#> - For variable: (Whole model)
#>
#> OK: Error variance appears to be homoscedastic (p = 0.924).
#> OK: No multicolinearity detected (VIF < 5)
#>