Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add linearmodels covariance class #7

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/lineamodels_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from functools import cached_property
from linearmodels.panel.covariance import HomoskedasticCovariance
from linearmodels.typing import Float64Array, IntArray
from typing import Union
from boot_algo3 import boot_algo3

class WildBootstrap(HomoskedasticCovariance):

def __init__(
self,
y: Float64Array,
x: Float64Array,
params: Float64Array,
entity_ids: Union[IntArray, None],
time_ids: Union[IntArray, None],
*,
debiased: bool = False,
extra_df: int = 0,
):
self._y = y
self._x = x
self._params = params
self._entity_ids = entity_ids
self._time_ids = time_ids
self._debiased = debiased
self._extra_df = extra_df
self._nobs, self._nvar = x.shape
self._nobs_eff = self._nobs - extra_df
if debiased:
self._nobs_eff -= self._nvar
self._scale = self._nobs / self._nobs_eff
self._name = "Wild Bootstrap"

@property
def name(self) -> str:
"""Covariance estimator name"""
return self._name

@property
def eps(self) -> Float64Array:
"""Model residuals"""
return self._y - self._x @ self._params

@property
def s2(self) -> float:
"""Error variance"""
eps = self.eps
return self._scale * float(eps.T @ eps) / self._nobs

@cached_property
def cov(self) -> Float64Array:
# add in bootalgo code

def deferred_cov(self) -> Float64Array:
"""Covariance calculation deferred until executed"""
return self.cov