src/estimagic/sensitivity/msm_sensitivity.py
def calculate_sensitivity_to_weighting(jac, weights, moments_cov, params_cov):
    """calculate the sensitivity to weighting.

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

    It answers the following question: How would the precision change if the weight of
        the kth moment is increased a little?

    Args:
        sensitivity_to_bias (np.ndarray or pandas.DataFrame): See
            ``calculate_sensitivity_to_bias`` for details.
        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 (numpy.ndarray or pandas.DataFrame): The covariance matrix of the
            parameter estimates.

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

    """
    _jac, _weights, _moments_cov, _params_cov, names = process_pandas_arguments(
        jac=jac, weights=weights, moments_cov=moments_cov, params_cov=params_cov
    )
    gwg_inverse = _sandwich(_jac, _weights)
    gwg_inverse = robust_inverse(gwg_inverse, INVALID_SENSITIVITY_MSG)

    m6 = []

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

        m6k_1 = gwg_inverse @ _sandwich(_jac, mask_matrix_o) @ _params_cov
        m6k_2 = (
            gwg_inverse
            @ _jac.T
            @ mask_matrix_o
            @ _moments_cov
            @ _weights
            @ _jac
            @ gwg_inverse
        )
        m6k_3 = (
            gwg_inverse
            @ _jac.T
            @ _weights
            @ _moments_cov
            @ mask_matrix_o
            @ _jac
            @ gwg_inverse
        )
        m6k_4 = _params_cov @ _sandwich(_jac, mask_matrix_o) @ gwg_inverse

        m6k = -m6k_1 + m6k_2 + m6k_3 - m6k_4
        m6k = m6k.diagonal()

        m6.append(m6k)

    m6 = np.array(m6).T

    weights_diagonal = np.diagonal(_weights)
    params_variances = np.diagonal(_params_cov)

    e6 = m6 / params_variances.reshape(-1, 1)
    e6 = e6 * weights_diagonal

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

    return e6
calculate the sensitivity to weighting.

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

    It answers the following question: How would the precision change if the weight of
        the kth moment is increased a little?

    Args:
        sensitivity_to_bias (np.ndarray or pandas.DataFrame): See
            ``calculate_sensitivity_to_bias`` for details.
        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 (numpy.ndarray or pandas.DataFrame): The covariance matrix of the
            parameter estimates.

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

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


calculate the sensitivity to weighting . The sensitivity measure is calculated for each parameter wrt each moment .
def calculate_sensitivity_to_weighting(jac, weights, moments_cov, params_cov):
    _jac, _weights, _moments_cov, _params_cov, names = process_pandas_arguments(
        jac=jac, weights=weights, moments_cov=moments_cov, params_cov=params_cov
    )
    gwg_inverse = _sandwich(_jac, _weights)
    gwg_inverse = robust_inverse(gwg_inverse, INVALID_SENSITIVITY_MSG)
    m6 = []
    for k in range(len(_weights)):
        mask_matrix_o = np.zeros(shape=_weights.shape)
        mask_matrix_o[k, k] = 1
        m6k_1 = gwg_inverse @ _sandwich(_jac, mask_matrix_o) @ _params_cov
        m6k_2 = (
            gwg_inverse
            @ _jac.T
            @ mask_matrix_o
            @ _moments_cov
            @ _weights
            @ _jac
            @ gwg_inverse
        )
        m6k_3 = (
            gwg_inverse
            @ _jac.T
            @ _weights
            @ _moments_cov
            @ mask_matrix_o
            @ _jac
            @ gwg_inverse
        )
        m6k_4 = _params_cov @ _sandwich(_jac, mask_matrix_o) @ gwg_inverse
        m6k = -m6k_1 + m6k_2 + m6k_3 - m6k_4
        m6k = m6k.diagonal()
        m6.append(m6k)
    m6 = np.array(m6).T
    weights_diagonal = np.diagonal(_weights)
    params_variances = np.diagonal(_params_cov)
    e6 = m6 / params_variances.reshape(-1, 1)
    e6 = e6 * weights_diagonal
    if names:
        e6 = pd.DataFrame(e6, index=names.get("params"), columns=names.get("moments"))
    return e6
def calculate_sensitivity_to_weighting ( jac , weights , moments_cov , params_cov ) : _jac , _weights , _moments_cov , _params_cov , names = process_pandas_arguments ( jac = jac , weights = weights , moments_cov = moments_cov , params_cov = params_cov ) gwg_inverse = _sandwich ( _jac , _weights ) gwg_inverse = robust_inverse ( gwg_inverse , INVALID_SENSITIVITY_MSG ) m6 = [ ] for k in range ( len ( _weights ) ) : mask_matrix_o = np . zeros ( shape = _weights . shape ) mask_matrix_o [ k , k ] = 1 m6k_1 = gwg_inverse @ _sandwich ( _jac , mask_matrix_o ) @ _params_cov m6k_2 = ( gwg_inverse @ _jac . T @ mask_matrix_o @ _moments_cov @ _weights @ _jac @ gwg_inverse ) m6k_3 = ( gwg_inverse @ _jac . T @ _weights @ _moments_cov @ mask_matrix_o @ _jac @ gwg_inverse ) m6k_4 = _params_cov @ _sandwich ( _jac , mask_matrix_o ) @ gwg_inverse m6k = - m6k_1 + m6k_2 + m6k_3 - m6k_4 m6k = m6k . diagonal ( ) m6 . append ( m6k ) m6 = np . array ( m6 ) . T weights_diagonal = np . diagonal ( _weights ) params_variances = np . diagonal ( _params_cov ) e6 = m6 / params_variances . reshape ( - 1 , 1 ) e6 = e6 * weights_diagonal if names : e6 = pd . DataFrame ( e6 , index = names . get ( "params" ) , columns = names . get ( "moments" ) ) return e6
calculate the sensitivity to weighting.
calculate the sensitivity to weighting .
"""calculate the sensitivity to weighting.

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

    It answers the following question: How would the precision change if the weight of
        the kth moment is increased a little?

    Args:
        sensitivity_to_bias (np.ndarray or pandas.DataFrame): See
            ``calculate_sensitivity_to_bias`` for details.
        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 (numpy.ndarray or pandas.DataFrame): The covariance matrix of the
            parameter estimates.

    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
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
The covariance matrix of the
parameter estimates.
The covariance matrix of the parameter estimates .
sensitivity_to_bias
See
``calculate_sensitivity_to_bias`` for details.
See ` ` calculate_sensitivity_to_bias ` ` for details .