{"action":"created","comment":{"url":"https://api.github.com/repos/biocore/scikit-bio/pulls/comments/25831948","id":25831948,"diff_hunk":"@@ -0,0 +1,419 @@\n+r\"\"\"\n+Composition Statistics (:mod:`skbio.stats.composition`)\n+=======================================================\n+\n+.. currentmodule:: skbio.stats.composition\n+\n+This module provides functions for compositional data analysis.\n+\n+Many 'omics datasets are inheriently compositional - meaning that they are best\n+interpreted as proportions or percentages rather than absolute counts.\n+\n+Formally, :math:`x` is a composition if :math:`\\sum_{i=0}^D x_{i} = c` and\n+:math:`x_{i} > 0`, :math:`1 \\leq i \\leq D`  and :math:`c` is a real valued\n+constant and there are :math:`D` components for each composition. In this\n+module :math:`c=1`. Compositional data can be analyzed using Aitchison\n+geometry [1]_\n+\n+However, in this framework, standard real Euclidean operations such as addition\n+and multiplication no longer apply.  Only operations such as perturbation and\n+power can be used to manipulate this data [1]_\n+\n+This module allows two styles of manipulation of compositional data.\n+Compositional data can be analyzed using perturbation and power operations,\n+which can be useful for simulation studies. The alternative strategy is to\n+transform compositional data into the real space.  Right now, the centre log\n+ratio transform (clr) [1]_ can be used to accomplish this.  This transform can\n+be useful for performing standard statistical tools such as parametric\n+hypothesis testing, regressions and more.\n+\n+The major caveat of using this framework is dealing with zeros.\n+In the Aitchison geometry, only compositions with nonzero components can be\n+considered. The multiplicative replacement technique [2]_ can be used to\n+substitute these zeros with small pseudocounts without introducing major\n+distortions to the data.\n+\n+Functions\n+---------\n+\n+.. autosummary::\n+   :toctree: generated/\n+\n+   multiplicative_replacement\n+   perturb\n+   perturb_inv\n+   power\n+   clr\n+   centralize\n+\n+Examples\n+--------\n+\n+>>> import numpy as np\n+\n+Consider a very simple environment with only 3 species.\n+The species in the environment are equally distributed and their\n+proportions are equilvalent:\n+\n+>>> otus = np.array([1./3, 1./3., 1./3])\n+\n+Suppose that an antibiotic kills off half of the population for the\n+first two species, but doesn't harm the third species.\n+Then the perturbation vector would be as follows\n+\n+>>> antibiotic = np.array([1./2, 1./2, 1])\n+\n+And the resulting perturbation would be\n+\n+>>> perturb(otus, antibiotic)\n+array([ 0.25,  0.25,  0.5 ])\n+\n+Reference\n+---------\n+.. [1] V. Pawlowsky-Glahn. \"Lecture Notes on Compositional Data Analysis\"\n+.. [2] J. A. Martin-Fernandez. \"Dealing With Zeros and Missing Values in\n+       Compositional Data Sets Using Nonparametric Imputation\"\n+\n+\"\"\"\n+from __future__ import absolute_import, division, print_function\n+\n+# ----------------------------------------------------------------------------\n+# Copyright (c) 2013--, scikit-bio development team.\n+#\n+# Distributed under the terms of the Modified BSD License.\n+#\n+# The full license is in the file COPYING.txt, distributed with this software.\n+# ----------------------------------------------------------------------------\n+\n+import numpy as np\n+\n+import scipy.stats as ss\n+\n+\n+def _closure(mat):\n+    \"\"\"\n+    Performs closure to ensure that all elements add up to 1\n+    mat : array-like\n+       a matrix of proportions where\n+       rows = compositions\n+       columns = components\n+\n+    Returns\n+    -------\n+    mat_ : numpy.ndarray, np.float64\n+       A matrix of proportions where all of the values\n+       are nonzero and each composition (row) adds up to 1\n+\n+    \"\"\"\n+    mat = np.asarray(mat)\n+    if not isinstance(mat.dtype, float):\n+        mat = mat.astype(np.float64)","path":"skbio/stats/composition.py","position":110,"original_position":110,"commit_id":"48f2f3d6e352a8485309708b4700735dcffba698","original_commit_id":"48f2f3d6e352a8485309708b4700735dcffba698","user":{"login":"Jorge-C","id":839897,"avatar_url":"https://avatars.githubusercontent.com/u/839897?v=3","gravatar_id":"","url":"https://api.github.com/users/Jorge-C","html_url":"https://github.com/Jorge-C","followers_url":"https://api.github.com/users/Jorge-C/followers","following_url":"https://api.github.com/users/Jorge-C/following{/other_user}","gists_url":"https://api.github.com/users/Jorge-C/gists{/gist_id}","starred_url":"https://api.github.com/users/Jorge-C/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jorge-C/subscriptions","organizations_url":"https://api.github.com/users/Jorge-C/orgs","repos_url":"https://api.github.com/users/Jorge-C/repos","events_url":"https://api.github.com/users/Jorge-C/events{/privacy}","received_events_url":"https://api.github.com/users/Jorge-C/received_events","type":"User","site_admin":false},"body":"These 3 lines can be condensed into `mat = np.asarray(mat, dtype=np.float64)`","created_at":"2015-03-05T01:18:49Z","updated_at":"2015-03-05T01:18:49Z","html_url":"https://github.com/biocore/scikit-bio/pull/860#discussion_r25831948","pull_request_url":"https://api.github.com/repos/biocore/scikit-bio/pulls/860","_links":{"self":{"href":"https://api.github.com/repos/biocore/scikit-bio/pulls/comments/25831948"},"html":{"href":"https://github.com/biocore/scikit-bio/pull/860#discussion_r25831948"},"pull_request":{"href":"https://api.github.com/repos/biocore/scikit-bio/pulls/860"}}},"pull_request":{"url":"https://api.github.com/repos/biocore/scikit-bio/pulls/860","id":29784050,"html_url":"https://github.com/biocore/scikit-bio/pull/860","diff_url":"https://github.com/biocore/scikit-bio/pull/860.diff","patch_url":"https://github.com/biocore/scikit-bio/pull/860.patch","issue_url":"https://api.github.com/repos/biocore/scikit-bio/issues/860","number":860,"state":"open","locked":false,"title":"Composition Analysis methods","user":{"login":"mortonjt","id":4184797,"avatar_url":"https://avatars.githubusercontent.com/u/4184797?v=3","gravatar_id":"","url":"https://api.github.com/users/mortonjt","html_url":"https://github.com/mortonjt","followers_url":"https://api.github.com/users/mortonjt/followers","following_url":"https://api.github.com/users/mortonjt/following{/other_user}","gists_url":"https://api.github.com/users/mortonjt/gists{/gist_id}","starred_url":"https://api.github.com/users/mortonjt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mortonjt/subscriptions","organizations_url":"https://api.github.com/users/mortonjt/orgs","repos_url":"https://api.github.com/users/mortonjt/repos","events_url":"https://api.github.com/users/mortonjt/events{/privacy}","received_events_url":"https://api.github.com/users/mortonjt/received_events","type":"User","site_admin":false},"body":"This is continuing the discussion from https://github.com/biocore/scikit-bio/issues/835\r\n\r\nThis methods are the barebones required to construct a compositional biplot\r\n\r\nThe math is a bit funky, so don't hesitate to ask questions - I know that it took me a while to understand it.\r\n\r\n@Jorge-C @ElDeveloper @antgonza are you still willing to look over this PR?","created_at":"2015-02-23T03:16:02Z","updated_at":"2015-03-05T01:18:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"42f4cc66940037e0a31919189307762624ba0563","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/biocore/scikit-bio/pulls/860/commits","review_comments_url":"https://api.github.com/repos/biocore/scikit-bio/pulls/860/comments","review_comment_url":"https://api.github.com/repos/biocore/scikit-bio/pulls/comments{/number}","comments_url":"https://api.github.com/repos/biocore/scikit-bio/issues/860/comments","statuses_url":"https://api.github.com/repos/biocore/scikit-bio/statuses/48f2f3d6e352a8485309708b4700735dcffba698","head":{"label":"mortonjt:master","ref":"master","sha":"48f2f3d6e352a8485309708b4700735dcffba698","user":{"login":"mortonjt","id":4184797,"avatar_url":"https://avatars.githubusercontent.com/u/4184797?v=3","gravatar_id":"","url":"https://api.github.com/users/mortonjt","html_url":"https://github.com/mortonjt","followers_url":"https://api.github.com/users/mortonjt/followers","following_url":"https://api.github.com/users/mortonjt/following{/other_user}","gists_url":"https://api.github.com/users/mortonjt/gists{/gist_id}","starred_url":"https://api.github.com/users/mortonjt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mortonjt/subscriptions","organizations_url":"https://api.github.com/users/mortonjt/orgs","repos_url":"https://api.github.com/users/mortonjt/repos","events_url":"https://api.github.com/users/mortonjt/events{/privacy}","received_events_url":"https://api.github.com/users/mortonjt/received_events","type":"User","site_admin":false},"repo":{"id":23898042,"name":"scikit-bio","full_name":"mortonjt/scikit-bio","owner":{"login":"mortonjt","id":4184797,"avatar_url":"https://avatars.githubusercontent.com/u/4184797?v=3","gravatar_id":"","url":"https://api.github.com/users/mortonjt","html_url":"https://github.com/mortonjt","followers_url":"https://api.github.com/users/mortonjt/followers","following_url":"https://api.github.com/users/mortonjt/following{/other_user}","gists_url":"https://api.github.com/users/mortonjt/gists{/gist_id}","starred_url":"https://api.github.com/users/mortonjt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mortonjt/subscriptions","organizations_url":"https://api.github.com/users/mortonjt/orgs","repos_url":"https://api.github.com/users/mortonjt/repos","events_url":"https://api.github.com/users/mortonjt/events{/privacy}","received_events_url":"https://api.github.com/users/mortonjt/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mortonjt/scikit-bio","description":"Core objects, functions and statistics for working with biological data in Python.","fork":true,"url":"https://api.github.com/repos/mortonjt/scikit-bio","forks_url":"https://api.github.com/repos/mortonjt/scikit-bio/forks","keys_url":"https://api.github.com/repos/mortonjt/scikit-bio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mortonjt/scikit-bio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mortonjt/scikit-bio/teams","hooks_url":"https://api.github.com/repos/mortonjt/scikit-bio/hooks","issue_events_url":"https://api.github.com/repos/mortonjt/scikit-bio/issues/events{/number}","events_url":"https://api.github.com/repos/mortonjt/scikit-bio/events","assignees_url":"https://api.github.com/repos/mortonjt/scikit-bio/assignees{/user}","branches_url":"https://api.github.com/repos/mortonjt/scikit-bio/branches{/branch}","tags_url":"https://api.github.com/repos/mortonjt/scikit-bio/tags","blobs_url":"https://api.github.com/repos/mortonjt/scikit-bio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mortonjt/scikit-bio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mortonjt/scikit-bio/git/refs{/sha}","trees_url":"https://api.github.com/repos/mortonjt/scikit-bio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mortonjt/scikit-bio/statuses/{sha}","languages_url":"https://api.github.com/repos/mortonjt/scikit-bio/languages","stargazers_url":"https://api.github.com/repos/mortonjt/scikit-bio/stargazers","contributors_url":"https://api.github.com/repos/mortonjt/scikit-bio/contributors","subscribers_url":"https://api.github.com/repos/mortonjt/scikit-bio/subscribers","subscription_url":"https://api.github.com/repos/mortonjt/scikit-bio/subscription","commits_url":"https://api.github.com/repos/mortonjt/scikit-bio/commits{/sha}","git_commits_url":"https://api.github.com/repos/mortonjt/scikit-bio/git/commits{/sha}","comments_url":"https://api.github.com/repos/mortonjt/scikit-bio/comments{/number}","issue_comment_url":"https://api.github.com/repos/mortonjt/scikit-bio/issues/comments{/number}","contents_url":"https://api.github.com/repos/mortonjt/scikit-bio/contents/{+path}","compare_url":"https://api.github.com/repos/mortonjt/scikit-bio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mortonjt/scikit-bio/merges","archive_url":"https://api.github.com/repos/mortonjt/scikit-bio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mortonjt/scikit-bio/downloads","issues_url":"https://api.github.com/repos/mortonjt/scikit-bio/issues{/number}","pulls_url":"https://api.github.com/repos/mortonjt/scikit-bio/pulls{/number}","milestones_url":"https://api.github.com/repos/mortonjt/scikit-bio/milestones{/number}","notifications_url":"https://api.github.com/repos/mortonjt/scikit-bio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mortonjt/scikit-bio/labels{/name}","releases_url":"https://api.github.com/repos/mortonjt/scikit-bio/releases{/id}","created_at":"2014-09-11T00:39:57Z","updated_at":"2015-03-05T00:41:40Z","pushed_at":"2015-03-05T00:41:40Z","git_url":"git://github.com/mortonjt/scikit-bio.git","ssh_url":"git@github.com:mortonjt/scikit-bio.git","clone_url":"https://github.com/mortonjt/scikit-bio.git","svn_url":"https://github.com/mortonjt/scikit-bio","homepage":"http://scikit-bio.org","size":30076,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"biocore:master","ref":"master","sha":"bf0d8c6b6fd61ebc168b2af91bc021c90d595f18","user":{"login":"biocore","id":6241857,"avatar_url":"https://avatars.githubusercontent.com/u/6241857?v=3","gravatar_id":"","url":"https://api.github.com/users/biocore","html_url":"https://github.com/biocore","followers_url":"https://api.github.com/users/biocore/followers","following_url":"https://api.github.com/users/biocore/following{/other_user}","gists_url":"https://api.github.com/users/biocore/gists{/gist_id}","starred_url":"https://api.github.com/users/biocore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biocore/subscriptions","organizations_url":"https://api.github.com/users/biocore/orgs","repos_url":"https://api.github.com/users/biocore/repos","events_url":"https://api.github.com/users/biocore/events{/privacy}","received_events_url":"https://api.github.com/users/biocore/received_events","type":"Organization","site_admin":false},"repo":{"id":15168264,"name":"scikit-bio","full_name":"biocore/scikit-bio","owner":{"login":"biocore","id":6241857,"avatar_url":"https://avatars.githubusercontent.com/u/6241857?v=3","gravatar_id":"","url":"https://api.github.com/users/biocore","html_url":"https://github.com/biocore","followers_url":"https://api.github.com/users/biocore/followers","following_url":"https://api.github.com/users/biocore/following{/other_user}","gists_url":"https://api.github.com/users/biocore/gists{/gist_id}","starred_url":"https://api.github.com/users/biocore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biocore/subscriptions","organizations_url":"https://api.github.com/users/biocore/orgs","repos_url":"https://api.github.com/users/biocore/repos","events_url":"https://api.github.com/users/biocore/events{/privacy}","received_events_url":"https://api.github.com/users/biocore/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/biocore/scikit-bio","description":"Core objects, functions and statistics for working with biological data in Python.","fork":false,"url":"https://api.github.com/repos/biocore/scikit-bio","forks_url":"https://api.github.com/repos/biocore/scikit-bio/forks","keys_url":"https://api.github.com/repos/biocore/scikit-bio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/biocore/scikit-bio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/biocore/scikit-bio/teams","hooks_url":"https://api.github.com/repos/biocore/scikit-bio/hooks","issue_events_url":"https://api.github.com/repos/biocore/scikit-bio/issues/events{/number}","events_url":"https://api.github.com/repos/biocore/scikit-bio/events","assignees_url":"https://api.github.com/repos/biocore/scikit-bio/assignees{/user}","branches_url":"https://api.github.com/repos/biocore/scikit-bio/branches{/branch}","tags_url":"https://api.github.com/repos/biocore/scikit-bio/tags","blobs_url":"https://api.github.com/repos/biocore/scikit-bio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/biocore/scikit-bio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/biocore/scikit-bio/git/refs{/sha}","trees_url":"https://api.github.com/repos/biocore/scikit-bio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/biocore/scikit-bio/statuses/{sha}","languages_url":"https://api.github.com/repos/biocore/scikit-bio/languages","stargazers_url":"https://api.github.com/repos/biocore/scikit-bio/stargazers","contributors_url":"https://api.github.com/repos/biocore/scikit-bio/contributors","subscribers_url":"https://api.github.com/repos/biocore/scikit-bio/subscribers","subscription_url":"https://api.github.com/repos/biocore/scikit-bio/subscription","commits_url":"https://api.github.com/repos/biocore/scikit-bio/commits{/sha}","git_commits_url":"https://api.github.com/repos/biocore/scikit-bio/git/commits{/sha}","comments_url":"https://api.github.com/repos/biocore/scikit-bio/comments{/number}","issue_comment_url":"https://api.github.com/repos/biocore/scikit-bio/issues/comments{/number}","contents_url":"https://api.github.com/repos/biocore/scikit-bio/contents/{+path}","compare_url":"https://api.github.com/repos/biocore/scikit-bio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/biocore/scikit-bio/merges","archive_url":"https://api.github.com/repos/biocore/scikit-bio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/biocore/scikit-bio/downloads","issues_url":"https://api.github.com/repos/biocore/scikit-bio/issues{/number}","pulls_url":"https://api.github.com/repos/biocore/scikit-bio/pulls{/number}","milestones_url":"https://api.github.com/repos/biocore/scikit-bio/milestones{/number}","notifications_url":"https://api.github.com/repos/biocore/scikit-bio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/biocore/scikit-bio/labels{/name}","releases_url":"https://api.github.com/repos/biocore/scikit-bio/releases{/id}","created_at":"2013-12-13T16:24:41Z","updated_at":"2015-03-03T05:11:54Z","pushed_at":"2015-02-24T23:53:58Z","git_url":"git://github.com/biocore/scikit-bio.git","ssh_url":"git@github.com:biocore/scikit-bio.git","clone_url":"https://github.com/biocore/scikit-bio.git","svn_url":"https://github.com/biocore/scikit-bio","homepage":"http://scikit-bio.org","size":36335,"stargazers_count":104,"watchers_count":104,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":57,"mirror_url":null,"open_issues_count":119,"forks":57,"open_issues":119,"watchers":104,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/biocore/scikit-bio/pulls/860"},"html":{"href":"https://github.com/biocore/scikit-bio/pull/860"},"issue":{"href":"https://api.github.com/repos/biocore/scikit-bio/issues/860"},"comments":{"href":"https://api.github.com/repos/biocore/scikit-bio/issues/860/comments"},"review_comments":{"href":"https://api.github.com/repos/biocore/scikit-bio/pulls/860/comments"},"review_comment":{"href":"https://api.github.com/repos/biocore/scikit-bio/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/biocore/scikit-bio/pulls/860/commits"},"statuses":{"href":"https://api.github.com/repos/biocore/scikit-bio/statuses/48f2f3d6e352a8485309708b4700735dcffba698"}}}}