{ "info": { "author": "Dreas Nielsen", "author_email": "dnielsen@integral-corp.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: End Users/Desktop", "License :: OSI Approved :: GNU General Public License (GPL)", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Office/Business" ], "description": "met.py\nMultinomial Exact Tests\n\nmet.py is a Python module that allows you to define a pair of\nmultinomial distributions (conceptually 'control' and 'test'\ndistributions) and then compute one- and two-sided p values to test\nwhether the 'test' distribution is equivalent to the 'control'\ndistribution. The likelihood of all possible 'control' distributions can\nbe evaluated and the distribution of p values can be expressed in terms\nof the likelihood of the observed 'control' distribution.\n\n\nInstallation\n======================\n\nYou can install the module from [PyPi](https://pypi.org/) with the\ncommand\n\n pip install met\n\nor you can install in manually by downloading `met.py` and copying\nthe module to wherever you want to use it. If you place it in a\nlocation other than the standard library for your Python distribution,\nyou must add that location to your Python path prior to importing the\nmodule.\n\n\nPurpose\n======================\n\nPerform exact tests of a (site or test) distribution of multinomial\ncount data against a distribution of equivalent ordered multinomial\ncount data from another (reference or control) data set. Both two-sided\nand one-sided tests can be performed. One-sided tests require that\ncategories be ordered.\n\nA practical example of relevant data (and the motivation for writing\nthis module) arises from the use of Sediment Profile Imaging to evaluate\nthe benthic macroinvertebrate community at site and reference locations,\nand characterization of each sample in terms of the benthic successional\nstage presen. These categorical data are ordered, and so a one-sided\nexact multinomial test can be applied.\n\n\nNotes\n======================\n\nExact Tests\n--------------------\n\nWhereas most statistical tests compute p values based on the parameters\nof a continuous distribution, and those p value are therefore\nestimates, calculation of exact p values is possible when every\npossible rearrangement of the data can be enumerated. Each \nrearrangement of the data must have a specific probability of\noccurrence, which is computed based on a theoretical or reference\ndistribution of probabilities. Summing of the probabilities of\noccurrence for the observed data and for all more extreme arrangments of\nthe data produces an exact p value--hence, the result of an exact test.\n\nFor two-sided tests, \"more extreme\" means that the probability of an alternative\narrangement of site data has a lower probability than the observed arrangement.\n\nFor one-sided tests, \"more extreme\" means a data arrangement in which\none or more observations is shifted from a 'better' category to a\n'worse' one. Therefore, to carry out one-sided exact tests, the\ncategories must be ordered from 'better' to 'worse'.\n\nIssues\n--------------------\n\nWhen reference area sample sizes are small relative to site sample\nsizes, the accuracy of the probabilities calculated from the reference\narea samples may be questionable. In particular, some categories that\nare represented in the site data may not be represented in the reference\ndata, and so have zero reference aera probabilities. Whenever a\nreference area probability for any category is zero, the probability of\nany arrangement of site data with a non-zero count in that category is\nalso zero. Small reference area sample sizes may therefore lead to\nunderestimation of true reference probabilities for some categories, and\nconsequently to an underestimation of p values in the exact tests.\n\nThe met module contains two features to help evaluate and account for\nuncertainties related to relatively small reference area sample sizes. \nThe first of these allows assignment of small non-zero probabilities to\ncategories with no reference area observations, and the second allows\nevaluation of the likelihood of different p values based on possible\nreference area probabilities that could have led to the observed\nreference data.\n\nExample\n======================\n\nThis example illustrates the computation of one-sided and two-sided *p* values, with\nand without zeroes in the reference distribution.\nimport met\n\n # Counts observed in the reference area, ordered from 'best' to 'worst'\n # category. For SPI data, the categories are Stage 3, Stage 2 on 3,\n #\t\t\tStage 1 on 3, Stage 2, and Stage 1.\n\n ref = [9, 6, 6, 0, 5]\n\n # Counts observed in the site.\n # These are skewed toward an impacted distribution.\n # Counts are low for speed of illustration.\n site = [10, 12, 14, 5, 6]\n\n\n # MET with zeroes in the reference distribution.\n\n t1 = met.Multinom(ref, site)\n\n t1_p1 = t1.onesided_exact_test(save_cases=True)\n print(\"Example 1 with no zero-fill; one-sided p = %s\" % t1_p1)\n print(\" Number of extreme cases = %s\" % t1.n_extreme_cases)\n\nThe results are shown as:\n\n Example 1 with no zero-fill; one-sided p = 0.00634738889819\n Number of extreme cases = 63348\n\nAlthough there are zero probabilities in the reference area distribution, a non-zero\none-sided probability is calculated because some of the more extreme distributions\n(i.e., skewed further from the reference distribution than the actual size) have zeroes\nin the same category.\n\nCalculation of a two-sided p value:\n\n t1_p2 = t1.twosided_exact_test(save_cases=True)\n print(\"Example 1 with no zero-fill; two-sided p = %s\" % t1_p2)\n print(\" Number of cases = %s\" % len(t1.cases))\n print(\" Number of extreme_cases = %s\" % t1.n_extreme_cases)\n\nThe result is:\n\n Example 1 with no zero-fill; two-sided p = 0.0\n Number of cases = 249900\n Number of extreme_cases = 0\n\nThe zero probabilities in the reference distribution prevent the calculation of a two-sided\n*p* value. The multinomial probability for the site itself is zero, and the two-sided test sums\nthat with the multinomial probabilities of all of the (249,900) other possible results for the\nsite that are less probable than the observed site data.\n\nSpecifying a 'zero-fill' value results in a different p value for both the one-sided and\ntwo-sided tests.\n\n # MET with zeros replaced with 1 and non-zeroes inflated by 10.\n\n t2 = met.Multinom(met.fillzeroes(ref, 10), site)\n\n t2_p1 = t2.onesided_exact_test()\n t2_p2 = t2.twosided_exact_test()\n\n print(\"Example 2 with a zero-fill factor of 10; one-sided p = %s, two-sided p = %s\" % (t2_p1, t2_p2))\n\nThe result is:\n\n Example 2 with a zero-fill factor of 10; one-sided p = 0.0070346, two-sided p = 1.95908e-06\n\n A larger fill factor results in different calculated probabilities.\n # MET with zeros replaced with 1 and non-zeroes inflated by 100.\n\n t3 = met.Multinom(met.fillzeroes(ref, 100), site)\n\n t3_p1 = t3.onesided_exact_test()\n t3_p2 = t3.twosided_exact_test()\n\n print(\"Example 3 with a zero-fill factor of 100; one-sided p = %s, two-sided p = %s\" % (t3_p1, t3_p2))\n\nThe result is:\n\n Example 3 with a zero-fill factor of 100; one-sided p = 0.0064139, two-sided p = 1.73424e-11\n\n\n\nCopyright and License\n======================\n\nCopyright (c) 2009, 2019 R.Dreas Nielsen\n\nThis program is free software: you can redistribute it and/or modify it under\nthe terms of the GNU General Public License as published by the Free Software\nFoundation, either version 3 of the License, or (at your option) any later\nversion. This program is distributed in the hope that it will be useful, but\nWITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\nFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\ndetails. The GNU General Public License is available at\nhttp://www.gnu.org/licenses/.", "description_content_type": "", "docs_url": "https://pythonhosted.org/met/", "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://pypi/project/met/", "keywords": "Statistics,Multnomial exact test,Multinomial", "license": "GPL", "maintainer": "", "maintainer_email": "", "name": "met", "package_url": "https://pypi.org/project/met/", "platform": "", "project_url": "https://pypi.org/project/met/", "project_urls": { "Homepage": "https://pypi/project/met/" }, "release_url": "https://pypi.org/project/met/1.0.0/", "requires_dist": null, "requires_python": "", "summary": "Multinomial Exact Tests", "version": "1.0.0" }, "last_serial": 5902754, "releases": { "0.1.5.0": [ { "comment_text": "", "digests": { "md5": "d66e56e48ec0ed95f8f41afe457f93d9", "sha256": "b177b92236727a7a0be889bb441b268ccab8371fe77af0b2b597a616a3b0ae7f" }, "downloads": -1, "filename": "met-0.1.5.0.zip", "has_sig": false, "md5_digest": "d66e56e48ec0ed95f8f41afe457f93d9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13797, "upload_time": "2009-01-31T03:55:37", "url": "https://files.pythonhosted.org/packages/67/95/aa7dcc8aadf4d2e3c9f2e9cd009b8498d344233f3ed044e1b064a473bb5d/met-0.1.5.0.zip" } ], "0.9.0": [ { "comment_text": "", "digests": { "md5": "e014b3d7f6c74668e6b7b78a51ab1025", "sha256": "ab1c2812d6460ee4c0cfa0b2fc95ebf361c9da86c47112e8863922c3e64cd058" }, "downloads": -1, "filename": "met-0.9.0.tar.gz", "has_sig": false, "md5_digest": "e014b3d7f6c74668e6b7b78a51ab1025", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9259, "upload_time": "2019-09-27T15:07:46", "url": "https://files.pythonhosted.org/packages/0d/57/b735ecfc1c069e18cf219b05d255cab8b8b3a07987a9d0938c7cf6fe47ef/met-0.9.0.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "d5f62f045810635664671246746b477f", "sha256": "2cae35ebc6c0c1f6b455692efd5b8d23070c45a3362508bcb137a0a2f8702481" }, "downloads": -1, "filename": "met-1.0.0.tar.gz", "has_sig": false, "md5_digest": "d5f62f045810635664671246746b477f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9281, "upload_time": "2019-09-29T14:31:25", "url": "https://files.pythonhosted.org/packages/79/fb/61e28ac9445f9c254397e0132cf42eec1d06f04341c9d931e98d06268f71/met-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d5f62f045810635664671246746b477f", "sha256": "2cae35ebc6c0c1f6b455692efd5b8d23070c45a3362508bcb137a0a2f8702481" }, "downloads": -1, "filename": "met-1.0.0.tar.gz", "has_sig": false, "md5_digest": "d5f62f045810635664671246746b477f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9281, "upload_time": "2019-09-29T14:31:25", "url": "https://files.pythonhosted.org/packages/79/fb/61e28ac9445f9c254397e0132cf42eec1d06f04341c9d931e98d06268f71/met-1.0.0.tar.gz" } ] }