Nested LMM (Hierarchical Mixed Model)

Nested LMM (Hierarchical Mixed Model)

⚡ Advanced · Mixed Models · Nested

v1.0.1

Health Sciences context — fixed effect (treatment) + nested random effects. HbA1c_pct ~ tedavi + (1|hastane/doktor/hasta). The difference from VARCOMP: a fixed effect (e.g., treatment/group comparison) is added.

hastane/doktor/hasta nestedTedavi sabit etkenREMLFixed effect estimate + p

🎯 What is it for?

When interpreting fixed effects in hierarchical data, it also accounts for the variance of the random factors. In Health Sciences, if the same patients receive different treatments, a classical t-test/ANOVA ignores the clustering → Type-I error. A nested LMM computes this correctly.

📌 When is it used?

  • Comparison of a fixed effect (treatment, intervention, condition) + hierarchical sampling
  • Multi-site clinical research, multi-center field trial
  • Adjusting site/group-level variance in RCTs

⚙ Assumptions

  1. Continuous DV, categorical fixed effect.
  2. Nested structure: doctor within hospital, patient within doctor.
  3. Random effects ~ Normal(0, σ²).
  4. ≥1 observation in each treatment-patient combination.

📊 How is it run in MerQur?

1
Load data.
2
Analysis → ⚡ Advanced → Nested LMM.
3

Panel assignments (form fields in the program):

  • Dependent variable (DV): HbA1c
  • Replication (R): vizit
  • Upper-level group (P): klinik
  • Lower-level group (F): doktor_no
  • SS method: 1
4
Estimator: REML.
5
▶ Run. Fixed effect β̂ + p + σ² for each random level.

📊 Sample Dataset — Health Sciences

ℹ Note: The scenario, MerQur output and interpretation below were produced by actually running the real example dataset in MerQur. Numeric results on your own data will differ; the goal is to show how the analysis is set up and interpreted end-to-end.

🎬 Example File

This analysis is demonstrated on the following example dataset for Health Sciences:

Tip/108_nested_lmm_clinical_doctor_visit_HbA1c.xlsx

🎬 Scenario

We model HbA1c in a nested design (clinic>doctor>visit). For nested hierarchies,
nested LMM is appropriate.

⚙️ Variable Selection

  • Dependent variable: HbA1c
  • Factor (categorical): visit
  • Factor (categorical): clinical
  • Factor (categorical): doctor_no

Data Preview (First 5 Rows)

patient_id visit clinical doctor_no HbA1c
H0001 V1 K_Ankara D01 6.49
H0002 V1 K_Ankara D01 5.74
H0003 V1 K_Ankara D01 6.67
H0004 V2 K_Ankara D01 6.62
H0005 V2 K_Ankara D01 7.59

n = 288 · Columns: patient_id, visit, clinical, doctor_no, HbA1c

📈 MerQur Output

NESTED LMM (HIERARCHICAL MIXED MODEL) RESULT
─────────────────────────────────────────────

clinical (P) effect: F = 10.37, p < .001 *** doctor_no (within clinic, F): F = 7.57, p < .001 ***
visit (R) effect: F = 14.20, p < .001 *** outcome: HbA1c

💬 Interpretation

We modeled HbA1c in a nested design (clinic > doctor > visit): the clinic level (F = 10.37, p < .001), the doctor
level (F = 7.57, p < .001) and the visit/replication level (F = 14.20, p < .001) all make significant contributions.
Nested LMM correctly handles hierarchies where sub-units are nested within super-units (each doctor belongs to only
one clinic); by partitioning variance into levels it shows each layer’s share. In medicine it is used to correctly
separate effects in clinic>doctor>patient hierarchies.

⚠ Common Mistakes

  • Specifying “crossed” instead of “nested” — the doctor-ids should not recur within each hospital.
  • Optimizer stalling (lbfgs llf=inf) — MerQur resolves this with a bfgs/cg cascade.
  • Treatment × hospital imbalance — the fixed-effect coefficient may be biased.

📚 MerQur’a Atıf

Örücü, Ö. K. (2026). MerQur: Integrated Academic Data Analysis & Reporting Platform [Computer software] (Version 1.0.0). https://doi.org/10.53463/merqur.2026001

Tüm atıf formatları →

📝 Üretim Notu — Bu sayfadaki örnek veri sentetik olarak üretilmiştir (sabit SEED=42, generator: samples/Ileri_Duzey_v102/_generate_v102_datasets.py). Sayfa içeriği Anthropic Claude desteği ile hazırlanmış, akademik doğruluk yazar tarafından kontrol edilmiştir.