src/estimagic/sensitivity/msm_sensitivity.py
def calculate_fundamental_sensitivity_to_removal(jac, moments_cov, params_cov_opt):
    """calculate the fundamental sensitivity to removal.

    The sensitivity measure is calculated for each parameter wrt each moment.

    It answers the following question: How much precision would be lost if the kth
        moment was excluded from the estimation with if the optimal weighting matrix is
        used?

    Args:
        jac (np.ndarray or pandas.DataFrame): The jacobian of simulate_moments with
            respect to params, evaluated at the  point estimates.
        weights (np.ndarray or pandas.DataFrame): The weighting matrix used for
            msm estimation.
        moments_cov (numpy.ndarray or pandas.DataFrame): The covariance matrix of the
            empirical moments.
        params_cov_opt (numpy.ndarray or pandas.DataFrame): The covariance matrix of the
            parameter estimates. Note that this needs to be the parameter covariance
            matrix using the formula for asymptotically optimal MSM.

    Returns:
        np.ndarray or pd.DataFrame: Sensitivity measure with shape (n_params, n_moments)

    """
    _jac, _moments_cov, _params_cov_opt, names = process_pandas_arguments(
        jac=jac,
        moments_cov=moments_cov,
        params_cov_opt=params_cov_opt,
    )
    m5 = []

    for k in range(len(_moments_cov)):
        g_k = np.copy(_jac)
        g_k = np.delete(g_k, k, axis=0)

        s_k = np.copy(_moments_cov)
        s_k = np.delete(s_k, k, axis=0)
        s_k = np.delete(s_k, k, axis=1)

        sigma_k = _sandwich(g_k, robust_inverse(s_k, INVALID_SENSITIVITY_MSG))
        sigma_k = robust_inverse(sigma_k, INVALID_SENSITIVITY_MSG)

        m5k = sigma_k - _params_cov_opt
        m5k = m5k.diagonal()

        m5.append(m5k)

    m5 = np.array(m5).T

    params_variances = np.diagonal(_params_cov_opt)
    e5 = m5 / params_variances.reshape(-1, 1)

    if names:
        e5 = pd.DataFrame(e5, index=names.get("params"), columns=names.get("moments"))

    return e5
calculate the fundamental sensitivity to removal.

    The sensitivity measure is calculated for each parameter wrt each moment.

    It answers the following question: How much precision would be lost if the kth
        moment was excluded from the estimation with if the optimal weighting matrix is
        used?

    Args:
        jac (np.ndarray or pandas.DataFrame): The jacobian of simulate_moments with
            respect to params, evaluated at the  point estimates.
        weights (np.ndarray or pandas.DataFrame): The weighting matrix used for
            msm estimation.
        moments_cov (numpy.ndarray or pandas.DataFrame): The covariance matrix of the
            empirical moments.
        params_cov_opt (numpy.ndarray or pandas.DataFrame): The covariance matrix of the
            parameter estimates. Note that this needs to be the parameter covariance
            matrix using the formula for asymptotically optimal MSM.

    Returns:
        np.ndarray or pd.DataFrame: Sensitivity measure with shape (n_params, n_moments)

    
calculate the fundamental sensitivity to removal.
The sensitivity measure is calculated for each parameter wrt each moment.


calculate the fundamental sensitivity to removal . The sensitivity measure is calculated for each parameter wrt each moment .
def calculate_fundamental_sensitivity_to_removal(jac, moments_cov, params_cov_opt):
    _jac, _moments_cov, _params_cov_opt, names = process_pandas_arguments(
        jac=jac,
        moments_cov=moments_cov,
        params_cov_opt=params_cov_opt,
    )
    m5 = []
    for k in range(len(_moments_cov)):
        g_k = np.copy(_jac)
        g_k = np.delete(g_k, k, axis=0)
        s_k = np.copy(_moments_cov)
        s_k = np.delete(s_k, k, axis=0)
        s_k = np.delete(s_k, k, axis=1)
        sigma_k = _sandwich(g_k, robust_inverse(s_k, INVALID_SENSITIVITY_MSG))
        sigma_k = robust_inverse(sigma_k, INVALID_SENSITIVITY_MSG)
        m5k = sigma_k - _params_cov_opt
        m5k = m5k.diagonal()
        m5.append(m5k)
    m5 = np.array(m5).T
    params_variances = np.diagonal(_params_cov_opt)
    e5 = m5 / params_variances.reshape(-1, 1)
    if names:
        e5 = pd.DataFrame(e5, index=names.get("params"), columns=names.get("moments"))
    return e5
def calculate_fundamental_sensitivity_to_removal ( jac , moments_cov , params_cov_opt ) : _jac , _moments_cov , _params_cov_opt , names = process_pandas_arguments ( jac = jac , moments_cov = moments_cov , params_cov_opt = params_cov_opt , ) m5 = [ ] for k in range ( len ( _moments_cov ) ) : g_k = np . copy ( _jac ) g_k = np . delete ( g_k , k , axis = 0 ) s_k = np . copy ( _moments_cov ) s_k = np . delete ( s_k , k , axis = 0 ) s_k = np . delete ( s_k , k , axis = 1 ) sigma_k = _sandwich ( g_k , robust_inverse ( s_k , INVALID_SENSITIVITY_MSG ) ) sigma_k = robust_inverse ( sigma_k , INVALID_SENSITIVITY_MSG ) m5k = sigma_k - _params_cov_opt m5k = m5k . diagonal ( ) m5 . append ( m5k ) m5 = np . array ( m5 ) . T params_variances = np . diagonal ( _params_cov_opt ) e5 = m5 / params_variances . reshape ( - 1 , 1 ) if names : e5 = pd . DataFrame ( e5 , index = names . get ( "params" ) , columns = names . get ( "moments" ) ) return e5
calculate the fundamental sensitivity to removal.
calculate the fundamental sensitivity to removal .
"""calculate the fundamental sensitivity to removal.

    The sensitivity measure is calculated for each parameter wrt each moment.

    It answers the following question: How much precision would be lost if the kth
        moment was excluded from the estimation with if the optimal weighting matrix is
        used?

    Args:
        jac (np.ndarray or pandas.DataFrame): The jacobian of simulate_moments with
            respect to params, evaluated at the  point estimates.
        weights (np.ndarray or pandas.DataFrame): The weighting matrix used for
            msm estimation.
        moments_cov (numpy.ndarray or pandas.DataFrame): The covariance matrix of the
            empirical moments.
        params_cov_opt (numpy.ndarray or pandas.DataFrame): The covariance matrix of the
            parameter estimates. Note that this needs to be the parameter covariance
            matrix using the formula for asymptotically optimal MSM.

    Returns:
        np.ndarray or pd.DataFrame: Sensitivity measure with shape (n_params, n_moments)

    """
np.ndarray or pd.DataFrame: Sensitivity measure with shape (n_params, n_moments)
np . ndarray or pd . DataFrame : Sensitivity measure with shape ( n_params n_moments )
jac
The jacobian of simulate_moments with
respect to params, evaluated at the  point estimates.
The jacobian of simulate_moments with respect to params evaluated at the point estimates .
moments_cov
The covariance matrix of the
empirical moments.
The covariance matrix of the empirical moments .
params_cov_opt
The covariance matrix of the
parameter estimates. Note that this needs to be the parameter covariance
matrix using the formula for asymptotically optimal MSM.
The covariance matrix of the parameter estimates . Note that this needs to be the parameter covariance matrix using the formula for asymptotically optimal MSM .
weights
The weighting matrix used for
msm estimation.
The weighting matrix used for msm estimation .