
Grad Hlm
- 30 installs
- 223 repo stars
- Updated June 6, 2026
- asgard-ai-platform/skills
grad-hlm is a Claude skill that applies Hierarchical Linear Modeling to analyze nested data with random intercepts and slopes, ICC, and cross-level interactions.
About
This skill applies Hierarchical Linear Modeling (multilevel modeling) to analyze nested data structures such as students within schools or repeated measures within individuals. A developer uses it to partition variance across levels via ICC, fit random-intercept and random-slope models, and test cross-level interactions. It outputs a data-structure summary, ICC, fixed and random effects tables, and model comparison statistics.
- Analyzes nested data with random intercepts and slopes
- Computes ICC and partitions variance into within- and between-group components
- Tests cross-level interactions where group factors moderate individual effects
Grad Hlm by the numbers
- 30 all-time installs (skills.sh)
- Ranked #1,108 of 2,064 Data Science & ML skills by installs in the Skillselion catalog
- Data as of Aug 2, 2026 (Skillselion catalog sync)
grad-hlm capabilities & compatibility
- Capabilities
- multilevel modeling · variance partitioning · statistical analysis
- Use cases
- data analysis · research
What grad-hlm says it does
Hierarchical Linear Modeling (HLM), also called multilevel modeling, accounts for the nested structure of data where lower-level units (e.g., students, employees) are clustered within higher-level uni
IRON LAW: Ignoring nested structure when ICC is non-trivial produces UNDERESTIMATED standard errors
npx skills add https://github.com/asgard-ai-platform/skills --skill grad-hlmAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 30 |
|---|---|
| repo stars | ★ 223 |
| Last updated | June 6, 2026 |
| Repository | asgard-ai-platform/skills ↗ |
What it does
Model nested data with random intercepts and slopes to partition variance across levels and test cross-level interactions.
Who is it for?
Analyzing nested or longitudinal data with non-trivial ICC and cross-level moderators
Skip if: Non-nested data, negligible clustering, fewer than 20 Level-2 units, or crossed (not hierarchical) structures
When should I use this skill?
When data has individuals nested in groups, you need to partition variance across levels, or ask about ICC
What you get
A multilevel model with ICC, fixed and random effects, and variance partitioned across levels
By the numbers
- 4-step methodology (null model, random intercept, cross-level, evaluate)
- ICC rule of thumb > 0.05
- minimum ~20 Level-2 units for stable estimates
Files
階層線性模型 (Hierarchical Linear Modeling)
Overview
Hierarchical Linear Modeling (HLM), also called multilevel modeling, accounts for the nested structure of data where lower-level units (e.g., students, employees) are clustered within higher-level units (e.g., schools, firms). By partitioning variance into within-group and between-group components and allowing intercepts and slopes to vary randomly, HLM produces unbiased estimates and correct standard errors.
When to Use
- Data has a hierarchical or nested structure (individuals within groups)
- Intra-class correlation (ICC) is non-trivial (rule of thumb: ICC > 0.05)
- Research questions involve cross-level interactions (group-level moderators of individual-level effects)
- Repeated measures or longitudinal data nested within subjects (growth models)
When NOT to Use
- Data are not nested or clustering is negligible (ICC near zero)
- Number of groups is very small (fewer than 20 Level-2 units)
- Interest is purely in fixed effects with no group-level predictors
- The nesting structure is crossed, not hierarchical (use crossed random effects instead)
Assumptions
IRON LAW: Ignoring nested structure when ICC is non-trivial produces
UNDERESTIMATED standard errors — leading to inflated Type I error rates.
OLS treats clustered observations as independent, overstating precision.Key assumptions: 1. Level-1 residuals are normally distributed with constant variance within groups 2. Random effects (intercepts, slopes) are normally distributed across groups 3. Random effects are independent of Level-1 and Level-2 predictors (unless modeled) 4. Sufficient number of Level-2 units for stable variance component estimation
Methodology
Step 1 — Estimate the Null Model (Unconditional)
Run an intercept-only model to compute ICC = τ₀₀ / (τ₀₀ + σ²). This tells you what proportion of total variance lies between groups. If ICC is near zero, HLM may be unnecessary.
Step 2 — Add Level-1 Predictors (Random Intercept Model)
Include individual-level predictors with a random intercept. Group-mean center Level-1 predictors if the research question distinguishes within-group from between-group effects. See references/ for centering decisions and equations.
Step 3 — Add Level-2 Predictors and Cross-Level Interactions
Include group-level predictors to explain between-group variance in intercepts. Add cross-level interactions to test whether group characteristics moderate individual-level slopes. Allow slopes to vary randomly if theoretically justified.
Step 4 — Evaluate Model and Report
Compare models using deviance (-2LL), AIC, BIC. Report fixed effects with robust standard errors, variance components, and proportion of variance explained at each level.
Output Format
## HLM Analysis: [Study Title]
### Data Structure
| Level | Unit | N |
|-------|------|---|
| Level 1 | [individual] | xxx |
| Level 2 | [group] | xxx |
### ICC (Null Model)
- ICC = x.xx (x% of variance is between groups)
### Fixed Effects
| Predictor | Level | γ | S.E. | t | p-value |
|-----------|-------|---|------|---|---------|
| Intercept | — | x.xx | x.xx | x.xx | x.xx |
| [L1 var] | 1 | x.xx | x.xx | x.xx | x.xx |
| [L2 var] | 2 | x.xx | x.xx | x.xx | x.xx |
| [Cross-level] | 1×2 | x.xx | x.xx | x.xx | x.xx |
### Random Effects
| Component | Variance | SD | p-value |
|-----------|----------|-----|---------|
| Intercept (τ₀₀) | x.xx | x.xx | x.xx |
| Slope (τ₁₁) | x.xx | x.xx | x.xx |
| Residual (σ²) | x.xx | x.xx | — |
### Model Comparison
| Model | -2LL | AIC | Parameters | Δ deviance (p) |
|-------|------|-----|------------|---------------|
| Null | x.xx | x.xx | x | — |
| Final | x.xx | x.xx | x | x.xx (x.xx) |
### Limitations
- [Note any assumption violations]Gotchas
- Grand-mean centering and group-mean centering answer fundamentally different research questions
- Too few Level-2 units (< 20) yields biased variance component estimates
- Adding random slopes without theoretical justification can cause non-convergence
- Pseudo-R² at Level 2 can be negative if adding Level-1 predictors redistributes variance
- Ignoring Level-3 nesting (students in classrooms in schools) when it exists biases Level-2 estimates
- Multicollinearity between Level-1 and Level-2 predictors inflates standard errors of cross-level interactions
References
- Raudenbush, S. W., & Bryk, A. S. (2002). Hierarchical Linear Models (2nd ed.). Sage.
- Hox, J. J., Moerbeek, M., & van de Schoot, R. (2018). Multilevel Analysis (3rd ed.). Routledge.
- Snijders, T. A. B., & Bosker, R. J. (2012). Multilevel Analysis (2nd ed.). Sage.
Example: 員工工作自主性對工作滿意度的影響——跨層次主管支持調節效果
Scenario
台灣一家人力資源顧問公司 TalentBridge 受委託分析一份問卷資料,資料來自 35 家中型製造業企業、共 892 名正職員工。研究問題:
個人層次的「工作自主性」是否預測「工作滿意度」?公司層次的「主管支持氣候」是否調節這個關係?
研究者懷疑員工間的相似性部分來自公司文化,因此擔心 OLS 迴歸會低估標準誤。
資料結構:
- Level 1(個人):工作自主性(
autonomy,1-7 分)、年資(tenure,年)、工作滿意度(satisf,1-7 分,依變數) - Level 2(公司):主管支持氣候(
mgr_climate,公司平均分、grand-mean centered)、公司規模(firm_size,log 員工數)
---
Analysis
Step 1 — Null Model (Unconditional)
僅含截距,估計組間變異:
Level 1: satisf_ij = β₀j + r_ij
Level 2: β₀j = γ₀₀ + u₀j估計結果:
| 參數 | 估計值 |
|---|---|
| Grand mean (γ₀₀) | 4.83 |
| 截距變異 (τ₀₀) | 0.31 |
| 殘差變異 (σ²) | 0.87 |
ICC = 0.31 / (0.31 + 0.87) = 0.263
26.3% 的工作滿意度變異在公司層次。ICC 遠超 0.05 門檻——若用 OLS,標準誤將被嚴重低估,必須使用 HLM。
---
Step 2 — Random Intercept Model(加入 Level-1 預測變數)
autonomy 採組內平均中心化(group-mean centering),分離「個人相對於公司同事的自主性」效果,避免與公司層次效果混淆。tenure 同樣組內中心化。
Level 1: satisf_ij = β₀j + β₁j(autonomy_ij − ā_j) + β₂j(tenure_ij) + r_ij
Level 2: β₀j = γ₀₀ + u₀j
β₁j = γ₁₀ ← 固定斜率(先不允許隨機)
β₂j = γ₂₀固定效果結果:
| 預測變數 | γ | S.E. | t | p |
|---|---|---|---|---|
| 截距 (γ₀₀) | 4.81 | 0.11 | 43.7 | < .001 |
| autonomy (γ₁₀) | 0.42 | 0.04 | 10.5 | < .001 |
| tenure (γ₂₀) | 0.03 | 0.01 | 3.0 | .003 |
Level-1 殘差變異 σ² 從 0.87 降至 0.64,Level-1 解釋比例 ≈ 26%。
---
Step 3 — 加入 Level-2 預測變數與跨層次交互作用
理論上,高主管支持氣候的公司,員工的自主性-滿意度斜率可能更陡(因為自主性在支持文化中更能發揮)。因此允許 autonomy 斜率隨機變動,並以 mgr_climate 加以解釋:
Level 1: satisf_ij = β₀j + β₁j(autonomy_cwc) + β₂j(tenure_cwc) + r_ij
Level 2: β₀j = γ₀₀ + γ₀₁(mgr_climate_j) + γ₀₂(firm_size_j) + u₀j
β₁j = γ₁₀ + γ₁₁(mgr_climate_j) + u₁j ← 跨層次交互
β₂j = γ₂₀固定效果:
| 預測變數 | Level | γ | S.E. | t | p |
|---|---|---|---|---|---|
| 截距 (γ₀₀) | — | 4.82 | 0.09 | 53.6 | < .001 |
| mgr_climate (γ₀₁) | 2 | 0.38 | 0.12 | 3.17 | .003 |
| firm_size (γ₀₂) | 2 | −0.07 | 0.06 | −1.17 | .251 |
| autonomy (γ₁₀) | 1 | 0.43 | 0.05 | 8.6 | < .001 |
| autonomy × mgr_climate (γ₁₁) | 1×2 | 0.19 | 0.07 | 2.71 | .008 |
| tenure (γ₂₀) | 1 | 0.03 | 0.01 | 3.1 | .002 |
隨機效果:
| 成分 | 變異 | SD | p |
|---|---|---|---|
| 截距 (τ₀₀) | 0.09 | 0.30 | < .001 |
| autonomy 斜率 (τ₁₁) | 0.04 | 0.20 | .012 |
| 殘差 (σ²) | 0.63 | 0.79 | — |
---
Step 4 — 模型比較
| 模型 | −2LL | AIC | 參數數 | Δ deviance (p) |
|---|---|---|---|---|
| Null | 2,341.6 | 2,347.6 | 3 | — |
| Random Intercept + L1 | 2,178.3 | 2,192.3 | 7 | 163.3 (< .001) |
| Final (+ L2 + cross-level) | 2,152.7 | 2,174.7 | 11 | 25.6 (< .001) |
Level-2 截距變異從 0.31(null)降至 0.09,Level-2 解釋比例 ≈ 71%。
---
Result
## HLM Analysis: 員工工作自主性與工作滿意度
### Data Structure
| Level | Unit | N |
|-------|------|---|
| Level 1 | 員工 | 892 |
| Level 2 | 製造業公司 | 35 |
### ICC (Null Model)
- ICC = 0.26(26% 的滿意度變異在公司層次)
- 結論:ICC 顯著,OLS 會低估標準誤,HLM 為必要選擇
### Fixed Effects (Final Model)
| 預測變數 | Level | γ | S.E. | t | p |
|----------|-------|---|------|---|---|
| 截距 | — | 4.82 | 0.09 | 53.6 | < .001 |
| 主管支持氣候 | 2 | 0.38 | 0.12 | 3.17 | .003 |
| 公司規模 | 2 | −0.07 | 0.06 | −1.17 | .251 |
| 工作自主性 (cwc) | 1 | 0.43 | 0.05 | 8.6 | < .001 |
| 自主性 × 主管支持氣候 | 1×2 | 0.19 | 0.07 | 2.71 | .008 |
| 年資 (cwc) | 1 | 0.03 | 0.01 | 3.1 | .002 |
### Random Effects
| 成分 | 變異 | SD | p |
|------|------|-----|---|
| 截距 (τ₀₀) | 0.09 | 0.30 | < .001 |
| autonomy 斜率 (τ₁₁) | 0.04 | 0.20 | .012 |
| 殘差 (σ²) | 0.63 | 0.79 | — |
### Model Comparison
| 模型 | −2LL | AIC | 參數 | Δ deviance (p) |
|------|------|-----|------|----------------|
| Null | 2341.6 | 2347.6 | 3 | — |
| Final | 2152.7 | 2174.7 | 11 | 188.9 (< .001) |
### 實質解釋
- 工作自主性正向預測滿意度(γ = 0.43),在其他條件不變下,
自主性每提升 1 分,滿意度平均提升 0.43 分
- 跨層次交互顯著(γ = 0.19):主管支持氣候越高的公司,
自主性對滿意度的效果越強——在 +1 SD 氣候公司中效果為 0.62,
在 −1 SD 氣候公司中效果為 0.24
- 公司規模對滿意度無顯著效果,可從最終模型精簡時考慮移除
### Limitations
- 35 個 Level-2 單位位於可接受下限,τ₁₁ 估計有較大不確定性
- 橫斷面資料,無法排除員工自我選擇進入高自主文化公司的反向因果
- 未控制個人層次的人格特質(如自我效能),可能造成自主性效果高估Related skills
FAQ
What is ICC in HLM?
The intra-class correlation is the proportion of total variance that lies between groups; a rule of thumb is that HLM is warranted when ICC exceeds 0.05.
When should I not use HLM?
When clustering is negligible (ICC near zero), when there are fewer than 20 Level-2 units, or when the structure is crossed rather than hierarchical.