滚动 WLS 中的权重

问题描述 投票:0回答:1

我有一个 RollingWLS 模型,其中包含 1 个因变量和 10 个自变量。我正在计算 60 个窗口的 RollingWLS 多元回归。

from statsmodels.regression.rolling import RollingWLS

endog = df1
exog = df2
cov_type = 'HC0'

wls_model = RollingWLS(endog, exog, window=60)
wls = wls_model.fit(cov_type=cov_type)

数据表现出异方差性,我想在 RollingWLS 中使用

Weights
参数来纠正这一点。

https://www.statsmodels.org/dev/ generated/statsmodels.regression.rolling.RollingWLS.html

一维权重数组。如果您提供 1/W,则变量将预先乘以 1/sqrt(W)。如果未提供权重,则默认值为 1,WLS 结果与 OLS 相同。

我应该如何计算 RollingWLS

Weights
函数的滚动权重?即:

wls_model = RollingWLS(endog, exog, **ROLLING_WEIGHTS_HERE**, window=60)
wls = wls_model.fit(cov_type=cov_type)

谢谢

python regression statsmodels weighted
1个回答
0
投票

ROLLING_WEIGHTS_HERE 替换为权重 = your_weights

n_samples = len(endog)
sample_weight = np.ones(n_samples) * 20
sample_weight[-n_samples//10:] *= 30

wls_model = RollingWLS(endog, exog, weights = sample_weight, window=60)
wls = wls_model.fit(cov_type=cov_type)
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.