Download code/tests/test_meta.py from bryan7264/lorapop: direct link, hf CLI and curl.
- Browser
- Download file 777 Bytes
-
https://huggingface.co/datasets/bryan7264/lorapop/resolve/main/code/tests/test_meta.py
- Command line
-
hf download hf://datasets/bryan7264/lorapop/code/tests/test_meta.py
-
curl -L -o test_meta.py https://huggingface.co/datasets/bryan7264/lorapop/resolve/main/code/tests/test_meta.py
777 Bytes
| # MIT License, Bryan Cheng, 2026. | |
| import numpy as np | |
| from src.analysis.meta import dersimonian_laird | |
| def test_dl_homogeneous_equals_fixed_effect(): | |
| r = dersimonian_laird([1.0, 1.0, 1.0], [0.1, 0.2, 0.4]) | |
| assert r["tau2"] == 0.0 and abs(r["estimate"] - 1.0) < 1e-12 and r["I2"] == 0.0 | |
| def test_dl_heterogeneous_textbook(): | |
| # tau^2 by hand: w = 1/v, Q = sum w (y - mu_f)^2, tau^2 = (Q - (k-1)) / (sum w - sum w^2 / sum w) | |
| y, v = np.array([0.0, 1.0, 3.0]), np.array([0.1, 0.1, 0.1]) | |
| w = 1 / v | |
| mu_f = (w * y).sum() / w.sum() | |
| Q = (w * (y - mu_f) ** 2).sum() | |
| tau2 = (Q - 2) / (w.sum() - (w ** 2).sum() / w.sum()) | |
| r = dersimonian_laird(y, v) | |
| assert abs(r["tau2"] - tau2) < 1e-12 and abs(r["estimate"] - y.mean()) < 1e-12 and r["I2"] > 0.9 | |