This project demonstrates a reproducible clinical-statistical workflow for analyzing repeated serum bilirubin measurements among patients with primary biliary cirrhosis.
The analysis addresses a clinically meaningful question:
How do serum bilirubin levels change during follow-up, and do baseline patient characteristics predict meaningful differences in those longitudinal trajectories?
The project emphasizes:
- transparent longitudinal data auditing,
- clinically interpretable model selection,
- patient-specific trajectory heterogeneity,
- adjusted reference-profile predictions,
- diagnostic assessment,
- sensitivity analysis,
- and reproducible repository outputs.
The analysis uses the publicly available Mayo Clinic primary biliary cirrhosis sequential dataset (pbcseq).
| Metric | Value |
|---|---|
| Unique patients | 312 |
| Repeated clinical observations | 1,945 |
| Median observations per patient | 5 |
| Maximum observations per patient | 16 |
| Maximum observed follow-up | 14.11 years |
All patients have a baseline record at day 0.
Serum bilirubin, the primary repeated outcome, is fully observed across all longitudinal records.
Repeated measurements from the same patient are correlated and cannot be treated as statistically independent observations.
An intercept-only random-intercept model produced:
ICC = 0.765
Approximately 76.5% of the total variation in log-transformed bilirubin is attributable to differences between patients.
A mixed-effects framework is therefore necessary to represent:
- within-patient change over time,
- between-patient differences in typical bilirubin levels,
- patient-specific rates of progression,
- and clinically meaningful subgroup differences.
The reproducible workflow includes:
- longitudinal data-structure inspection,
- duplicate and follow-up integrity checks,
- targeted clinical plausibility review,
- baseline cohort profiling,
- repeated-observation missingness assessment,
- descriptive trajectory visualization,
- raw-versus-log outcome-scale comparison,
- random-intercept and random-slope model comparison,
- linear-versus-quadratic time-specification assessment,
- adjusted mixed-effects modeling,
- baseline-stage-by-time interaction modeling,
- adjusted reference-profile trajectory prediction,
- follow-up-range sensitivity analysis,
- residual and random-effect diagnostics,
- focused extreme-residual sensitivity analysis,
- repository-output verification.
The longitudinal dataset passed the core structural checks:
- no fully duplicated rows,
- no duplicated patient-day records,
- no negative follow-up times,
- no measurements recorded beyond documented follow-up,
- and no missing serum bilirubin values.
Two isolated albumin spikes were reviewed within their patient-specific trajectories and recoded as missing in the working dataset only.
No rows were removed during the integrity audit.
Raw serum bilirubin values were strongly right-skewed:
| Outcome scale | Skewness |
|---|---|
| Raw bilirubin | 2.817 |
| Log-transformed bilirubin | 0.652 |
The primary mixed-effects models therefore use:
log_bilirubin = log(bili)
The final REML-refitted model includes:
- linear follow-up time,
- quadratic follow-up time,
- baseline age,
- baseline albumin,
- sex,
- treatment assignment,
- baseline histologic-stage group,
- stage-by-linear-time interaction,
- stage-by-quadratic-time interaction,
- patient-specific random intercepts,
- and patient-specific linear-time slopes.
The adjusted coefficients describe observational longitudinal associations rather than causal effects.
Patients with advanced baseline histologic stage (Stages 3–4) have higher bilirubin levels than patients with lower baseline stage (Stages 1–2).
The advanced-stage quadratic time interaction remains statistically supported:
β = 0.006, p = 0.007
This indicates that patients with advanced baseline histologic disease appear to follow a steeper bilirubin trajectory over time.
A 0.5-unit higher baseline albumin value is associated with approximately 36.5% lower bilirubin across follow-up after adjustment:
β = −0.454, p < 0.001
Male patients show approximately 39.7% higher adjusted bilirubin than female patients:
β = 0.335, p = 0.041
This estimate should be interpreted cautiously because the male subgroup is relatively small.
The D-penicillamine coefficient is not statistically supported:
β = −0.096, p = 0.348
This longitudinal biomarker model should not be interpreted as a definitive treatment-efficacy analysis.
| Variance component | Estimate |
|---|---|
| Random-intercept variance | 0.769 |
| Random-slope variance | 0.031 |
| Intercept–slope correlation | 0.326 |
| Within-patient residual variance | 0.119 |
Patients differ meaningfully in both:
- their typical bilirubin levels,
- and their longitudinal rates of change.
The primary figure focuses on the first 7 years of follow-up, where the longitudinal information base is stronger.
For a common reference profile, the predicted bilirubin values at 7 years are:
| Baseline histologic-stage group | Predicted bilirubin | 95% CI |
|---|---|---|
| Lower stage: Stages 1–2 | 2.96 | 1.88 to 4.66 |
| Advanced stage: Stages 3–4 | 8.79 | 6.36 to 12.17 |
These curves are back-transformed fixed-effect predictions for a common reference profile.
They are not arithmetic cohort means, individual patient forecasts, or causal effects.
Interpretation beyond 7 years requires additional caution because:
- fewer patients remain under observation,
- uncertainty intervals widen,
- and polynomial time terms become more influential near the observed-data boundary.
The selected model was refitted using the first 7 years of follow-up only.
This retained:
- 1,681 observations,
- 86.43% of the full longitudinal records,
- and all 312 patients.
A focused sensitivity model excluded only the 11 visits with:
|standardized conditional residual| > 3
This retained:
- 1,934 observations,
- 99.43% of the primary-analysis records,
- and all 312 patients.
The advanced-stage quadratic interaction remained statistically supported:
| Model | p-value |
|---|---|
| Primary model | 0.007 |
| Extreme-residual sensitivity model | 0.008 |
The primary model retains all observations.
| Diagnostic metric | Value |
|---|---|
| Mean conditional residual | 0.000 |
| Median conditional residual | −0.009 |
| Residual excess kurtosis | 2.898 |
| Visits with absolute standardized residual greater than 3 | 11 |
The repository contains:
README.mdrequirements.txt.gitignoreruntime_environment.txtdata/README.mdscripts/README.mdnotebooks/README.mdnotebooks/Longitudinal_Bilirubin_Mixed_Effects_Project.ipynboutputs/with verified tables and figures
-
Machine-readable project summary
outputs/project_summary.csv -
Baseline patient-level cohort profile
outputs/baseline_cohort_profile.csv -
Longitudinal integrity audit
outputs/repeated_observation_audit.csv -
Final REML fixed-effect estimates
outputs/primary_model_fixed_effect_summary.csv -
Final random-effect variance components
outputs/primary_model_random_effect_summary.csv
- Adjusted bilirubin trajectories by baseline histologic stage
outputs/adjusted_bilirubin_trajectory_primary_0_to_7_years.png
-
Follow-up-range sensitivity summary
outputs/followup_range_sensitivity_summary.csv -
Extreme-residual-exclusion sensitivity summary
outputs/extreme_residual_exclusion_sensitivity_summary.csv
-
Repository-output audit
outputs/repository_output_audit.csv -
Complete outputs-folder inventory
outputs/final_outputs_folder_inventory.csv
This project demonstrates an observational longitudinal modeling workflow.
The results should not be interpreted as:
- causal effects,
- individual patient forecasts,
- definitive treatment-efficacy conclusions,
- or evidence that every patient follows the same disease-progression pattern.
The workflow is designed for execution in Google Colab.
To reproduce the analysis:
- open the notebook inside the
notebooks/folder, - install the packages listed in
requirements.txt, - obtain the publicly available
pbcseqdataset, - run the notebook cells sequentially,
- review the generated files inside the
outputs/folder.
- Python
- pandas
- NumPy
- SciPy
- statsmodels
- patsy
- matplotlib
| Verification metric | Result |
|---|---|
| Verified repository-ready outputs | 50 |
| Total files in packaged outputs folder | 53 |
| CSV tables | 40 |
| PNG figures | 13 |
| Empty files | 0 |
Dr. Imran Sarmad
PhD Statistical Consultant | Clinical, RWE, HEOR/HTA, Causal Inference & Advanced Modeling
Lecturer, Virtual University of Pakistan
Professional website: https://drimransarmad.com
LinkedIn: https://www.linkedin.com/in/dr-imran-sarmad/





