akelleh / causality

Tools for causal analysis
MIT License
1.06k stars 128 forks source link

ValueError: zero-size array to reduction operation maximum which has no identity #26

Closed lmsanch closed 7 years ago

lmsanch commented 7 years ago

Hi there. First of all, great library to compliment Judea Pearl's book. I am causality on a df that has about 120 rows by 500 columns, and I am getting the following error:

51     # run the search
     52     ic_algorithm = IC(RobustRegressionTest, data_frame, variable_types)
---> 53     graph = ic_algorithm.search()
     54     solution = graph.edges(data=True)
     55 

/Users/luissanchez/anaconda/lib/python2.7/site-packages/causality/inference/search/__init__.pyc in search(self)
     23     def search(self):
     24         self._build_g()
---> 25         self._find_skeleton()
     26         self._orient_colliders()
     27 

/Users/luissanchez/anaconda/lib/python2.7/site-packages/causality/inference/search/__init__.pyc in _find_skeleton(self)
    124                 for z in itertools.combinations(z_candidates, N):
    125                     test = self.independence_test([y], [x], list(z), 
--> 126                         self.data, self.alpha)
    127                     if test.independent():
    128                         self._g.remove_edge(x,y)

/Users/luissanchez/anaconda/lib/python2.7/site-packages/causality/inference/independence_tests/__init__.pyc in __init__(self, y, x, z, data, alpha)
      4 class RobustRegressionTest():
      5     def __init__(self, y, x, z, data, alpha):
----> 6         self.regression = sm.RLM(data[y], data[x+z])
      7         self.result = self.regression.fit()
      8         self.coefficient = self.result.params[x][0]

/Users/luissanchez/anaconda/lib/python2.7/site-packages/statsmodels/robust/robust_linear_model.pyc in __init__(self, endog, exog, M, missing, **kwargs)
    115         self.M = M
    116         super(base.LikelihoodModel, self).__init__(endog, exog,
--> 117                 missing=missing, **kwargs)
    118         self._initialize()
    119         #things to remove_data

/Users/luissanchez/anaconda/lib/python2.7/site-packages/statsmodels/base/model.pyc in __init__(self, endog, exog, **kwargs)
     58         hasconst = kwargs.pop('hasconst', None)
     59         self.data = self._handle_data(endog, exog, missing, hasconst,
---> 60                                       **kwargs)
     61         self.k_constant = self.data.k_constant
     62         self.exog = self.data.exog

/Users/luissanchez/anaconda/lib/python2.7/site-packages/statsmodels/base/model.pyc in _handle_data(self, endog, exog, missing, hasconst, **kwargs)
     82 
     83     def _handle_data(self, endog, exog, missing, hasconst, **kwargs):
---> 84         data = handle_data(endog, exog, missing, hasconst, **kwargs)
     85         # kwargs arrays could have changed, easier to just attach here
     86         for key in kwargs:

/Users/luissanchez/anaconda/lib/python2.7/site-packages/statsmodels/base/data.pyc in handle_data(endog, exog, missing, hasconst, **kwargs)
    564     klass = handle_data_class_factory(endog, exog)
    565     return klass(endog, exog=exog, missing=missing, hasconst=hasconst,
--> 566                  **kwargs)

/Users/luissanchez/anaconda/lib/python2.7/site-packages/statsmodels/base/data.pyc in __init__(self, endog, exog, missing, hasconst, **kwargs)
     73 
     74         # this has side-effects, attaches k_constant and const_idx
---> 75         self._handle_constant(hasconst)
     76         self._check_integrity()
     77         self._cache = resettable_cache()

/Users/luissanchez/anaconda/lib/python2.7/site-packages/statsmodels/base/data.pyc in _handle_constant(self, hasconst)
     91             # detect where the constant is
     92             check_implicit = False
---> 93             const_idx = np.where(self.exog.ptp(axis=0) == 0)[0].squeeze()
     94             self.k_constant = const_idx.size
     95 

ValueError: zero-size array to reduction operation maximum which has no identity

other less dense dfs are running fine. Any idea about what could be wrong? Thanks