• Stars
    star
    141
  • Rank 259,971 (Top 6 %)
  • Language
    Ruby
  • License
    Other
  • Created almost 14 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Statistical Distributions multi library wrapper. Uses Ruby by default and C (statistics2/GSL) or Java extensions where available.

Distribution

Build Status Code Climate

Distribution is a gem with several probabilistic distributions. Pure Ruby is used by default, C (GSL) or Java extensions are used if available. Some facts:

  • Very fast ruby 1.9.3+ implementation, with improved method to calculate factorials and other common functions.
  • All methods tested on several ranges. See spec/.
  • Code for normal, Student's t and chi square is lifted from the statistics2 gem. Originally at this site.
  • The code for some functions and RNGs was lifted from Julia's Rmath-julia, a patched version of R's standalone math library.

The following table lists the available distributions and the methods available for each one. If a field is marked with an x, that distribution doesn't have that method implemented.

Distribution PDF CDF Quantile RNG Mean Mode Variance Skewness Kurtosis Entropy
Uniform x x x x x x x x x x
Normal x x x x x x x x x x
Lognormal x x x x x x x x
Bivariate Normal x x x x x x x x
Exponential x x x x x x x x
Logistic x x x x x x x x
t-Student x x x x x x x x
Chi Square x x x x x x x x
Fisher-Snedecor x x x x x x x x
Beta x x x x x x x x
Gamma x x x x x x x x
Weibull x x x x x x x x
Binomial x x x x x x x x
Poisson x x x x x x x x
Hypergeometric x x x x x x x x

Installation

$ gem install distribution

You can install GSL for better performance:

  • For Mac OS X: brew install gsl
  • For Ubuntu / Debian: sudo apt-get install gsl

After successfully installing the library:

$ gem install rb-gsl

Examples

You can find automatically generated documentation on RubyDoc.

# 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)

# API.

# You would normally use the following
p = Distribution::T.cdf(x)

# to get the cumulative probability of `x`. However, you can also:

include Distribution::Shorthand
tdist_cdf(x)

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
  • Uniform: unif

Roadmap

This gem wasn't updated for a long time before I started working on it, so there are a lot of work to do. The first priority is cleaning the interface and removing cruft whenever possible. After that, I want to implement more distributions and make sure that each one has a RNG.

Short-term

  • Define a minimal interface for continuous and discrete distributions (e.g. mean, variance, mode, skewness, kurtosis, pdf, cdf, quantile, cquantile).
  • Implement Distribution::Uniform with the default Ruby Random.
  • Clean up the implementation of normal distribution. Implement the necessary functions.
  • The same for Student's t, chi square, Fisher-Snedecor, beta, gamma, lognormal, logistic.
  • The same for discrete distributions: binomial, hypergeometric, bernoulli (still missing), etc.

Medium-term

  • Implement DSFMT for the uniform random generator.
  • Cauchy distribution.

Long-term

  • Implementing everything in the distributions x functions table above.

Issues

  • On JRuby and Rubinius, BivariateNormal returns incorrect pdf

For current issues see the issue tracker pages.

OMG! I want to help!

Everyone is welcome to help! Please, test these distributions with your own use cases and give a shout on the issue tracker if you find a problem or something is strange or hard to use. Documentation pull requests are totally welcome. More generally, any ideas or suggestions are welcome -- even by private e-mail.

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.

More Repositories

1

statsample

A suite for basic and advanced statistics on Ruby.
Ruby
401
star
2

rubyvis

Ruby version of Protovis, a visualization toolkit.
Ruby
236
star
3

rinruby

Ruby library that integrates the R interpreter in Ruby, making R's statistical routines and graphics available within Ruby.
Ruby
152
star
4

Rserve-Ruby-client

Pure Ruby client for Rserve. Based on 'new' Java client provided with server, but with modifications to adhere to POLS
Ruby
126
star
5

PHP_Beautifier

This program reformat and beautify PHP 4 and PHP 5 source code files automatically. The program is Open Source and distributed under the terms of PHP Licence. It is written in PHP 5 and has a command line tool.
PHP
106
star
6

extendmatrix

Cosmin Bonchis's enhancements to the Ruby "Vector" and "Matrix" module and includes: LU and QR (Householder, Givens, Gram Schmidt, Hessenberg) decompositions, bidiagonalization, eigenvalue and eigenvector calculations. Work on Ruby 1.8.7, 1.9.1 and 1.9.2 (SVN version)
Ruby
33
star
7

buhos

Web based systematic literature review software
Ruby
27
star
8

dominanceAnalysis

Dominance Analysis (Azen and Bodescu), for multiple regression models: OLS (univariate, multivariate), beta regression, Dynamic Linear Models, GLM and HLM
R
21
star
9

minimization

Minimization algorithms on pure Ruby
Ruby
19
star
10

integration

Integration methods, based on original work by Beng
Ruby
15
star
11

svg-graph

SVG:::Graph is a pure Ruby library for generating charts, which are a type of graph where the values of one axis are not scalar. SVG::Graph has a verry similar API to the Perl library SVG::TT::Graph, and the resulting charts also look the same. This isn't surprising, because SVG::Graph started as a loose port of SVG::TT::Graph, although the internal code no longer resembles the Perl original at all.
Ruby
13
star
12

reportbuilder

Ruby report abstract interface. Creates text, html and rtf output, based on a common framework.
JavaScript
11
star
13

analisis_covid19_chile

Ejemplo de analisis de serie de tiempo sobre casos Covid-19. Se presenta un reporte comparativo de Chile con otros países, así como por regiones.
HTML
6
star
14

web-plotter3d

A web based 3d plotter, using canvas and JS
JavaScript
6
star
15

statsample-optimization

Extension for statsample, that speed some methods.
C
5
star
16

gsl_narray_stdlib_comparison

Compare perfomance of GSL, Narray and stdlib Matrix on matrix and vectors operations
Ruby
4
star
17

statsample-sem

Structural Equation Modeling on Ruby, using statsample and R
Ruby
4
star
18

exner

Create structural summary for Rorschach Comprehensive System. Works with Znudic method for Zulliger test, based on Exner's RCS.
Ruby
3
star
19

analisis_constitucion

Análisis de contenido de las diferencias entre la versión de 1980 y la versión de 2005 de la Constitución Chilena
Ruby
3
star
20

coolcat-r

Clustering algorithm Coolcat(Barbará, Couto, Li) implemented on R
R
3
star
21

buhos-windows-tk

Windows toolkit to build Buhos installer
HTML
2
star
22

dirty-memoize

Like Memoize, but designed for mutable and parametizable objects
Ruby
2
star
23

rcebn

Just some random methods I use on R. Mainly mplus interfaces and some utilities
R
1
star
24

statsample-bivariate-extension

Polychoric and Tetrachoric support for statsample
Ruby
1
star