Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value Error when computing optimal bandwidth #9

Open
ojwenzel opened this issue Nov 2, 2019 · 0 comments
Open

Value Error when computing optimal bandwidth #9

ojwenzel opened this issue Nov 2, 2019 · 0 comments

Comments

@ojwenzel
Copy link

ojwenzel commented Nov 2, 2019

I'm running the following line in a jupyter notebook to compute the optimal bandwidth.

bandwidth_opt = rdd.optimal_bandwidth(data[predictor], data[target], cut=threshold)

where data is a pandas data frame. The columns have 20 non-nan entries. The predictor column ist of dtype int64 and the target is of dtype float64. The dataset is actually the original dataset from the paper on RDD by Thistlethwait and Capbell. I added the output with the Exception below.
As far as I can interpret the error the function cannot find an optimal bandwidth, but I have not traced back the error!

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-10-85f5965b1696> in <module>
----> 1 bandwidth_opt = rdd.optimal_bandwidth(data[predictor], data[target], cut=threshold)

~/anaconda3/envs/causality/lib/python3.7/site-packages/rdd/rdd.py in optimal_bandwidth(Y, X, cut)
     44     dat_temp['X3'] = X**3
     45     eqn = 'Y ~ 1 + treat + X + X2 + X3'
---> 46     results = smf.ols(eqn, data=dat_temp).fit()
     47     m3 = 6*results.params.loc['X3']
     48     h2pos = 3.56 * (X[X>=0].shape[0]**(-1/7.0)) * (sig2c/(fXc * np.max([m3**2, .01]))) ** (1/7.0)

~/anaconda3/envs/causality/lib/python3.7/site-packages/statsmodels/base/model.py in from_formula(cls, formula, data, subset, drop_cols, *args, **kwargs)
    176                        'formula': formula,  # attach formula for unpckling
    177                        'design_info': design_info})
--> 178         mod = cls(endog, exog, *args, **kwargs)
    179         mod.formula = formula
    180 

~/anaconda3/envs/causality/lib/python3.7/site-packages/statsmodels/regression/linear_model.py in __init__(self, endog, exog, missing, hasconst, **kwargs)
    836                  **kwargs):
    837         super(OLS, self).__init__(endog, exog, missing=missing,
--> 838                                   hasconst=hasconst, **kwargs)
    839         if "weights" in self._init_keys:
    840             self._init_keys.remove("weights")

~/anaconda3/envs/causality/lib/python3.7/site-packages/statsmodels/regression/linear_model.py in __init__(self, endog, exog, weights, missing, hasconst, **kwargs)
    682             weights = weights.squeeze()
    683         super(WLS, self).__init__(endog, exog, missing=missing,
--> 684                                   weights=weights, hasconst=hasconst, **kwargs)
    685         nobs = self.exog.shape[0]
    686         weights = self.weights

~/anaconda3/envs/causality/lib/python3.7/site-packages/statsmodels/regression/linear_model.py in __init__(self, endog, exog, **kwargs)
    194     """
    195     def __init__(self, endog, exog, **kwargs):
--> 196         super(RegressionModel, self).__init__(endog, exog, **kwargs)
    197         self._data_attr.extend(['pinv_wexog', 'wendog', 'wexog', 'weights'])
    198 

~/anaconda3/envs/causality/lib/python3.7/site-packages/statsmodels/base/model.py in __init__(self, endog, exog, **kwargs)
    214 
    215     def __init__(self, endog, exog=None, **kwargs):
--> 216         super(LikelihoodModel, self).__init__(endog, exog, **kwargs)
    217         self.initialize()
    218 

~/anaconda3/envs/causality/lib/python3.7/site-packages/statsmodels/base/model.py in __init__(self, endog, exog, **kwargs)
     66         hasconst = kwargs.pop('hasconst', None)
     67         self.data = self._handle_data(endog, exog, missing, hasconst,
---> 68                                       **kwargs)
     69         self.k_constant = self.data.k_constant
     70         self.exog = self.data.exog

~/anaconda3/envs/causality/lib/python3.7/site-packages/statsmodels/base/model.py in _handle_data(self, endog, exog, missing, hasconst, **kwargs)
     89 
     90     def _handle_data(self, endog, exog, missing, hasconst, **kwargs):
---> 91         data = handle_data(endog, exog, missing, hasconst, **kwargs)
     92         # kwargs arrays could have changed, easier to just attach here
     93         for key in kwargs:

~/anaconda3/envs/causality/lib/python3.7/site-packages/statsmodels/base/data.py in handle_data(endog, exog, missing, hasconst, **kwargs)
    633     klass = handle_data_class_factory(endog, exog)
    634     return klass(endog, exog=exog, missing=missing, hasconst=hasconst,
--> 635                  **kwargs)

~/anaconda3/envs/causality/lib/python3.7/site-packages/statsmodels/base/data.py in __init__(self, endog, exog, missing, hasconst, **kwargs)
     78         self.const_idx = None
     79         self.k_constant = 0
---> 80         self._handle_constant(hasconst)
     81         self._check_integrity()
     82         self._cache = {}

~/anaconda3/envs/causality/lib/python3.7/site-packages/statsmodels/base/data.py in _handle_constant(self, hasconst)
    122             # detect where the constant is
    123             check_implicit = False
--> 124             ptp_ = np.ptp(self.exog, axis=0)
    125             if not np.isfinite(ptp_).all():
    126                 raise MissingDataError('exog contains inf or nans')

<__array_function__ internals> in ptp(*args, **kwargs)

~/anaconda3/envs/causality/lib/python3.7/site-packages/numpy/core/fromnumeric.py in ptp(a, axis, out, keepdims)
   2494         else:
   2495             return ptp(axis=axis, out=out, **kwargs)
-> 2496     return _methods._ptp(a, axis=axis, out=out, **kwargs)
   2497 
   2498 

~/anaconda3/envs/causality/lib/python3.7/site-packages/numpy/core/_methods.py in _ptp(a, axis, out, keepdims)
    228 def _ptp(a, axis=None, out=None, keepdims=False):
    229     return um.subtract(
--> 230         umr_maximum(a, axis, None, out, keepdims),
    231         umr_minimum(a, axis, None, None, keepdims),
    232         out

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant