cdt15 / lingam

Python package for causal discovery based on LiNGAM.
https://sites.google.com/view/sshimizu06/lingam
MIT License
368 stars 56 forks source link

VARLiNGAM statsmodels #86

Closed TomVanDeuren closed 1 year ago

TomVanDeuren commented 1 year ago

Dear, if I run VARLiNGAM with the latest version of statsmodels (0.14.0) installed, I seem to be getting an error:

Traceback (most recent call last):
  File ".../var_lingam.py", line 79, in <module>
    model.fit(df1)
  File ".../opt/anaconda3/envs/lingam/lib/python3.9/site-packages/lingam/var_lingam.py", line 95, in fit
    M_taus, lags, residuals = self._estimate_var_coefs(X)
  File ".../opt/anaconda3/envs/lingam/lib/python3.9/site-packages/lingam/var_lingam.py", line 279, in _estimate_var_coefs
    fitted = var.fit(maxlags=lag, ic=None, trend="nc")
  File ".../opt/anaconda3/envs/lingam/lib/python3.9/site-packages/statsmodels/tsa/vector_ar/var_model.py", line 656, in fit
    raise ValueError("trend '{}' not supported for VAR".format(trend))
ValueError: trend 'nc' not supported for VAR

With an older version (0.12.2) everything seems to be working fine.

Thanks

nick111 commented 1 year ago

I believe the error is due to a recent modification of statsmodels. According to this article (https://github.com/statsmodels/statsmodels/pull/7593 ), all "nc" has been replaced with "n". All codes in lingam that pass "nc" to statsmodels functions should be changed to "n".

haraoka-screen commented 1 year ago

@TomVanDeuren Thank you for your bug report.

@nick111 Thank you for the valuable information. I'll apply your solution to the code.