def het_white(resid, exog, retres=False):
 x = np.asarray(exog)
 y = np.asarray(resid)
 if (x.ndim == 1):
  raise ValueError('x should have constant and at least one more variable')
 (nobs, nvars0) = x.shape
 (i0, i1) = np.triu_indices(nvars0)
 exog = (x[:, i0] * x[:, i1])
 (nobs, nvars) = exog.shape
 assert (nvars == (((nvars0 * (nvars0 - 1)) / 2.0) + nvars0))
 resols = OLS((y ** 2), exog).fit()
 fval = resols.fvalue
 fpval = resols.f_pvalue
 lm = (nobs * resols.rsquared)
 assert (resols.df_model == (np_matrix_rank(exog) - 1))
 lmpval = stats.chi2.sf(lm, resols.df_model)
 return (lm, lmpval, fval, fpval)

def het_white ( resid , exog , retres = False ) : x = np . asarray ( exog ) y = np . asarray ( resid ) if ( x . ndim == 1 ) : raise ValueError ( 'x should have constant and at least one more variable' ) ( nobs , nvars0 ) = x . shape ( i0 , i1 ) = np . triu_indices ( nvars0 ) exog = ( x [ : , i0 ] * x [ : , i1 ] ) ( nobs , nvars ) = exog . shape assert ( nvars == ( ( ( nvars0 * ( nvars0 - 1 ) ) / 2.0 ) + nvars0 ) ) resols = OLS ( ( y ** 2 ) , exog ) . fit ( ) fval = resols . fvalue fpval = resols . f_pvalue lm = ( nobs * resols . rsquared ) assert ( resols . df_model == ( np_matrix_rank ( exog ) - 1 ) ) lmpval = stats . chi2 . sf ( lm , resols . df_model ) return ( lm , lmpval , fval , fpval )
whites lagrange multiplier test for heteroscedasticity parameters resid : array_like residuals .