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

Adjacency matrix for varlingam #43

Closed UzmaHasan closed 2 years ago

UzmaHasan commented 2 years ago

I simply tried to test a dataset with lag=30 with the bellow code snippet but it gives at most 14 adjacency matrix as output. What could be the resaon?

model = lingam.VARLiNGAM(lags=30, criterion='bic',prune=True) model.fit(X) print(model._adjacency_matrices)

ikeuchi-screen commented 2 years ago

@UzmaHasan Thanks for using lingam.

VARLiNGAM uses a VAR of statsmodels. In this VAR, the optimal order is calculated by specifying the Information criterion. https://www.statsmodels.org/dev/generated/statsmodels.tsa.vector_ar.var_model.VAR.fit.html#statsmodels.tsa.vector_ar.var_model.VAR.fit

You can specify the criterion at instance creation in VARLiNGAM as well. The default setting is bic, and the optimal order is used below the value specified for lags. Therefore, even if you specify lags=2, the optimal lags=1 may be selected as a result.

If you set criterion=None, the specified lags should be used as is.

import lingam
model = lingam.VARLiNGAM(lags=30, criterion=None, prune=True)
model.fit(X)
UzmaHasan commented 2 years ago

Thanks @ikeuchi-screen for such a quick and detailed solution. Appreciate it a lot!

UzmaHasan commented 2 years ago

Closing it as @ikeuchi-screen provided the solution already.