Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, reason, *, name=None):
self._reason = reason
super(InvalidTestStatistic, self).__init__(NaN, NaN, df=1, df_denom=1, name=name)
self.dist_name = 'None'
def _f_statistic(self, weps, y, x, root_w, df_resid):
"""Compute model F-statistic"""
weps_const = y
num_df = x.shape[1]
name = 'Model F-statistic (homoskedastic)'
if self.has_constant:
if num_df == 1:
return InvalidTestStatistic('Model contains only a constant',
name=name)
num_df -= 1
weps_const = y - float((root_w.T @ y) / (root_w.T @ root_w))
resid_ss = weps.T @ weps
num = float(weps_const.T @ weps_const - resid_ss)
denom = resid_ss
denom_df = df_resid
stat = float((num / num_df) / (denom / denom_df))
return WaldTestStatistic(stat, null='All parameters ex. constant not zero',
df=num_df, df_denom=denom_df, name=name)
def invalid_f():
return InvalidTestStatistic('Model contains only a constant',
name=name)
def __init__(self, reason, *, name=None):
self._reason = reason
super(InvalidTestStatistic, self).__init__(np.NaN, np.NaN, df=1, df_denom=1, name=name)
self.dist_name = 'None'
cov = stats.cov
k = cov.shape[0]
sel = list(range(k))
if stats.has_constant:
sel.pop(stats.constant_loc)
cov = cov[sel][:, sel]
params = stats.params[sel]
df = params.shape[0]
nobs = stats.nobs
null = 'All parameters ex. constant are zero'
name = 'Equation F-statistic'
try:
stat = float(params.T @ inv(cov) @ params)
except np.linalg.LinAlgError:
return InvalidTestStatistic('Covariance is singular, possibly due '
'to constraints.', name=name)
if debiased:
total_reg = np.sum(list(map(lambda s: s.shape[1], self._wx)))
df_denom = len(self._wx) * nobs - total_reg
wald = WaldTestStatistic(stat / df, null, df, df_denom=df_denom,
name=name)
else:
return WaldTestStatistic(stat, null=null, df=df, name=name)
return wald