Skip to content

ENH: SVAR with no unknown A, B parameters #9436

Open

Description

@menghan465

edit shape problem as in #9302 and empty parameter for A, B. A, B are fully known is not supported.

import numpy as np
import pandas as pd
import statsmodels.api as sm
np.random.seed(123)
nobs = 1000
data = np.random.randn(nobs, 2)
df = pd.DataFrame(data, columns=['y1', 'y2'])
A = np.array([[1, 0], [0.5, 1]])
B = np.identity(2)
svar_model = sm.tsa.SVAR(df, svar_type='A', A=A, B=B)
svar_result = svar_model.fit()
print(svar_result.summary())
1732464486237

Activity

  1. josef-pkt commented on Nov 24, 2024

    @josef-pkt
    Member

    my guess is that it is the same as #9302

  2. josef-pkt commented on Nov 24, 2024

    @josef-pkt
    Member

    mabye not the same

    A and B are fully specified, there are no structural params to estimate

    But A_mask and B_mask are boolean scalar instead of array.
    Something is wrong with shape if a mask is empty.

    ipdb> p A
    array([[1. , 0. ],
           [0.5, 1. ]])
    ipdb> p A_mask
    False
    ipdb> start_params[:A_len]
    array([], dtype=float64)
    ipdb> start_params[A_len:]
    array([], dtype=float64)
    ipdb> start_params
    array([], dtype=float64)
    ipdb> B_mask
    False
    
  3. josef-pkt commented on Nov 24, 2024

    @josef-pkt
    Member

    @menghan465 What's your numpy version?

    reason that maks is scalar boolean if empty is:

    ipdb> np.logical_or(A == 'E', A == 'e')
    <stdin>:1: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
    False
    ipdb> np.__version__
    '1.21.5'
    
  4. menghan465 commented on Nov 24, 2024

    @menghan465
    Author

    @menghan465 What's your numpy version?

    reason that maks is scalar boolean if empty is:

    ipdb> np.logical_or(A == 'E', A == 'e')
    <stdin>:1: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
    False
    ipdb> np.__version__
    '1.21.5'
    
    微信图片_20241125011500
  5. josef-pkt commented on Nov 24, 2024

    @josef-pkt
    Member

    ok, I will fix logical_or for, I guess, numpy < 2.0

    However, that will not fix possible problems if both A and B have no parameters to estimate.
    I don't remember how SVAR estimation works, but most likely it cannot handle empty parameters.

    Another issue with my current numpy

    dtype of A and B

    A in example here is float/float64.
    A in unit test has dtype "U"
    internally stored, attributes A and B are float with np.nan instead of "E".

    (A == 'e')
    ...\Local\Temp\ipykernel_22988\2041847108.py:1: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
      (A == 'e')
    False
    
    A.astype("U") == "e"
    array([[False, False],
           [False, False]])
    
  6. josef-pkt commented on Nov 24, 2024

    @josef-pkt
    Member

    fix with A = A.astype("U") and for B works to get around shape problem

    But this example errors then in rank check with eventually
    ValueError: zero-size array to reduction operation maximum which has no identity

        354             J = self._compute_J(A, B)
        355             self.check_order(J)
    --> 356             self.check_rank(J)
    

    So empty params problems here is in addition to shape problem in #9302

    I'm not sure whether we should try to fix that.
    It does not have the SVAR simultaneous estimation problem anymore.
    I guess it still does not reduce to standard VAR, e.g. it could be a known triangular structure in A.

  7. changed the title [-]Not sure what's wrong with this one.[/-] [+]ENH: SVAR with no unknown A, B parameters[/+] on Nov 24, 2024
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