Home

Awesome

Statistex Hex Version docs CI Coverage Status

Statistex helps you do common statistics calculations and to explore a data set. It focusses on two things:

Installation

def deps do
  [
    {:statistex, "~> 1.0"}
  ]
end

Supported elixir versions are 1.6+ (together with their respective erlang OTP versions aka 19+).

Usage

Check out the documentation of the main Statistex module but here is a small overview:

iex> samples = [1, 3.0, 2.35, 11.0, 1.37, 35, 5.5, 10, 0, 2.35]
# calculate all available statistics at once, efficiently reusing already calculated values
iex> Statistex.statistics(samples)
%Statistex{
  average: 7.156999999999999,
  frequency_distribution: %{
    0 => 1,
    1 => 1,
    10 => 1,
    35 => 1,
    1.37 => 1,
    2.35 => 2,
    3.0 => 1,
    5.5 => 1,
    11.0 => 1
  },
  maximum: 35,
  median: 2.675,
  minimum: 0,
  mode: 2.35,
  percentiles: %{50 => 2.675},
  sample_size: 10,
  standard_deviation: 10.47189577445799,
  standard_deviation_ratio: 1.46316833512058,
  total: 71.57,
  variance: 109.6606011111111
}
# or just calculate the value you need
iex> Statistex.average(samples)
7.156999999999999
# Calculate the value you want reusing values you already know
# (check the docs for what functions accepts what options)
iex> Statistex.average(samples, sample_size: 10)
7.156999999999999
# Most Statistex functions raise given an empty list as most functions don't make sense then.
# It is recommended that you manually handle the empty list case should that occur as your
# output is likely also very different from when you have statistics.
iex> Statistex.statistics([])
** (ArgumentError) Passed an empty list ([]) to calculate statistics from, please pass a list containing at least on number.

Supported Statistics

For an up to date overview with explanations please check out the documentation of the Statistex module.

Statistics currently supported:

Alternatives

In elixir there are 2 notable other libraries that I'm aware of: statistics and Numerix.

Both include more functions than just for statistics: general math and more (drawing of random values for instance). They also have more statistics related functions as of this writing. So if you'e looking for something, that Statistex doesn't provide (yet) these are some of the first places I'd look.

Why would you still want to use Statistex?

We're naturally also looking to add more statistical functions as we go along, and pull requests are very welcome :)

Performance

Statistex is written in pure elixir. C-extensions and friends would surely be faster. The goal of statistex is to be as fast possible in pure elixir while providing correct results. Hence, the focus on reusing previously calculated values and providing that ability to users.

History

Statistex was extracted from benchee and as such it powers benchees statistics calculations. Its great ancestor (if you will) was first conceived in this commit.

Contributing

Contributions to benchee are very welcome! Bug reports, documentation, spelling corrections, new statistics, bugfixes... all of those (and probably more) are much appreciated contributions!

Please respect the Code of Conduct.

You can also look directly at the open issues.

A couple of (hopefully) helpful points:

Development