def _choose_cov(self, cov_type, **cov_config):
"""Return covariance estimator reformat clusters"""
cov_est = self._cov_estimators[cov_type]
if cov_type != 'clustered':
return cov_est, cov_config
cov_config_upd = {k: v for k, v in cov_config.items()}
clusters = cov_config.get('clusters', None)
if clusters is not None:
clusters = self.reformat_clusters(clusters).copy()
cluster_max = np.nanmax(clusters.values3d, axis=1)
delta = cluster_max - np.nanmin(clusters.values3d, axis=1)
if np.any(delta != 0):
raise ValueError('clusters must not vary within an entity')
index = clusters.panel.minor_axis
reindex = clusters.entities
clusters = pd.DataFrame(cluster_max.T, index=index, columns=clusters.vars)
clusters = clusters.loc[reindex].astype(np.int64)
cov_config_upd['clusters'] = clusters
return cov_est, cov_config_upd
评论列表
文章目录