def norm_resid(self): """ Residuals, normalized to have unit length and unit variance. Returns ------- An array wresid/sqrt(scale) Notes ----- This method is untested """ if not hasattr(self, 'resid'): raise ValueError, 'need normalized residuals to estimate standard\ deviation' return self.wresid * recipr(np.sqrt(self.scale))
def t_test(self, r_matrix, scale=None): """ Compute a tcontrast/t-test for a row vector array. Parameters ---------- r_matrix : array-like A length p row vector specifying the linear restrictions. scale : float, optional An optional `scale` to use. Default is the scale specified by the model fit. scale : scalar Examples -------- >>> import numpy as np >>> import scikits.statsmodels as sm >>> data = sm.datasets.longley.load() >>> data.exog = sm.add_constant(data.exog) >>> results = sm.OLS(data.endog, data.exog).fit() >>> r = np.zeros_like(results.params) >>> r[4:6] = [1,-1] >>> print r [ 0. 0. 0. 0. 1. -1. 0.] r tests that the coefficients on the 5th and 6th independent variable are the same. >>>T_Test = results.t_test(r) >>>print T_test <T contrast: effect=-1829.2025687192481, sd=455.39079425193762, t=-4.0167754636411717, p=0.0015163772380899498, df_denom=9> >>> T_test.effect -1829.2025687192481 >>> T_test.sd 455.39079425193762 >>> T_test.t -4.0167754636411717 >>> T_test.p 0.0015163772380899498 See also --------- t : method to get simpler t values f_test : for f tests """ r_matrix = np.squeeze(np.asarray(r_matrix)) if self.normalized_cov_params is None: raise ValueError, 'Need covariance of parameters for computing \ T statistics' if r_matrix.ndim == 1: if r_matrix.shape[0] != self.params.shape[0]: raise ValueError, 'r_matrix and params are not aligned' elif r_matrix.ndim >1: if r_matrix.shape[1] != self.params.shape[0]: raise ValueError, 'r_matrix and params are not aligned' _t = _sd = None _effect = np.dot(r_matrix, self.params) _sd = np.sqrt(self.cov_params(r_matrix=r_matrix)) if _sd.ndim > 1: _sd = np.diag(_sd) _t = _effect * recipr(_sd) return ContrastResults(effect=_effect, t=_t, sd=_sd, df_denom=self.model.df_resid)