def spec_hausman(params_e, params_i, cov_params_e, cov_params_i, dof=None):
 params_diff = (params_i - params_e)
 cov_diff = (cov_params_i - cov_params_e)
 if (not dof):
  dof = np_matrix_rank(cov_diff)
 cov_diffpinv = np.linalg.pinv(cov_diff)
 H = np.dot(params_diff, np.dot(cov_diffpinv, params_diff))
 pval = stats.chi2.sf(H, dof)
 evals = np.linalg.eigvalsh(cov_diff)
 return (H, pval, dof, evals)

def spec_hausman ( params_e , params_i , cov_params_e , cov_params_i , dof = None ) : params_diff = ( params_i - params_e ) cov_diff = ( cov_params_i - cov_params_e ) if ( not dof ) : dof = np_matrix_rank ( cov_diff ) cov_diffpinv = np . linalg . pinv ( cov_diff ) H = np . dot ( params_diff , np . dot ( cov_diffpinv , params_diff ) ) pval = stats . chi2 . sf ( H , dof ) evals = np . linalg . eigvalsh ( cov_diff ) return ( H , pval , dof , evals )
hausmans specification test parameters params_e : array efficient and consistent under null hypothesis .