Two-way clustered covariance of the panel models can have negative variances
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue nà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
Start with the reproducer in the issue: PooledOLS(...).fit(cov_type='clustered', cluster_entity=True, cluster_time=True) yields a negative diagonal in res.cov. Read the clustered covariance code path that fit reaches, where the one-way covariances are summed and the intersection term is subtracted, and where std_errors takes the square root. Done means a maintainer-chosen behaviour (eigenvalue clipping by default or as an option, or a named warning) and a test that covers the small-panel case. The default-versus-option decision is still open, so confirm it before writing code.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
The two-way clustered covariance of the panel models (cluster_entity=True, cluster_time=True, or two cluster variables) is the sum of the two one-way clustered covariances minus the covariance clustered by their intersection (Cameron, Gelbach and Miller, 2011). It is not guaranteed to be positive semi-definite. In small panels a variance can be negative, and std_errors is then NaN, with a RuntimeWarning from np.sqrt:
import numpy as np
import pandas as pd
from linearmodels.panel import PooledOLS
rng = np.random.default_rng(4)
idx = pd.MultiIndex.from_product([range(6), range(5)], names=["entity", "time"])
df = pd.DataFrame({"x": rng.standard_normal(30), "y": rng.standard_normal(30)}, index=idx)
df["const"] = 1.0
res = PooledOLS(df.y, df[["const", "x"]]).fit(
cov_type="clustered", cluster_entity=True, cluster_time=True
)
print(np.diag(res.cov)) # [-0.005253 0.019529]
print(res.std_errors) # const is NaN, RuntimeWarning: invalid value encountered in sqrt
Options:
- Replace the negative eigenvalues of the covariance with zero, as Cameron, Gelbach and Miller (2011) suggest and as Stata's
reghdfeandvcemwaydo. This needs a decision on whether it is the default or an option, and on how to report that it happened. - Keep the covariance, and say clearly that a variance is negative (a warning naming the parameters) instead of a numpy RuntimeWarning.
Deferred from 7.1.
- 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
-
IV: LIML kappa with an endogenous regressor spanned by the instruments, kappa's unit dependence, scale-dependent instrument rank checkCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
bashtage/linearmodels#823 ·
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ự
-
getchaintips leaves out the active tip once a header is staged on it, where Core always lists itĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
btclib-org/btclib-node#2158 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
dbt-msft/dbt-sqlserver#897 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Gathin23/cleanyourtv#2770 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
vllm-project/vllm#64845 ·
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 84/100
dekobon/big-code-analysis#1729 ·
Maintainer thường phản hồi trong vòng 1 ngày