1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
# [Distribution](https://github.com/sciruby/distribution)
[](https://travis-ci.org/SciRuby/distribution)
[](https://codeclimate.com/github/SciRuby/distribution)
## Installation
```
$ gem install distribution
```
If you have GSL installed and want to speed things up, install `rb-gsl`:
```bash
$ gem install rb-gsl
```
## Description
Statistical Distributions library. Includes Normal univariate and bivariate, T, F, Chi Square, Binomial, Hypergeometric, Exponential, Poisson, Beta, LogNormal and Gamma.
Uses Ruby by default and C (statistics2/GSL) or Java extensions where available.
Includes code from statistics2 on Normal, T, F and Chi Square ruby code [http://blade.nagaokaut.ac.jp/~sinara/ruby/math/statistics2]
## Synopsis
* Returns Gaussian PDF for x
```
pdf=Distribution::Normal.pdf(x)
```
* Returns Gaussian CDF for x
```
cdf=Distribution::Normal.cdf(x)
```
* Returns inverse CDF (or p-value) for x
```
pv=Distribution::Normal.p_value(x)
```
## Developers
```
$ git clone https://github.com/SciRuby/distribution.git
```
If you want to provide a new distribution, run `lib/distribution`:
```
$ distribution --new your_distribution
```
This should create the main distribution file, the directory with Ruby and GSL engines and specs on the spec/ directory.
## API Structure
Distribution::<name>.(cdf|pdf|p_value|rng)
On discrete distributions, exact Ruby implementations of pdf, cdf and p_value could be provided, using
```
Distribution::<name>.exact_(cdf|pdf|p_value)
```
module Distribution::Shorthand provides (you guess?) shortands method to call all methods
```
<Distribution shortname>_(cdf|pdf|p|r)
```
On discrete distributions, exact cdf, pdf and p_value are
```
<Distribution shortname>_(ecdf|epdf|ep)
```
Shortnames for distributions:
* Normal: norm
* Bivariate Normal: bnor
* T: tdist
* F: fdist
* Chi Square: chisq
* Binomial: bino
* Hypergeometric: hypg
* Exponential: expo
* Poisson: pois
* Beta: beta
* Gamma: gamma
* LogNormal: lognormal
### API Structure Example
```
Distribution::T.cdf
```
could be called after including Distribution::Shorthand
```
tdist_cdf
```
## Features
* Very fast ruby 1.8.7/1.9.+ implementation, with improved method to calculate factorials and others common functions
* All methods tested on several ranges. See spec/
## Issues
* On JRuby and Rubinius, BivariateNormal returns incorrect pdf
For current issues see the [issue tracker pages](https://github.com/sciruby/distribution/issues).
|