statsmodels.regression.rolling.RollingWLS

class statsmodels.regression.rolling.RollingWLS(endog, exog, window=None, *, weights=None, min_nobs=None, missing='drop', expanding=False)[source]

Rolling Weighted Least Squares

Parameters:
endogarray_like

A 1-d endogenous response variable. The dependent variable.

exogarray_like

A nobs x k array where nobs is the number of observations and k is the number of regressors. An intercept is not included by default and should be added by the user. See statsmodels.tools.add_constant.

windowint

Length of the rolling window. Must be strictly larger than the number of variables in the model.

weightsarray_like, optional

A 1d array of weights. If you supply 1/W then the variables are pre- multiplied by 1/sqrt(W). If no weights are supplied the default value is 1 and WLS results are the same as OLS.

min_nobs{int, None}

Minimum number of observations required to estimate a model when data are missing. If None, the minimum depends on the number of regressors in the model. Must be smaller than window.

missingstr, default “drop”

Available options are “drop”, “skip” and “raise”. If “drop”, any observations with nans are dropped and the estimates are computed using only the non-missing values in each window. If ‘skip’ blocks containing missing values are skipped and the corresponding results contains NaN. If ‘raise’, an error is raised. Default is ‘drop’.

expandingbool, default False

If True, then the initial observations after min_nobs are filled using an expanding scheme until window observations are available, after which rolling is used.

See also

statsmodels.regression.linear_model.WLS

WLS estimation and parameter testing.

Notes

Tested against WLS for accuracy.

Results may differ from WLS applied to windows of data if this model contains an implicit constant (i.e., includes dummies for all categories) rather than an explicit constant (e.g., a column of 1s).

Examples

>>> from statsmodels.regression.rolling import RollingWLS
>>> from statsmodels.datasets import longley
>>> data = longley.load()
>>> exog = add_constant(data.exog, prepend=False)
>>> mod = RollingWLS(data.endog, exog)
>>> rolling_res = mod.fit(reset=50)

Use params_only to skip all calculations except parameter estimation

>>> rolling_params = mod.fit(params_only=True)

Use expanding and min_nobs to fill the initial results using an expanding scheme until window observation, and the roll.

>>> mod = RollingWLS(data.endog, exog, window=60, min_nobs=12,
... expanding=True)
>>> rolling_res = mod.fit()

Methods

fit([method, cov_type, cov_kwds, reset, ...])

Estimate model parameters.

from_formula(formula, data, window[, ...])

Create a Model from a formula and dataframe.


Last update: Dec 16, 2024