Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

IV: LIML kappa with an endogenous regressor spanned by the instruments, kappa's unit dependence, scale-dependent instrument rank check

Đang mở
#823 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@inchang-ing đang làm issue này rồi.

Từ ngày 18/10/2026.

  • #850 của @inchang-ing — đang mở

Đá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
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
numpy, python
Lĩnh vực
data

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ả

bug

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của bashtage/linearmodels

Tất cả issue của bashtage/linearmodels

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.