HLM_summary {bruceR} | R Documentation |
lmer
and glmer
models).Nice report of Hierarchical Linear Model (HLM), also known as Multilevel Linear Model (MLM) or Linear Mixed Model (LMM). HLM, MLM, or LMM (the same) refers to a model with nested data (e.g., Level-1: participants, Level-2: city; or Level-1: repeated-measures within a participant, Level-2: participants).
HLM_summary( model = NULL, level2.predictors = NULL, vartypes = NULL, test.rand = FALSE, nsmall = 3, ... )
model |
A model fitted by |
level2.predictors |
[only for *** Example: *** If there is no level-2 predictor in the formula of |
vartypes |
[only for |
test.rand |
[only for |
nsmall |
Number of decimal places of output. Default is 3. But for some statistics (e.g., R^2, ICC), to provide more precise information, we fix the decimal places to 5. |
... |
Other optional parameters. You may re-define |
Hierarchical Linear Model (HLM), aka. Multilevel Linear Model (MLM) or Linear Mixed Model (LMM), is more complex than General Linear Model (GLM; i.e., OLS regression). Predictor variables at different levels may have five types:
The overall intercept (γ_{00})
Level-1 predictor with fixed slope
Level-1 predictor with random slopes nested with a grouping/clustering variable
Level-2 predictor (e.g., GDP per capita at city level), always with fixed slope unless there is also a level-3 structure.
*** NOTE: the current version of 'HLM_summary'
function does not consider three-levels design, so you may only use this function in two-levels HLM or cross-classified HLM.
Cross-level interaction consisting of level-1 and level-2 predictors
The degrees of freedom (df) of predictor variables in HLM vary across different levels and also depend on the variable types.
However, different software use different estimation methods and thus provide somewhat different dfs, which may be confusing.
Whereas the lmerTest
package in R provides dfs that are estimated by the Satterthwaite's (1946) approximation (i.e., a data-driven approach without defining variable types),
the HLM
software provides dfs that totally depend on the variable types (i.e., a theory-driven approach).
No return value.
Hox, J. J. (2010). Multilevel analysis: Techniques and applications (2nd ed.). New York, NY: Routledge. doi: 10.4324/9780203852279
Nakagawa, S., & Schielzeth, H. (2013). A general and simple method for obtaining R^2 from generalized linear mixed-effects models. Methods in Ecology and Evolution, 4, 133-142. doi: 10.1111/j.2041-210x.2012.00261.x
Xu, R. (2003). Measuring explained variation in linear mixed effects models. Statistics in Medicine, 22, 3527-3541. doi: 10.1002/sim.1572
library(lmerTest) ## Example 1: data from lme4::sleepstudy # (1) 'Subject' is a grouping/clustering variable # (2) 'Days' is a level-1 predictor nested within 'Subject' # (3) No level-2 predictors m1=lmer(Reaction ~ (1 | Subject), data=sleepstudy) m2=lmer(Reaction ~ Days + (1 | Subject), data=sleepstudy) m3=lmer(Reaction ~ Days + (Days | Subject), data=sleepstudy) HLM_summary(m1) HLM_summary(m2) HLM_summary(m3) ## Example 2: data from lmerTest::carrots # (1) 'Consumer' is a grouping/clustering variable # (2) 'Sweetness' is a level-1 predictor # (3) 'Age' and 'Frequency' are level-2 predictors hlm.1=lmer(Preference ~ Sweetness + Age + Frequency + (1 | Consumer), data=carrots) hlm.2=lmer(Preference ~ Sweetness + Age + Frequency + (Sweetness | Consumer) + (1 | Product), data=carrots) HLM_summary(hlm.1, level2.predictors="Consumer: Age + Frequency") HLM_summary(hlm.2, level2.predictors="Consumer: Age + Frequency") anova(hlm.1, hlm.2)