Show covariance matrix type in regression results

This commit is contained in:
RunasSudo 2022-10-17 20:34:58 +11:00
parent b24f675d57
commit 7a93355dab
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -86,7 +86,7 @@ class RegressionResult:
def __init__(self,
raw_result,
full_name, model_name, fit_method,
dep, nobs, dof_model, fitted_dt,
dep, nobs, dof_model, fitted_dt, cov_type,
terms,
llf, llnull,
dof_resid, rsquared, f_statistic,
@ -105,6 +105,7 @@ class RegressionResult:
self.nobs = nobs
self.dof_model = dof_model
self.fitted_dt = fitted_dt
self.cov_type = cov_type
# Regression coefficients/p values
self.terms = terms
@ -175,11 +176,12 @@ class RegressionResult:
left_col.append(('Method:', self.fit_method))
left_col.append(('Date:', self.fitted_dt.strftime('%Y-%m-%d')))
left_col.append(('Time:', self.fitted_dt.strftime('%H:%M:%S')))
left_col.append(('No. Observations:', format(self.nobs, '.0f')))
left_col.append(('Std. Errors:', 'Non-Robust' if self.cov_type == 'nonrobust' else self.cov_type.upper()))
# Right column
right_col = []
right_col.append(('No. Observations:', format(self.nobs, '.0f')))
right_col.append(('Df. Model:', format(self.dof_model, '.0f')))
if self.dof_resid:
right_col.append(('Df. Residuals:', format(self.dof_resid, '.0f')))
@ -463,7 +465,7 @@ def regress(
return RegressionResult(
result,
full_name, model_class.__name__, header_dict['Method:'],
dep, result.nobs, result.df_model, datetime.now(),
dep, result.nobs, result.df_model, datetime.now(), result.cov_type,
terms,
result.llf, llnull,
getattr(result, 'df_resid', None), getattr(result, 'rsquared', None), getattr(result, 'fvalue', None),
@ -500,7 +502,7 @@ class PenalisedLogit(statsmodels.discrete.discrete_model.BinaryModel):
NB: This class expects to be used in the context of yli.regress()
"""
def fit(self):
def fit(self, disp=False):
import rpy2.robjects as ro
import rpy2.robjects.packages
import rpy2.robjects.pandas2ri
@ -532,7 +534,7 @@ class PenalisedLogit(statsmodels.discrete.discrete_model.BinaryModel):
return RegressionResult(
model,
'Penalised Logistic Regression', 'Logit', 'Penalised ML',
self.endog_names, model['n'][0], model['df'][0], datetime.now(),
self.endog_names, model['n'][0], model['df'][0], datetime.now(), 'nonrobust',
terms,
model['loglik'][0], model['loglik'][1],
None, None, None,