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

    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 subject to a little additional noise 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, _weights, _moments_cov, _params_cov_opt, names = process_pandas_arguments(
        jac=jac, weights=weights, moments_cov=moments_cov, params_cov_opt=params_cov_opt
    )

    m2 = []

    for k in range(len(_weights)):
        mask_matrix_o = np.zeros(shape=_weights.shape)
        mask_matrix_o[k, k] = 1

        meat = _sandwich_plus(_jac, _weights, mask_matrix_o)

        m2k = _params_cov_opt @ meat @ _params_cov_opt
        m2k = np.diagonal(m2k)

        m2.append(m2k)

    m2 = np.array(m2).T

    moments_variances = np.diagonal(_moments_cov)
    params_variances = np.diagonal(_params_cov_opt)

    e2 = m2 / params_variances.reshape(-1, 1)
    e2 = e2 * moments_variances

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

    return e2
calculate the fundamental sensitivity to noise.

    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 subject to a little additional noise 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 noise.
The sensitivity measure is calculated for each parameter wrt each moment.


calculate the fundamental sensitivity to noise . The sensitivity measure is calculated for each parameter wrt each moment .
def calculate_fundamental_sensitivity_to_noise(
    jac, weights, moments_cov, params_cov_opt
):
    _jac, _weights, _moments_cov, _params_cov_opt, names = process_pandas_arguments(
        jac=jac, weights=weights, moments_cov=moments_cov, params_cov_opt=params_cov_opt
    )
    m2 = []
    for k in range(len(_weights)):
        mask_matrix_o = np.zeros(shape=_weights.shape)
        mask_matrix_o[k, k] = 1
        meat = _sandwich_plus(_jac, _weights, mask_matrix_o)
        m2k = _params_cov_opt @ meat @ _params_cov_opt
        m2k = np.diagonal(m2k)
        m2.append(m2k)
    m2 = np.array(m2).T
    moments_variances = np.diagonal(_moments_cov)
    params_variances = np.diagonal(_params_cov_opt)
    e2 = m2 / params_variances.reshape(-1, 1)
    e2 = e2 * moments_variances
    if names:
        e2 = pd.DataFrame(e2, index=names.get("params"), columns=names.get("moments"))
    return e2
def calculate_fundamental_sensitivity_to_noise ( jac , weights , moments_cov , params_cov_opt ) : _jac , _weights , _moments_cov , _params_cov_opt , names = process_pandas_arguments ( jac = jac , weights = weights , moments_cov = moments_cov , params_cov_opt = params_cov_opt ) m2 = [ ] for k in range ( len ( _weights ) ) : mask_matrix_o = np . zeros ( shape = _weights . shape ) mask_matrix_o [ k , k ] = 1 meat = _sandwich_plus ( _jac , _weights , mask_matrix_o ) m2k = _params_cov_opt @ meat @ _params_cov_opt m2k = np . diagonal ( m2k ) m2 . append ( m2k ) m2 = np . array ( m2 ) . T moments_variances = np . diagonal ( _moments_cov ) params_variances = np . diagonal ( _params_cov_opt ) e2 = m2 / params_variances . reshape ( - 1 , 1 ) e2 = e2 * moments_variances if names : e2 = pd . DataFrame ( e2 , index = names . get ( "params" ) , columns = names . get ( "moments" ) ) return e2
calculate the fundamental sensitivity to noise.
calculate the fundamental sensitivity to noise .
"""calculate the fundamental sensitivity to noise.

    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 subject to a little additional noise 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 .
weights
The weighting matrix used for
msm estimation.
The weighting matrix used for msm estimation .
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 .