{"action":"created","issue":{"url":"https://api.github.com/repos/statsmodels/statsmodels/issues/2152","labels_url":"https://api.github.com/repos/statsmodels/statsmodels/issues/2152/labels{/name}","comments_url":"https://api.github.com/repos/statsmodels/statsmodels/issues/2152/comments","events_url":"https://api.github.com/repos/statsmodels/statsmodels/issues/2152/events","html_url":"https://github.com/statsmodels/statsmodels/issues/2152","id":52609033,"number":2152,"title":"Issues with UnivariateKDE.evaluate","user":{"login":"mwaskom","id":315810,"avatar_url":"https://avatars.githubusercontent.com/u/315810?v=3","gravatar_id":"","url":"https://api.github.com/users/mwaskom","html_url":"https://github.com/mwaskom","followers_url":"https://api.github.com/users/mwaskom/followers","following_url":"https://api.github.com/users/mwaskom/following{/other_user}","gists_url":"https://api.github.com/users/mwaskom/gists{/gist_id}","starred_url":"https://api.github.com/users/mwaskom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mwaskom/subscriptions","organizations_url":"https://api.github.com/users/mwaskom/orgs","repos_url":"https://api.github.com/users/mwaskom/repos","events_url":"https://api.github.com/users/mwaskom/events{/privacy}","received_events_url":"https://api.github.com/users/mwaskom/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/statsmodels/statsmodels/labels/comp-nonparametric","name":"comp-nonparametric","color":"ededed"},{"url":"https://api.github.com/repos/statsmodels/statsmodels/labels/type-bug","name":"type-bug","color":"ff9999"}],"state":"open","locked":false,"assignee":{"login":"jseabold","id":296164,"avatar_url":"https://avatars.githubusercontent.com/u/296164?v=3","gravatar_id":"","url":"https://api.github.com/users/jseabold","html_url":"https://github.com/jseabold","followers_url":"https://api.github.com/users/jseabold/followers","following_url":"https://api.github.com/users/jseabold/following{/other_user}","gists_url":"https://api.github.com/users/jseabold/gists{/gist_id}","starred_url":"https://api.github.com/users/jseabold/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jseabold/subscriptions","organizations_url":"https://api.github.com/users/jseabold/orgs","repos_url":"https://api.github.com/users/jseabold/repos","events_url":"https://api.github.com/users/jseabold/events{/privacy}","received_events_url":"https://api.github.com/users/jseabold/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/statsmodels/statsmodels/milestones/7","labels_url":"https://api.github.com/repos/statsmodels/statsmodels/milestones/7/labels","id":756183,"number":7,"title":"0.7","description":"","creator":{"login":"josef-pkt","id":440735,"avatar_url":"https://avatars.githubusercontent.com/u/440735?v=3","gravatar_id":"","url":"https://api.github.com/users/josef-pkt","html_url":"https://github.com/josef-pkt","followers_url":"https://api.github.com/users/josef-pkt/followers","following_url":"https://api.github.com/users/josef-pkt/following{/other_user}","gists_url":"https://api.github.com/users/josef-pkt/gists{/gist_id}","starred_url":"https://api.github.com/users/josef-pkt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josef-pkt/subscriptions","organizations_url":"https://api.github.com/users/josef-pkt/orgs","repos_url":"https://api.github.com/users/josef-pkt/repos","events_url":"https://api.github.com/users/josef-pkt/events{/privacy}","received_events_url":"https://api.github.com/users/josef-pkt/received_events","type":"User","site_admin":false},"open_issues":147,"closed_issues":28,"state":"open","created_at":"2014-08-16T23:51:52Z","updated_at":"2015-01-19T20:17:27Z","due_on":null,"closed_at":null},"comments":17,"created_at":"2014-12-21T22:59:04Z","updated_at":"2015-01-19T20:24:46Z","closed_at":null,"body":"I'm trying to understand what's causing some surprising behavior with the `KDEUnivariate` class.\r\n\r\n```python\r\nimport numpy as np\r\nfrom statsmodels.nonparametric.kde import KDEUnivariate\r\nx = np.random.randn(20)\r\nkde = KDEUnivariate(x)\r\n```\r\n\r\nSpecifically, the `kde.evaluate` method seems unable to reproduce the `kde.density` property:\r\n\r\n```python\r\nkde.fit()\r\nnp.testing.assert_array_almost_equal(kde.density, kde.evaluate(kde.support))\r\n```\r\n```\r\nAssertionError: \r\nArrays are not almost equal to 6 decimals\r\n\r\n(mismatch 99.21875%)\r\n x: array([ 0.001018,  0.000991,  0.000969,  0.000953,  0.000942,  0.000937,\r\n        0.000937,  0.000943,  0.000953,  0.000969,  0.00099 ,  0.001015,\r\n        0.001046,  0.001082,  0.001123,  0.00117 ,  0.001221,  0.001278,...\r\n y: array([  3.280454e-04,   3.543112e-04,   3.824256e-04,   4.124967e-04,\r\n         4.446365e-04,   4.789620e-04,   5.155945e-04,   5.546600e-04,\r\n         5.962887e-04,   6.406158e-04,   6.877806e-04,   7.379272e-04,...\r\n```\r\n\r\nThis is a subtle difference:\r\n```python\r\nimport matplotlib.pyplot as plt\r\nimport seaborn\r\nplt.plot(kde.support, kde.density, lw=5)\r\nplt.plot(kde.support, kde.evaluate(kde.support), \"--\", lw=5)\r\n```\r\n![kde](https://cloud.githubusercontent.com/assets/315810/5519987/c83a0594-893a-11e4-9391-2362eaf359f1.png)\r\n\r\n\r\nIt seems to be because `evaluate()` is not picking up the `fft` option:\r\n\r\n```python\r\nkde.fit(fft=False)\r\nnp.testing.assert_array_almost_equal(kde.density, kde.evaluate(kde.support))\r\n```\r\n\r\nAlthough, this fails a stricter test:\r\n\r\n```python\r\nnp.testing.assert_array_equal(kde.density, kde.evaluate(kde.support))\r\n```\r\n```\r\nAssertionError: \r\nArrays are not equal\r\n\r\n(mismatch 68.0%)\r\n x: array([  3.280454e-04,   7.088984e-04,   1.425063e-03,   2.664943e-03,\r\n         4.636106e-03,   7.503213e-03,   1.129811e-02,   1.583096e-02,\r\n         2.065008e-02,   2.509707e-02,   2.847294e-02,   3.028022e-02,...\r\n y: array([  3.280454e-04,   7.088984e-04,   1.425063e-03,   2.664943e-03,\r\n         4.636106e-03,   7.503213e-03,   1.129811e-02,   1.583096e-02,\r\n         2.065008e-02,   2.509707e-02,   2.847294e-02,   3.028022e-02,...\r\n```\r\n\r\nMore troubling is that trying to use `evaluate` with a non-gaussian kernel raises an exception:\r\n\r\n```python\r\nkde.fit(kernel=\"tri\", fft=False)\r\nkde.evaluate(kde.support)\r\n```\r\n```\r\n---------------------------------------------------------------------------\r\nValueError                                Traceback (most recent call last)\r\n<ipython-input-16-bb57467307a4> in <module>()\r\n      1 kde.fit(kernel=\"tri\", fft=False)\r\n----> 2 kde.evaluate(kde.support)\r\n\r\n/Users/mwaskom/anaconda/lib/python2.7/site-packages/statsmodels/nonparametric/kde.pyc in evaluate(self, point)\r\n    256         \"\"\"\r\n    257         _checkisfit(self)\r\n--> 258         return self.kernel.density(self.endog, point)\r\n    259 \r\n    260 \r\n\r\n/Users/mwaskom/anaconda/lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/kernels.pyc in density(self, xs, x)\r\n    181         xs = np.asarray(xs)\r\n    182         n = len(xs) # before inDomain?\r\n--> 183         xs = self.inDomain( xs, xs, x )[0]\r\n    184         if xs.ndim == 1:\r\n    185             xs = xs[:,None]\r\n\r\n/Users/mwaskom/anaconda/lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/kernels.pyc in inDomain(self, xs, ys, x)\r\n    168             return (xs, ys)\r\n    169         else:\r\n--> 170             filtered = filter(isInDomain, zip(xs, ys))\r\n    171             if len(filtered) > 0:\r\n    172                 xs, ys = zip(*filtered)\r\n\r\n/Users/mwaskom/anaconda/lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/kernels.pyc in isInDomain(xy)\r\n    163             \"\"\"Used for filter to check if point is in the domain\"\"\"\r\n    164             u = (xy[0]-x)/self.h\r\n--> 165             return u >= self.domain[0] and u <= self.domain[1]\r\n    166 \r\n    167         if self.domain is None:\r\n\r\nValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()\r\n```"},"comment":{"url":"https://api.github.com/repos/statsmodels/statsmodels/issues/comments/70554860","html_url":"https://github.com/statsmodels/statsmodels/issues/2152#issuecomment-70554860","issue_url":"https://api.github.com/repos/statsmodels/statsmodels/issues/2152","id":70554860,"user":{"login":"josef-pkt","id":440735,"avatar_url":"https://avatars.githubusercontent.com/u/440735?v=3","gravatar_id":"","url":"https://api.github.com/users/josef-pkt","html_url":"https://github.com/josef-pkt","followers_url":"https://api.github.com/users/josef-pkt/followers","following_url":"https://api.github.com/users/josef-pkt/following{/other_user}","gists_url":"https://api.github.com/users/josef-pkt/gists{/gist_id}","starred_url":"https://api.github.com/users/josef-pkt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josef-pkt/subscriptions","organizations_url":"https://api.github.com/users/josef-pkt/orgs","repos_url":"https://api.github.com/users/josef-pkt/repos","events_url":"https://api.github.com/users/josef-pkt/events{/privacy}","received_events_url":"https://api.github.com/users/josef-pkt/received_events","type":"User","site_admin":false},"created_at":"2015-01-19T20:24:46Z","updated_at":"2015-01-19T20:24:46Z","body":"@jseabold  if you have a day available for statsmodels, then reviewing kalman filter, statespace model and SARIMAX would be more important. "}}