Skip to content

ENH: delta method #2155

Open
Open

Description

@josef-pkt

add a standalone, reusable function with options

multivariate version is used in discrete_margins, we had brief discussion, my version is in miscmodels

one issues is how to handle different multi-dimensional use cases

Margins needs vectorized for at='all', in the basic usecase we would need only se, i.e. diagonal.
I think there should be a computational short cut to calculate only the diagonal of vectorized version.

We still need the entire covariance matrix for hypothesis test that involve more than a single effect.

I guess it's:
se = (jac.dot( cov_params) * jac).sum(-1)
where jac is (nobs, k_params, k_params) or (nobs, k_effects, k_params)

Activity

  1. josef-pkt commented on Dec 24, 2014

    @josef-pkt
    MemberAuthor

    np.dot can handle (nobs, k1, k2) dot (k2, k3) to give (nobs, k1, k3) most likely faster than einsum

    dot product for each pair by rows (first index) using einsum (regular dot won't work)

    >>> xx = np.arange(2 * 3 * 3).reshape(2,3,3)
    
    >>> np.einsum('kij, kjl -> kil', xx, xx)
    array([[[ 15,  18,  21],
            [ 42,  54,  66],
            [ 69,  90, 111]],
    
           [[366, 396, 426],
            [474, 513, 552],
            [582, 630, 678]]])
    >>> for xxi in xx: xxi.dot(xxi)
    ... 
    array([[ 15,  18,  21],
           [ 42,  54,  66],
           [ 69,  90, 111]])
    array([[366, 396, 426],
           [474, 513, 552],
           [582, 630, 678]])
    
    
    >>> np.einsum('kij, klj -> kil', xx, xx)
    array([[[  5,  14,  23],
            [ 14,  50,  86],
            [ 23,  86, 149]],
    
           [[302, 392, 482],
            [392, 509, 626],
            [482, 626, 770]]])
    >>> for xxi in xx: xxi.dot(xxi.T)
    ... 
    array([[  5,  14,  23],
           [ 14,  50,  86],
           [ 23,  86, 149]])
    array([[302, 392, 482],
           [392, 509, 626],
           [482, 626, 770]])
    
  2. josef-pkt commented on Dec 24, 2014

    @josef-pkt
    MemberAuthor

    a bit related: at several occasions I was looking at vectorized hessian, hessian_obs, but there wasn't any real usecase, for the final calculations only the sum or average over observations is relevant, even though hessian_obs might show up in the theory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions