A set of functions for statistical analysis ** Created just for fun 😃
-
Add the dependency to your
shard.yml
:dependencies: statistical-analysis: github: ouracademy/statistical-analysis
-
Run
shards install
See the spec files for more documentation
require "statistical-analysis"
# Factorial
5.factorial # Object (OO) way
Math.factorial(5) # Functional (FP) way
# Permutation
# In math: n P r or P(n,r)
4.permutation(r: 3) # 24
Math.permutation(4, 3)
# n C r or C(n,r)
4.combination(r: 3) # 4
Math.combination(4, 3)
# OO
X = [20, 23, 21, 22]
X.mean # also you can use X.harmonic_mean
X.standard_deviation # or alias X.std_dev
# FP
# if you include the Stats module or else Stats.mean(X)
include Stats
mean(X) # also you can use harmonic_mean(X)
standard_deviation(X) # or alias std_dev(X)
# Binomial
x = 2
p = binomial_distribution(trials: 5, success_probability: 0.1)
p.call(x) # approx. 0.0729, note syntax like math: p(x)
p = bernoulli_distribution(success_probability: 0.7)
p.call(0) # 0.3
# Test if some function is a distribution function
X = [2, 3, 4, 5, 6] # given some discrete sample (X)
DistributionFunction.is?(X){ |x| 5.2551 / x ** 3 } # true
- Fork it (https://github.com/ouracademy/statistical-analysis/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request