def cov_cluster(results, group, use_correction=True):
 (xu, hessian_inv) = _get_sandwich_arrays(results, cov_type='clu')
 if ((not hasattr(group, 'dtype')) or (group.dtype != np.dtype('int'))):
  (clusters, group) = np.unique(group, return_inverse=True)
 else:
  clusters = np.unique(group)
 scale = S_crosssection(xu, group)
 (nobs, k_params) = xu.shape
 n_groups = len(clusters)
 cov_c = _HCCM2(hessian_inv, scale)
 if use_correction:
  cov_c *= ((n_groups / (n_groups - 1.0)) * ((nobs - 1.0) / float((nobs - k_params))))
 return cov_c

def cov_cluster ( results , group , use_correction = True ) : ( xu , hessian_inv ) = _get_sandwich_arrays ( results , cov_type = 'clu' ) if ( ( not hasattr ( group , 'dtype' ) ) or ( group . dtype != np . dtype ( 'int' ) ) ) : ( clusters , group ) = np . unique ( group , return_inverse = True ) else : clusters = np . unique ( group ) scale = S_crosssection ( xu , group ) ( nobs , k_params ) = xu . shape n_groups = len ( clusters ) cov_c = _HCCM2 ( hessian_inv , scale ) if use_correction : cov_c *= ( ( n_groups / ( n_groups - 1.0 ) ) * ( ( nobs - 1.0 ) / float ( ( nobs - k_params ) ) ) ) return cov_c
cluster robust covariance matrix calculates sandwich covariance matrix for a single cluster .