'Full fit of the model.
The results include an estimate of covariance matrix, (whitened)
residuals and an estimate of scale.
Parameters
method : str, optional
Can be "pinv", "qr".  "pinv" uses the Moore-Penrose pseudoinverse
to solve the least squares problem. "qr" uses the QR
factorization.
cov_type : str, optional
See `regression.linear_model.RegressionResults` for a description
of the available covariance estimators
cov_kwds : list or None, optional
See `linear_model.RegressionResults.get_robustcov_results` for a
description required keywords for alternative covariance estimators
use_t : bool, optional
Flag indicating to use the Student\'s t distribution when computing
p-values.  Default behavior depends on cov_type. See
`linear_model.RegressionResults.get_robustcov_results` for
implementation details.
Returns
A RegressionResults class instance.
See Also
regression.linear_model.RegressionResults
regression.linear_model.RegressionResults.get_robustcov_results
Notes
The fit method uses the pseudoinverse of the design/exogenous variables
to solve the least squares minimization.'

def fit(self, method='pinv', cov_type='nonrobust', cov_kwds=None, use_t=None, **kwargs):

    if (method == 'pinv'):
        if (not (hasattr(self, 'pinv_wexog') and hasattr(self, 'normalized_cov_params') and hasattr(self, 'rank'))):
            (self.pinv_wexog, singular_values) = pinv_extended(self.wexog)
            self.normalized_cov_params = np.dot(self.pinv_wexog, np.transpose(self.pinv_wexog))
            self.wexog_singular_values = singular_values
            self.rank = np_matrix_rank(np.diag(singular_values))
        beta = np.dot(self.pinv_wexog, self.wendog)
    elif (method == 'qr'):
        if (not (hasattr(self, 'exog_Q') and hasattr(self, 'exog_R') and hasattr(self, 'normalized_cov_params') and hasattr(self, 'rank'))):
            (Q, R) = np.linalg.qr(self.wexog)
            (self.exog_Q, self.exog_R) = (Q, R)
            self.normalized_cov_params = np.linalg.inv(np.dot(R.T, R))
            self.wexog_singular_values = np.linalg.svd(R, 0, 0)
            self.rank = np_matrix_rank(R)
        else:
            (Q, R) = (self.exog_Q, self.exog_R)
        self.effects = effects = np.dot(Q.T, self.wendog)
        beta = np.linalg.solve(R, effects)
    if (self._df_model is None):
        self._df_model = float((self.rank - self.k_constant))
    if (self._df_resid is None):
        self.df_resid = (self.nobs - self.rank)
    if isinstance(self, OLS):
        lfit = OLSResults(self, beta, normalized_cov_params=self.normalized_cov_params, cov_type=cov_type, cov_kwds=cov_kwds, use_t=use_t)
    else:
        lfit = RegressionResults(self, beta, normalized_cov_params=self.normalized_cov_params, cov_type=cov_type, cov_kwds=cov_kwds, use_t=use_t, **kwargs)
    return RegressionResultsWrapper(lfit)
