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

Two-way clustered covariance of the panel models can have negative variances

Đang mở
#831 1 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

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

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ả

bug

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 reghdfe and vcemway do. 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

  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.