Skip to main content

A Python 3 package of statistical analysis and distributions

Project description

PyStats

PyStats is a Python 3 library of statistical analysis and distribution functions with simple R-like syntax, scalar/list input/output with OpenMP parallelization.

Contents

Distributions

Functions to compute the cdf, pdf, quantile, as well as random sampling methods, are available for the following distributions:

  • Bernoulli
  • Beta
  • Binomial
  • Cauchy
  • Chi-squared
  • Exponential
  • F
  • Gamma
  • Inverse-Gamma
  • Laplace
  • Logistic
  • Log-Normal
  • Normal (Gaussian)
  • Poisson
  • Student's t
  • Uniform
  • Weibull

Installation

You can use pip to install this library:

pip3 install pystats

Alternatively, you can also clone this repository and install the plugin manually using pip:

$ git clone git@github.com:marcizhu/PyStats.git
$ pip3 install ./PyStats

After that, you can just import pystats (or do from pystats import * if you don't want to type pystats. before all functions) and you're ready to go.

Documentation

Full documentation is available online:

Documentation Status

A PDF version of the documentation is available here.

Syntax and Examples

Functions are called using an R-like syntax. Some general rules:

  • Density functions: pystats.d*. For example, the Normal (Gaussian) density is called using
pystats.dnorm(<value>, <mean>, <standard deviation>)
  • Cumulative distribution functions: pystats.p*. For example, the Gamma CDF is called using
pystats.pgamma(<value>, <shape parameter>, <scale parameter>)
  • Quantile functions: pystats.q*. For example, the Beta quantile is called using
pystats.qbeta(<value>, <a parameter>, <b parameter>)
  • Random sampling: pystats.r*. For example, to generate a single draw from the Logistic distribution:
pystats.rlogis(<location parameter>, <scale parameter>)

The library also supports lists as input/output:

  • The pdf, cdf and quantile functions can take list arguments. For example:
norm_pdf_vals = pystats.dnorm([x / 10 for x in range(-10, 10, 1)], 1.0, 2.0)
  • The randomization functions (r*) can output lists of arbitrary size. For example, the following code will generate a 100-item list of iid draws from a Gamma(3,2) distribution:
gamma_rvs = pystats.rgamma(100, 3.0, 2.0)

Additionally, most parameters have defaults to most common values and named parameters are also supported. For example, to generate a single draw from a Normal(0, 2) the following can be used:

norm_draw = pystats.rnorm(sd=2.0)

Examples

More examples with code:

# Evaluate the normal PDF at x = 1, mu = 0, sigma = 1
dval_1 = pystats.dnorm(1.0, 0.0, 1.0)

# Evaluate the normal PDF at x = 1, mu = 0, sigma = 1, and return the log value
dval_2 = pystats.dnorm(1.0, 0.0, 1.0, True)

# Same as above, but using default values and named parameters
dval_3 = pystats.dnorm(1.0, log=True)

# Evaluate the normal CDF at x = 1, mu = 0, sigma = 1
pval = pystats.pnorm(1.0, 0.0, 1.0)

# Evaluate the Laplacian quantile at q = 0.1, mu = 0, sigma = 1
qval = pystats.qlaplace(0.1, 0.0, 1.0)

# Draw from a t-distribution with dof = 30
rval = pystats.rt(dof=30)

# List output
beta_rvs = pystats.rbeta(100, 3.0, 2.0)

# List input
beta_cdf_vals = pystats.pbeta(beta_rvs, 3.0, 2.0)

For more information on default values, parameter names and other examples, check the documentation.

Credits

This library uses kthohr/stats for the statistical distribution functions, kthohr/gcem (a dependency of the previous library) and pybind/pybind11 to generate the binding code.

License

Copyright (c) Marc Izquierdo 2021
This library is licensed under the MIT License. See LICENSE for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyStats-0.1.tar.gz (5.4 kB view hashes)

Uploaded Source

Built Distributions

PyStats-0.1-pp37-pypy37_pp73-win32.whl (105.9 kB view hashes)

Uploaded PyPy Windows x86

PyStats-0.1-pp37-pypy37_pp73-manylinux2010_x86_64.whl (193.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ x86-64

PyStats-0.1-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (170.9 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

PyStats-0.1-pp36-pypy36_pp73-win32.whl (105.8 kB view hashes)

Uploaded PyPy Windows x86

PyStats-0.1-pp36-pypy36_pp73-manylinux2010_x86_64.whl (193.4 kB view hashes)

Uploaded PyPy manylinux: glibc 2.12+ x86-64

PyStats-0.1-pp36-pypy36_pp73-macosx_10_9_x86_64.whl (170.9 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

PyStats-0.1-cp39-cp39-win_amd64.whl (125.1 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

PyStats-0.1-cp39-cp39-win32.whl (105.8 kB view hashes)

Uploaded CPython 3.9 Windows x86

PyStats-0.1-cp39-cp39-manylinux2010_x86_64.whl (192.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64

PyStats-0.1-cp39-cp39-manylinux2010_i686.whl (194.3 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686

PyStats-0.1-cp39-cp39-macosx_10_9_x86_64.whl (171.3 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

PyStats-0.1-cp38-cp38-win_amd64.whl (135.3 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

PyStats-0.1-cp38-cp38-win32.whl (105.7 kB view hashes)

Uploaded CPython 3.8 Windows x86

PyStats-0.1-cp38-cp38-manylinux2010_x86_64.whl (192.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

PyStats-0.1-cp38-cp38-manylinux2010_i686.whl (194.6 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ i686

PyStats-0.1-cp38-cp38-macosx_10_9_x86_64.whl (171.2 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

PyStats-0.1-cp37-cp37m-win_amd64.whl (133.5 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

PyStats-0.1-cp37-cp37m-win32.whl (106.5 kB view hashes)

Uploaded CPython 3.7m Windows x86

PyStats-0.1-cp37-cp37m-manylinux2010_x86_64.whl (202.0 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

PyStats-0.1-cp37-cp37m-manylinux2010_i686.whl (204.8 kB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.12+ i686

PyStats-0.1-cp37-cp37m-macosx_10_9_x86_64.whl (164.3 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

PyStats-0.1-cp36-cp36m-win_amd64.whl (133.5 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

PyStats-0.1-cp36-cp36m-win32.whl (106.5 kB view hashes)

Uploaded CPython 3.6m Windows x86

PyStats-0.1-cp36-cp36m-manylinux2010_x86_64.whl (202.0 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

PyStats-0.1-cp36-cp36m-manylinux2010_i686.whl (204.8 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ i686

PyStats-0.1-cp36-cp36m-macosx_10_9_x86_64.whl (164.3 kB view hashes)

Uploaded CPython 3.6m macOS 10.9+ x86-64

PyStats-0.1-cp35-cp35m-win_amd64.whl (133.5 kB view hashes)

Uploaded CPython 3.5m Windows x86-64

PyStats-0.1-cp35-cp35m-win32.whl (106.5 kB view hashes)

Uploaded CPython 3.5m Windows x86

PyStats-0.1-cp35-cp35m-manylinux2010_x86_64.whl (202.0 kB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.12+ x86-64

PyStats-0.1-cp35-cp35m-manylinux2010_i686.whl (204.8 kB view hashes)

Uploaded CPython 3.5m manylinux: glibc 2.12+ i686

PyStats-0.1-cp35-cp35m-macosx_10_9_x86_64.whl (164.3 kB view hashes)

Uploaded CPython 3.5m macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page