src/estimagic/inference/ml_covs.py
def _clustering(jac, design_info):
    """Variance estimation for each cluster.

    The function takes the sum of the jacobian observations for each cluster.
    The result is the meat of the sandwich estimator.

    Args:
        jac (np.array): "jacobian" - an n x k + 1-dimensional array of first
            derivatives of the pseudo-log-likelihood function w.r.t. the parameters
        design_info (pd.DataFrame): dataframe containing psu, stratum,
            population/design weight and/or a finite population corrector (fpc)

    Returns:
        cluster_meat (np.array): 2d square array of length k + 1. Variance of
            the likelihood equation (Pg.557, 14-10, Greene 7th edition)

    """

    list_of_clusters = design_info["psu"].unique()
    meat = np.zeros([len(jac[0, :]), len(jac[0, :])])
    for psu in list_of_clusters:
        psu_scores = jac[design_info["psu"] == psu]
        psu_scores_sum = psu_scores.sum(axis=0)
        meat += np.dot(psu_scores_sum[:, None], psu_scores_sum[:, None].T)
    cluster_meat = len(list_of_clusters) / (len(list_of_clusters) - 1) * meat
    return cluster_meat
Variance estimation for each cluster.

    The function takes the sum of the jacobian observations for each cluster.
    The result is the meat of the sandwich estimator.

    Args:
        jac (np.array): "jacobian" - an n x k + 1-dimensional array of first
            derivatives of the pseudo-log-likelihood function w.r.t. the parameters
        design_info (pd.DataFrame): dataframe containing psu, stratum,
            population/design weight and/or a finite population corrector (fpc)

    Returns:
        cluster_meat (np.array): 2d square array of length k + 1. Variance of
            the likelihood equation (Pg.557, 14-10, Greene 7th edition)

    
Variance estimation for each cluster.
The function takes the sum of the jacobian observations for each cluster.
The result is the meat of the sandwich estimator.
Variance estimation for each cluster . The function takes the sum of the jacobian observations for each cluster . The result is the meat of the sandwich estimator .
def _clustering(jac, design_info):
    list_of_clusters = design_info["psu"].unique()
    meat = np.zeros([len(jac[0, :]), len(jac[0, :])])
    for psu in list_of_clusters:
        psu_scores = jac[design_info["psu"] == psu]
        psu_scores_sum = psu_scores.sum(axis=0)
        meat += np.dot(psu_scores_sum[:, None], psu_scores_sum[:, None].T)
    cluster_meat = len(list_of_clusters) / (len(list_of_clusters) - 1) * meat
    return cluster_meat
def _clustering ( jac , design_info ) : list_of_clusters = design_info [ "psu" ] . unique ( ) meat = np . zeros ( [ len ( jac [ 0 , : ] ) , len ( jac [ 0 , : ] ) ] ) for psu in list_of_clusters : psu_scores = jac [ design_info [ "psu" ] == psu ] psu_scores_sum = psu_scores . sum ( axis = 0 ) meat += np . dot ( psu_scores_sum [ : , None ] , psu_scores_sum [ : , None ] . T ) cluster_meat = len ( list_of_clusters ) / ( len ( list_of_clusters ) - 1 ) * meat return cluster_meat
Variance estimation for each cluster.
Variance estimation for each cluster .
"""Variance estimation for each cluster.

    The function takes the sum of the jacobian observations for each cluster.
    The result is the meat of the sandwich estimator.

    Args:
        jac (np.array): "jacobian" - an n x k + 1-dimensional array of first
            derivatives of the pseudo-log-likelihood function w.r.t. the parameters
        design_info (pd.DataFrame): dataframe containing psu, stratum,
            population/design weight and/or a finite population corrector (fpc)

    Returns:
        cluster_meat (np.array): 2d square array of length k + 1. Variance of
            the likelihood equation (Pg.557, 14-10, Greene 7th edition)

    """
cluster_meat (np.array): 2d square array of length k + 1. Variance of
the likelihood equation (Pg.557, 14-10, Greene 7th edition)
cluster_meat ( np . array ) : 2d square array of length k + 1 . Variance of the likelihood equation ( Pg . 557 14 - 10 Greene 7th edition )
jac
"jacobian" - an n x k + 1-dimensional array of first
derivatives of the pseudo-log-likelihood function w.r.t. the parameters
" jacobian " - an n x k + 1 - dimensional array of first derivatives of the pseudo - log - likelihood function w . r . t . the parameters
design_info
dataframe containing psu, stratum,
population/design weight and/or a finite population corrector (fpc)
dataframe containing psu stratum population / design weight and / or a finite population corrector ( fpc )