Description Usage Arguments Details Value References See Also Examples
View source: R/bruceR_stats_04_regress.R
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., Level1: participants, Level2: city; or Level1: repeatedmeasures within a participant, Level2: participants).
1 2 3 4 5 6 7 8 9 
model 
A model fitted by 
level2.predictors 
[only for *** Example: *** If there is no level2 predictor in the formula of 
vartypes 
[only for 
test.rand 
[only for 
digits, 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 redefine 
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})
Level1 predictor with fixed slope
Level1 predictor with random slopes nested with a grouping/clustering variable
Level2 predictor (e.g., GDP per capita at city level), always with fixed slope unless there is also a level3 structure.
*** NOTE: the current version of 'HLM_summary'
function does not consider threelevels design, so you may only use this function in twolevels HLM or crossclassified HLM.
Crosslevel interaction consisting of level1 and level2 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 datadriven approach without defining variable types),
the HLM
software provides dfs that totally depend on the variable types (i.e., a theorydriven 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 mixedeffects models. Methods in Ecology and Evolution, 4, 133142. doi: 10.1111/j.2041210x.2012.00261.x
Xu, R. (2003). Measuring explained variation in linear mixed effects models. Statistics in Medicine, 22, 35273541. doi: 10.1002/sim.1572
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24  library(lmerTest)
## Example 1: data from lme4::sleepstudy
# (1) 'Subject' is a grouping/clustering variable
# (2) 'Days' is a level1 predictor nested within 'Subject'
# (3) No level2 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 level1 predictor
# (3) 'Age' and 'Frequency' are level2 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)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.