IV: LIML kappa with an endogenous regressor spanned by the instruments, kappa's unit dependence, scale-dependent instrument rank check
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
The kappa computation is in _estimate_kappa, and the rank check is in _validate_inputs; both are reached through IVLIML and IV2SLS. Start by running the two reproduction scripts in the issue to see the unstable kappa values and the scale-dependent ValueError. Done means a relative-residual test that catches the spanned endogenous regressor, kappa that is invariant to units with several endogenous regressors, and an instrument rank check that does not depend on column scale. The detection method is still an open design choice, so agree on it with the maintainer first.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Three numerical edge cases in the IV models, found during 7.1 and deferred to 7.2.
1. LIML's kappa is noise when an endogenous regressor is spanned by the instruments. _estimate_kappa inverts W'M_Z W, where W holds the dependent variable and the endogenous regressors. If an endogenous regressor is an exact combination of the exogenous regressors and instruments, its column of M_Z W is rounding error. The matrix is then singular, and kappa is noise instead of an error:
import numpy as np
from linearmodels.iv import IVLIML
kappas = []
for seed in range(8):
rng = np.random.default_rng(seed)
n = 500
z = rng.standard_normal((n, 2))
x = z[:, 0] + 2 * z[:, 1] # exactly spanned by the instruments
y = 1 + 0.5 * x + rng.standard_normal(n)
kappas.append(IVLIML(y, np.ones((n, 1)), x, z).fit().kappa)
print(np.round(kappas, 6))
# [1.002657 1.002214 1.004278 1.004001 1.000129 1.001426 1.005058 1.00002 ]
A rank test on residuals scaled to unit columns can't see this, because scaling a column of rounding error gives it unit length. Detecting it needs a relative-residual test, e.g. ||M_Z w|| against ||M_1 w||, that doesn't flag variables with a small coefficient of variation in models without a constant.
2. Kappa depends on the units of the variables when there are several endogenous regressors. With two endogenous regressors, rescaling y or one regressor by 1e6 or 1e-6 changes kappa by up to 2.6e-4 relative (20 random designs, n = 200). Computing kappa from residuals scaled to unit columns makes it invariant to about 2e-15. However, it turns case 1 into values like -5.5e10 or 1.1e12, because the column of rounding error is magnified by about 1e14. So 1 and 2 have to be fixed together: detect case 1 first, then scale.
3. The rank check of the instruments depends on their scale. _validate_inputs checks the rank of [exog, instruments] without scaling the columns, so instruments on very different scales are rejected:
import numpy as np
from linearmodels.iv import IV2SLS
rng = np.random.default_rng(0)
n = 500
z = rng.standard_normal((n, 2))
x = z @ [1.0, 1.0] + rng.standard_normal(n)
y = 1 + 0.5 * x + rng.standard_normal(n)
IV2SLS(y, np.ones((n, 1)), x, z * [1.0, 1e12]).fit() # fits
IV2SLS(y, np.ones((n, 1)), x, z * [1.0, 1e13]).fit() # ValueError: ... do not have full column rank
Scaling the columns to unit length before the rank test would make it independent of units.
Deferred from 7.1. In 7.1, _estimate_kappa raises when there are too few observations or the residuals are rank deficient, but it leaves these three cases as they are.
- Ngôn ngữ chính
- Python
- Star
- 1.1k
- Fork
- 203
- Merge trung bình
- 3 giờ 26 phút
- Pull request đã merge (30 ngày)
- 115
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của bashtage/linearmodels
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
bashtage/linearmodels#832 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
bashtage/linearmodels#831 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 18/100
bashtage/linearmodels#817 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
bashtage/linearmodels#780 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
bashtage/linearmodels#714 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của bashtage/linearmodels
Issue tương tự
-
Add `openai_safety_identifier`, the replacement for the `user` field that `openai_user` sendsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
pydantic/pydantic-ai#12091 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Enhance blog readabilityĐang mởCSS enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
pychess/pychess-variants#2448 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bump locked PyTensor so Apple clang 21 does not pass -ld64Có thể đã có người làm @drbenvincent đã nhận hôm nay. Đang mởbug dev ops
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 2 ngày
-
ai_p2 bug comp-datalake
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
ClickHouse/ClickHouse#128306 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày