{"action":"created","comment":{"url":"https://api.github.com/repos/astropy/astropy/pulls/comments/29104627","id":29104627,"diff_hunk":"@@ -790,3 +792,322 @@ def mad_std(data):\n \n     # NOTE: 1. / scipy.stats.norm.ppf(0.75) = 1.482602218505602\n     return median_absolute_deviation(data) * 1.482602218505602\n+\n+\n+\n+def kuiper_FPP(D,N):\n+    \"\"\"Compute the false positive probability for the Kuiper statistic.\n+\n+    Uses the set of four formulas described in Paltani 2004; they report \n+    the resulting function never underestimates the false positive probability \n+    but can be a bit high in the N=40..50 range. (They quote a factor 1.5 at \n+    the 1e-7 level.\n+\n+    Parameters\n+    ----------\n+    D : float\n+        The Kuiper test score.\n+    N : float\n+        The effective sample size.\n+\n+    Returns\n+    -------\n+    fpp : float\n+        The probability of a score this large arising from the null hypothesis.\n+\n+    Reference\n+    ---------\n+    Paltani, S., \"Searching for periods in X-ray observations using \n+    Kuiper's test. Application to the ROSAT PSPC archive\", Astronomy and\n+    Astrophysics, v.240, p.789-790, 2004.\n+\n+    \"\"\"\n+    from scipy.misc import factorial, comb\n+\n+    if D<0. or D>2.:\n+        raise ValueError(\"Must have 0<=D<=2 by definition of the Kuiper test\")\n+\n+    if D<2./N:\n+        return 1. - factorial(N)*(D-1./N)**(N-1)\n+    elif D<3./N:\n+        k = -(N*D-1.)/2.\n+        r = np.sqrt(k**2 - (N*D-2.)/2.)\n+        a, b = -k+r, -k-r\n+        return 1. - factorial(N-1)*(b**(N-1.)*(1.-a)-a**(N-1.)*(1.-b))/float(N)**(N-2)*(b-a)\n+    elif (D>0.5 and N%2==0) or (D>(N-1.)/(2.*N) and N%2==1):\n+        def T(t):\n+            y = D+t/float(N)\n+            return y**(t-3)*(y**3*N-y**2*t*(3.-2./N)/N-t*(t-1)*(t-2)/float(N)**2)\n+        s = 0.\n+        # NOTE: the upper limit of this sum is taken from Stephens 1965\n+        for t in xrange(int(np.floor(N*(1-D)))+1):\n+            term = T(t)*comb(N,t)*(1-D-t/float(N))**(N-t-1)\n+            s += term\n+        return s\n+    else:\n+        z = D*np.sqrt(N) \n+        S1 = 0.\n+        term_eps = 1e-12\n+        abs_eps = 1e-100\n+        for m in itertools.count(1):\n+            T1 = 2.*(4.*m**2*z**2-1.)*np.exp(-2.*m**2*z**2)\n+            so = S1\n+            S1 += T1\n+            if np.abs(S1-so)/(np.abs(S1)+np.abs(so))<term_eps or np.abs(S1-so)<abs_eps:\n+                break\n+        S2 = 0.\n+        for m in itertools.count(1):\n+            T2 = m**2*(4.*m**2*z**2-3.)*np.exp(-2*m**2*z**2)\n+            so = S2\n+            S2 += T2\n+            if np.abs(S2-so)/(np.abs(S2)+np.abs(so))<term_eps or np.abs(S1-so)<abs_eps:\n+                break\n+        return S1 - 8*D/(3.*np.sqrt(N))*S2\n+\n+def kuiper(data, cdf=lambda x: x, args=()):\n+    \"\"\"Compute the Kuiper statistic.\n+    \n+    Use the Kuiper statistic version of the Kolmogorov-Smirnov test to \n+    find the probability that something like data was drawn from the \n+    distribution whose CDF is given as cdf.\n+    \n+    Parameters\n+    ----------\n+    data : array-like\n+        The data values.\n+    cdf : callable\n+        A callable to evaluate the CDF of the distribution being tested\n+        against. Will be called with a vector of all values at once.\n+    args : list-like, optional\n+        Additional arguments to be supplied to cdf.\n+\n+    Returns\n+    -------\n+    D : float\n+        The raw statistic.\n+    fpp : float\n+        The probability of a D this large arising with a sample drawn from\n+        the distribution whose CDF is cdf.\n+\n+    Notes\n+    -----\n+    The Kuiper statistic resembles the Kolmogorov-Smirnov test in that \n+    it is nonparametric and invariant under reparameterizations of the data. \n+    The Kuiper statistic, in addition, is equally sensitive throughout \n+    the domain, and it is also invariant under cyclic permutations (making \n+    it particularly appropriate for analyzing circular data). \n+\n+    Returns (D, fpp), where D is the Kuiper D number and fpp is the \n+    probability that a value as large as D would occur if data was \n+    drawn from cdf.\n+\n+    Warning: The fpp is calculated only approximately, and it can be ","path":"astropy/stats/funcs.py","position":122,"original_position":122,"commit_id":"c7334c57a8f3fc8f056a3ef33816bb93fbe36eff","original_commit_id":"c7334c57a8f3fc8f056a3ef33816bb93fbe36eff","user":{"login":"hamogu","id":498688,"avatar_url":"https://avatars.githubusercontent.com/u/498688?v=3","gravatar_id":"","url":"https://api.github.com/users/hamogu","html_url":"https://github.com/hamogu","followers_url":"https://api.github.com/users/hamogu/followers","following_url":"https://api.github.com/users/hamogu/following{/other_user}","gists_url":"https://api.github.com/users/hamogu/gists{/gist_id}","starred_url":"https://api.github.com/users/hamogu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hamogu/subscriptions","organizations_url":"https://api.github.com/users/hamogu/orgs","repos_url":"https://api.github.com/users/hamogu/repos","events_url":"https://api.github.com/users/hamogu/events{/privacy}","received_events_url":"https://api.github.com/users/hamogu/received_events","type":"User","site_admin":false},"body":"Sphinx would render the warning as a box with red background (always a good idea for a warning for):\r\n```\r\n.. warning::\r\n   The fpp is calculated only approximately, and it can be as much as 1.5 times the true value.\r\n```","created_at":"2015-04-25T22:16:13Z","updated_at":"2015-04-25T22:16:13Z","html_url":"https://github.com/astropy/astropy/pull/3724#discussion_r29104627","pull_request_url":"https://api.github.com/repos/astropy/astropy/pulls/3724","_links":{"self":{"href":"https://api.github.com/repos/astropy/astropy/pulls/comments/29104627"},"html":{"href":"https://github.com/astropy/astropy/pull/3724#discussion_r29104627"},"pull_request":{"href":"https://api.github.com/repos/astropy/astropy/pulls/3724"}}},"pull_request":{"url":"https://api.github.com/repos/astropy/astropy/pulls/3724","id":34095081,"html_url":"https://github.com/astropy/astropy/pull/3724","diff_url":"https://github.com/astropy/astropy/pull/3724.diff","patch_url":"https://github.com/astropy/astropy/pull/3724.patch","issue_url":"https://api.github.com/repos/astropy/astropy/issues/3724","number":3724,"state":"open","locked":false,"title":"Implemented Kuiper test and some support functions","user":{"login":"aarchiba","id":136867,"avatar_url":"https://avatars.githubusercontent.com/u/136867?v=3","gravatar_id":"","url":"https://api.github.com/users/aarchiba","html_url":"https://github.com/aarchiba","followers_url":"https://api.github.com/users/aarchiba/followers","following_url":"https://api.github.com/users/aarchiba/following{/other_user}","gists_url":"https://api.github.com/users/aarchiba/gists{/gist_id}","starred_url":"https://api.github.com/users/aarchiba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aarchiba/subscriptions","organizations_url":"https://api.github.com/users/aarchiba/orgs","repos_url":"https://api.github.com/users/aarchiba/repos","events_url":"https://api.github.com/users/aarchiba/events{/privacy}","received_events_url":"https://api.github.com/users/aarchiba/received_events","type":"User","site_admin":false},"body":"The Kuiper test resembles the K-S test but is invariant under cyclic permutations; it is therefore suitable for circular data. Non-uniform coverage can be accommodated by testing against a non-uniform distribution using included tools.","created_at":"2015-04-24T23:43:34Z","updated_at":"2015-04-25T22:16:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"52b8173be0299a028ec4405dae7214da5ada3f71","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/astropy/astropy/pulls/3724/commits","review_comments_url":"https://api.github.com/repos/astropy/astropy/pulls/3724/comments","review_comment_url":"https://api.github.com/repos/astropy/astropy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/astropy/astropy/issues/3724/comments","statuses_url":"https://api.github.com/repos/astropy/astropy/statuses/c7334c57a8f3fc8f056a3ef33816bb93fbe36eff","head":{"label":"aarchiba:kuiper","ref":"kuiper","sha":"c7334c57a8f3fc8f056a3ef33816bb93fbe36eff","user":{"login":"aarchiba","id":136867,"avatar_url":"https://avatars.githubusercontent.com/u/136867?v=3","gravatar_id":"","url":"https://api.github.com/users/aarchiba","html_url":"https://github.com/aarchiba","followers_url":"https://api.github.com/users/aarchiba/followers","following_url":"https://api.github.com/users/aarchiba/following{/other_user}","gists_url":"https://api.github.com/users/aarchiba/gists{/gist_id}","starred_url":"https://api.github.com/users/aarchiba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aarchiba/subscriptions","organizations_url":"https://api.github.com/users/aarchiba/orgs","repos_url":"https://api.github.com/users/aarchiba/repos","events_url":"https://api.github.com/users/aarchiba/events{/privacy}","received_events_url":"https://api.github.com/users/aarchiba/received_events","type":"User","site_admin":false},"repo":{"id":34362934,"name":"astropy","full_name":"aarchiba/astropy","owner":{"login":"aarchiba","id":136867,"avatar_url":"https://avatars.githubusercontent.com/u/136867?v=3","gravatar_id":"","url":"https://api.github.com/users/aarchiba","html_url":"https://github.com/aarchiba","followers_url":"https://api.github.com/users/aarchiba/followers","following_url":"https://api.github.com/users/aarchiba/following{/other_user}","gists_url":"https://api.github.com/users/aarchiba/gists{/gist_id}","starred_url":"https://api.github.com/users/aarchiba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aarchiba/subscriptions","organizations_url":"https://api.github.com/users/aarchiba/orgs","repos_url":"https://api.github.com/users/aarchiba/repos","events_url":"https://api.github.com/users/aarchiba/events{/privacy}","received_events_url":"https://api.github.com/users/aarchiba/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/aarchiba/astropy","description":"Repository for the Astropy core package","fork":true,"url":"https://api.github.com/repos/aarchiba/astropy","forks_url":"https://api.github.com/repos/aarchiba/astropy/forks","keys_url":"https://api.github.com/repos/aarchiba/astropy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aarchiba/astropy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aarchiba/astropy/teams","hooks_url":"https://api.github.com/repos/aarchiba/astropy/hooks","issue_events_url":"https://api.github.com/repos/aarchiba/astropy/issues/events{/number}","events_url":"https://api.github.com/repos/aarchiba/astropy/events","assignees_url":"https://api.github.com/repos/aarchiba/astropy/assignees{/user}","branches_url":"https://api.github.com/repos/aarchiba/astropy/branches{/branch}","tags_url":"https://api.github.com/repos/aarchiba/astropy/tags","blobs_url":"https://api.github.com/repos/aarchiba/astropy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aarchiba/astropy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aarchiba/astropy/git/refs{/sha}","trees_url":"https://api.github.com/repos/aarchiba/astropy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aarchiba/astropy/statuses/{sha}","languages_url":"https://api.github.com/repos/aarchiba/astropy/languages","stargazers_url":"https://api.github.com/repos/aarchiba/astropy/stargazers","contributors_url":"https://api.github.com/repos/aarchiba/astropy/contributors","subscribers_url":"https://api.github.com/repos/aarchiba/astropy/subscribers","subscription_url":"https://api.github.com/repos/aarchiba/astropy/subscription","commits_url":"https://api.github.com/repos/aarchiba/astropy/commits{/sha}","git_commits_url":"https://api.github.com/repos/aarchiba/astropy/git/commits{/sha}","comments_url":"https://api.github.com/repos/aarchiba/astropy/comments{/number}","issue_comment_url":"https://api.github.com/repos/aarchiba/astropy/issues/comments{/number}","contents_url":"https://api.github.com/repos/aarchiba/astropy/contents/{+path}","compare_url":"https://api.github.com/repos/aarchiba/astropy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aarchiba/astropy/merges","archive_url":"https://api.github.com/repos/aarchiba/astropy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aarchiba/astropy/downloads","issues_url":"https://api.github.com/repos/aarchiba/astropy/issues{/number}","pulls_url":"https://api.github.com/repos/aarchiba/astropy/pulls{/number}","milestones_url":"https://api.github.com/repos/aarchiba/astropy/milestones{/number}","notifications_url":"https://api.github.com/repos/aarchiba/astropy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aarchiba/astropy/labels{/name}","releases_url":"https://api.github.com/repos/aarchiba/astropy/releases{/id}","created_at":"2015-04-22T02:04:39Z","updated_at":"2015-04-22T02:04:44Z","pushed_at":"2015-04-25T17:21:05Z","git_url":"git://github.com/aarchiba/astropy.git","ssh_url":"git@github.com:aarchiba/astropy.git","clone_url":"https://github.com/aarchiba/astropy.git","svn_url":"https://github.com/aarchiba/astropy","homepage":"www.astropy.org","size":64599,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"astropy:master","ref":"master","sha":"7ce848ed1f04c6fd6eaf808e3713b78ae9476fa9","user":{"login":"astropy","id":847984,"avatar_url":"https://avatars.githubusercontent.com/u/847984?v=3","gravatar_id":"","url":"https://api.github.com/users/astropy","html_url":"https://github.com/astropy","followers_url":"https://api.github.com/users/astropy/followers","following_url":"https://api.github.com/users/astropy/following{/other_user}","gists_url":"https://api.github.com/users/astropy/gists{/gist_id}","starred_url":"https://api.github.com/users/astropy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astropy/subscriptions","organizations_url":"https://api.github.com/users/astropy/orgs","repos_url":"https://api.github.com/users/astropy/repos","events_url":"https://api.github.com/users/astropy/events{/privacy}","received_events_url":"https://api.github.com/users/astropy/received_events","type":"Organization","site_admin":false},"repo":{"id":2081289,"name":"astropy","full_name":"astropy/astropy","owner":{"login":"astropy","id":847984,"avatar_url":"https://avatars.githubusercontent.com/u/847984?v=3","gravatar_id":"","url":"https://api.github.com/users/astropy","html_url":"https://github.com/astropy","followers_url":"https://api.github.com/users/astropy/followers","following_url":"https://api.github.com/users/astropy/following{/other_user}","gists_url":"https://api.github.com/users/astropy/gists{/gist_id}","starred_url":"https://api.github.com/users/astropy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/astropy/subscriptions","organizations_url":"https://api.github.com/users/astropy/orgs","repos_url":"https://api.github.com/users/astropy/repos","events_url":"https://api.github.com/users/astropy/events{/privacy}","received_events_url":"https://api.github.com/users/astropy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/astropy/astropy","description":"Repository for the Astropy core package","fork":false,"url":"https://api.github.com/repos/astropy/astropy","forks_url":"https://api.github.com/repos/astropy/astropy/forks","keys_url":"https://api.github.com/repos/astropy/astropy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/astropy/astropy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/astropy/astropy/teams","hooks_url":"https://api.github.com/repos/astropy/astropy/hooks","issue_events_url":"https://api.github.com/repos/astropy/astropy/issues/events{/number}","events_url":"https://api.github.com/repos/astropy/astropy/events","assignees_url":"https://api.github.com/repos/astropy/astropy/assignees{/user}","branches_url":"https://api.github.com/repos/astropy/astropy/branches{/branch}","tags_url":"https://api.github.com/repos/astropy/astropy/tags","blobs_url":"https://api.github.com/repos/astropy/astropy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/astropy/astropy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/astropy/astropy/git/refs{/sha}","trees_url":"https://api.github.com/repos/astropy/astropy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/astropy/astropy/statuses/{sha}","languages_url":"https://api.github.com/repos/astropy/astropy/languages","stargazers_url":"https://api.github.com/repos/astropy/astropy/stargazers","contributors_url":"https://api.github.com/repos/astropy/astropy/contributors","subscribers_url":"https://api.github.com/repos/astropy/astropy/subscribers","subscription_url":"https://api.github.com/repos/astropy/astropy/subscription","commits_url":"https://api.github.com/repos/astropy/astropy/commits{/sha}","git_commits_url":"https://api.github.com/repos/astropy/astropy/git/commits{/sha}","comments_url":"https://api.github.com/repos/astropy/astropy/comments{/number}","issue_comment_url":"https://api.github.com/repos/astropy/astropy/issues/comments{/number}","contents_url":"https://api.github.com/repos/astropy/astropy/contents/{+path}","compare_url":"https://api.github.com/repos/astropy/astropy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/astropy/astropy/merges","archive_url":"https://api.github.com/repos/astropy/astropy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/astropy/astropy/downloads","issues_url":"https://api.github.com/repos/astropy/astropy/issues{/number}","pulls_url":"https://api.github.com/repos/astropy/astropy/pulls{/number}","milestones_url":"https://api.github.com/repos/astropy/astropy/milestones{/number}","notifications_url":"https://api.github.com/repos/astropy/astropy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/astropy/astropy/labels{/name}","releases_url":"https://api.github.com/repos/astropy/astropy/releases{/id}","created_at":"2011-07-21T01:33:49Z","updated_at":"2015-04-25T20:03:58Z","pushed_at":"2015-04-25T20:03:57Z","git_url":"git://github.com/astropy/astropy.git","ssh_url":"git@github.com:astropy/astropy.git","clone_url":"https://github.com/astropy/astropy.git","svn_url":"https://github.com/astropy/astropy","homepage":"www.astropy.org","size":64599,"stargazers_count":538,"watchers_count":538,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":378,"mirror_url":null,"open_issues_count":495,"forks":378,"open_issues":495,"watchers":538,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/astropy/astropy/pulls/3724"},"html":{"href":"https://github.com/astropy/astropy/pull/3724"},"issue":{"href":"https://api.github.com/repos/astropy/astropy/issues/3724"},"comments":{"href":"https://api.github.com/repos/astropy/astropy/issues/3724/comments"},"review_comments":{"href":"https://api.github.com/repos/astropy/astropy/pulls/3724/comments"},"review_comment":{"href":"https://api.github.com/repos/astropy/astropy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/astropy/astropy/pulls/3724/commits"},"statuses":{"href":"https://api.github.com/repos/astropy/astropy/statuses/c7334c57a8f3fc8f056a3ef33816bb93fbe36eff"}}}}