Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
lbarasti committed Mar 30, 2020
1 parent 79953a4 commit 189432e
Show file tree
Hide file tree
Showing 13 changed files with 116 additions and 101 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,31 @@ include Statistics
x = [1, 10, 7]
mean(x) # 6
var(x) # 14
var(x, corrected: true) # 21
var(x, mean: 8) # 18.0
std(x) # 3.7416...
```

If you'd like to know a bit more about your dataset, you can simply `describe` it

```crystal
x = (1..1000).map { rand }.to_a # a uniformely distributed dataset
describe(x)
# {
# mean: 0.48, var: 0.08, std: 0.28,
# skewness: 0.04, kurtosis: 1.81,
# min: 0.01, middle: 0.49, max: 0.99,
# q1: 0.24, median: 0.49, q3: 0.73
# }
```

`Statistics.describe` returns a `NamedTuple`, so you can extract any value via indexing:

```crystal
stats = describe(x)
stats[:q1] # returns the first quartile of your sample
```

For a complete list of the statistical functions provided, including `quantile`, `moment` and `skew`, check out the [docs](https://lbarasti.com/statistics/Statistics.html).

### Sampling
To work with distributions, import the `Distributions` namespace as follows.
```crystal
Expand Down
62 changes: 31 additions & 31 deletions docs/Statistics.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ <h2>
</h2>


<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L1" target="_blank">
<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/lib/distributions.cr#L1" target="_blank">
lib/distributions.cr
</a>

<br/>


<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L6" target="_blank">
<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/statistics.cr#L6" target="_blank">
statistics.cr
</a>

Expand Down Expand Up @@ -332,13 +332,13 @@ <h2>

<p>Parameters</p>

<ul><li><code>values</code>: a one-dimensional dataset.</li></ul>
<ul><li>values: a one-dimensional dataset.</li></ul>
</div>

<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L14" target="_blank">View source</a>]
[<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/statistics.cr#L14" target="_blank">View source</a>]

</div>
</div>
Expand All @@ -359,13 +359,13 @@ <h2>

<p>Parameters</p>

<ul><li><code>values</code>: a one-dimensional dataset</li></ul>
<ul><li>values: a one-dimensional dataset</li></ul>
</div>

<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L38" target="_blank">View source</a>]
[<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/statistics.cr#L38" target="_blank">View source</a>]

</div>
</div>
Expand All @@ -384,15 +384,15 @@ <h2>

<p>Parameters</p>

<ul><li><code>values</code>: a one-dimensional dataset.</li><li><code>corrected</code>: when set to <code>true</code>, then the calculations are corrected for statistical bias. Default is <code>false</code>.</li><li><code>excess</code>: when set to <code>true</code>, computes the <a href="https://en.wikipedia.org/wiki/Kurtosis#Excess_kurtosis" target="_blank">excess kurtosis</a>. Default is <code>false</code>.</li></ul>
<ul><li>values: a one-dimensional dataset.</li><li>corrected: when set to <code>true</code>, then the calculations are corrected for statistical bias. Default is <code>false</code>.</li><li>excess: when set to <code>true</code>, computes the <a href="https://en.wikipedia.org/wiki/Kurtosis#Excess_kurtosis" target="_blank">excess kurtosis</a>. Default is <code>false</code>.</li></ul>

<p>This implementation is based on the <a href="https://github.com/scipy/scipy/blob/3de0d58/scipy/stats/stats.py#L1142" target="_blank">scipy/stats.py</a>.</p>
</div>

<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L53" target="_blank">View source</a>]
[<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/statistics.cr#L53" target="_blank">View source</a>]

</div>
</div>
Expand All @@ -411,13 +411,13 @@ <h2>

<p>Parameters</p>

<ul><li><code>values</code>: a one-dimensional dataset.</li></ul>
<ul><li>values: a one-dimensional dataset.</li></ul>
</div>

<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L72" target="_blank">View source</a>]
[<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/statistics.cr#L72" target="_blank">View source</a>]

</div>
</div>
Expand All @@ -438,7 +438,7 @@ <h2>

<p>Parameters</p>

<ul><li><code>values</code>: a one-dimensional dataset.</li><li><code>sorted</code>: when <code>true</code>, the computations assume that the provided values are
<ul><li>values: a one-dimensional dataset.</li><li>sorted: when <code>true</code>, the computations assume that the provided values are
sorted. Default is <code>false</code>.</li></ul>

<p>See Julia's <a href="https://docs.julialang.org/en/v1/stdlib/Statistics/#Statistics.median" target="_blank">Statistics.median</a>.</p>
Expand All @@ -447,7 +447,7 @@ <h2>
<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L86" target="_blank">View source</a>]
[<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/statistics.cr#L86" target="_blank">View source</a>]

</div>
</div>
Expand All @@ -468,7 +468,7 @@ <h2>
<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L111" target="_blank">View source</a>]
[<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/statistics.cr#L111" target="_blank">View source</a>]

</div>
</div>
Expand All @@ -488,15 +488,15 @@ <h2>

<p>Parameters</p>

<ul><li><code>values</code>: a one-dimensional dataset.</li></ul>
<ul><li>values: a one-dimensional dataset.</li></ul>

<p>See Julia's <a href="https://docs.julialang.org/en/v1/stdlib/Statistics/#Statistics.middle" target="_blank">Statistics.middle</a>.</p>
</div>

<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L105" target="_blank">View source</a>]
[<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/statistics.cr#L105" target="_blank">View source</a>]

</div>
</div>
Expand All @@ -516,17 +516,17 @@ <h2>
<p>Returns a pair with the modal value and the bin-count for the modal bin.
If there is more than one such value, no guarantees are made which one will be picked.</p>

<p><span class="flag purple">NOTE</span> computing the mode requires traversing the entire dataset.</p>
<p><span class="flag purple">NOTE</span> Computing the mode requires traversing the entire dataset.</p>

<p>Parameters</p>

<ul><li><code>values</code>: a one-dimensional dataset.</li></ul>
<ul><li>values: a one-dimensional dataset.</li></ul>
</div>

<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L123" target="_blank">View source</a>]
[<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/statistics.cr#L123" target="_blank">View source</a>]

</div>
</div>
Expand All @@ -545,14 +545,14 @@ <h2>

<p>Parameters</p>

<ul><li><code>values</code>: a one-dimensional dataset.</li><li><code><a href="Statistics.html#mean(values)-instance-method">#mean</a></code>: a pre-computed mean. If a mean is not provided, then the sample's
mean will be computed. Default is <code>nil</code>.</li><li><code>n</code>: Order of central moment that is returned. Default is <code>1</code>.</li></ul>
<ul><li>values: a one-dimensional dataset.</li><li>mean: a pre-computed mean. If a mean is not provided, then the sample's
mean will be computed. Default is <code>nil</code>.</li><li>n: order of central moment that is returned. Default is <code>1</code>.</li></ul>
</div>

<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L134" target="_blank">View source</a>]
[<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/statistics.cr#L134" target="_blank">View source</a>]

</div>
</div>
Expand All @@ -574,15 +574,15 @@ <h2>

<p>Parameters</p>

<ul><li><code>values</code>: a one-dimensional dataset.</li><li><code>p</code>: probability. Values of <code>p</code> should be in the interval <code>[0, 1]</code>.</li><li><code>sorted</code> indicates whether <code>values</code> can be assumed to be sorted.</li></ul>
<ul><li>values: a one-dimensional dataset.</li><li>p: probability. Values of <code>p</code> should be in the interval <code>[0, 1]</code>.</li><li>sorted indicates whether values can be assumed to be sorted.</li></ul>

<p>Implementation based on Julia's <a href="https://docs.julialang.org/en/v1/stdlib/Statistics/#Statistics.quantile" target="_blank">Statistics.quantile</a>.</p>
</div>

<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L150" target="_blank">View source</a>]
[<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/statistics.cr#L150" target="_blank">View source</a>]

</div>
</div>
Expand All @@ -601,15 +601,15 @@ <h2>

<p>Parameters</p>

<ul><li><code>values</code>: a one-dimensional dataset.</li><li><code>corrected</code>: when set to <code>true</code>, then the calculations are corrected for statistical bias. Default is <code>false</code>.</li></ul>
<ul><li>values: a one-dimensional dataset.</li><li>corrected: when set to <code>true</code>, then the calculations are corrected for statistical bias. Default is <code>false</code>.</li></ul>

<p>This implementation is based on the <a href="https://github.com/scipy/scipy/blob/3de0d58/scipy/stats/stats.py#L1039" target="_blank">scipy/stats.py</a>.</p>
</div>

<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L170" target="_blank">View source</a>]
[<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/statistics.cr#L170" target="_blank">View source</a>]

</div>
</div>
Expand All @@ -628,16 +628,16 @@ <h2>

<p>Parameters</p>

<ul><li><code>values</code>: a one-dimensional dataset.</li><li><code><a href="Statistics.html#mean(values)-instance-method">#mean</a></code>: a pre-computed <code><a href="Statistics.html#mean(values)-instance-method">#mean</a></code>. This could be a pre-computed sample's mean
<ul><li>values: a one-dimensional dataset.</li><li>mean: a pre-computed mean. This could be a pre-computed sample's mean
or the population's known mean. If a mean is not provided, then the sample's
mean will be computed. Default is <code>nil</code>.</li><li><code>corrected</code>: when set to <code>true</code>, then the sum of squares is scaled
mean will be computed. Default is <code>nil</code>.</li><li>corrected: when set to <code>true</code>, then the sum of squares is scaled
with <code>values.size - 1</code>, rather than with <code>values.size</code>. Default is <code>false</code>.</li></ul>
</div>

<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L188" target="_blank">View source</a>]
[<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/statistics.cr#L188" target="_blank">View source</a>]

</div>
</div>
Expand All @@ -656,16 +656,16 @@ <h2>

<p>Parameters</p>

<ul><li><code>values</code>: a one-dimensional dataset.</li><li><code><a href="Statistics.html#mean(values)-instance-method">#mean</a></code>: a pre-computed <code><a href="Statistics.html#mean(values)-instance-method">#mean</a></code>. This could be a pre-computed sample's mean
<ul><li>values: a one-dimensional dataset.</li><li>mean: a pre-computed mean. This could be a pre-computed sample's mean
or the population's known mean. If a mean is not provided, then the sample's
mean will be computed. Default is <code>nil</code>.</li><li><code>corrected</code>: when set to <code>true</code>, then the sum of squares is scaled
mean will be computed. Default is <code>nil</code>.</li><li>corrected: when set to <code>true</code>, then the sum of squares is scaled
with <code>values.size - 1</code>, rather than with <code>values.size</code>. Default is <code>false</code>.</li></ul>
</div>

<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/statistics.cr#L201" target="_blank">View source</a>]
[<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/statistics.cr#L201" target="_blank">View source</a>]

</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/Statistics/Distributions.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ <h2>
</h2>


<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L2" target="_blank">
<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/lib/distributions.cr#L2" target="_blank">
lib/distributions.cr
</a>

Expand Down
27 changes: 3 additions & 24 deletions docs/Statistics/Distributions/Constant.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ <h2>
</h2>


<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L3" target="_blank">
<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/lib/distributions.cr#L3" target="_blank">
lib/distributions.cr
</a>

Expand Down Expand Up @@ -174,11 +174,6 @@ <h2>

</li>

<li class="entry-summary">
<a href="#rand=(rand)-instance-method" class="signature"><strong>#rand=</strong>(rand)</a>

</li>

</ul>


Expand Down Expand Up @@ -230,7 +225,7 @@ <h2>
<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L6" target="_blank">View source</a>]
[<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/lib/distributions.cr#L6" target="_blank">View source</a>]

</div>
</div>
Expand Down Expand Up @@ -260,23 +255,7 @@ <h2>
<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L4" target="_blank">View source</a>]

</div>
</div>

<div class="entry-detail" id="rand=(rand)-instance-method">
<div class="signature">

def <strong>rand=</strong>(rand)

<a class="method-permalink" href="#rand=(rand)-instance-method">#</a>
</div>

<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L4" target="_blank">View source</a>]
[<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/lib/distributions.cr#L4" target="_blank">View source</a>]

</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions docs/Statistics/Distributions/Exponential.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ <h2>
</h2>


<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L10" target="_blank">
<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/lib/distributions.cr#L10" target="_blank">
lib/distributions.cr
</a>

Expand Down Expand Up @@ -233,7 +233,7 @@ <h2>
<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L13" target="_blank">View source</a>]
[<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/lib/distributions.cr#L13" target="_blank">View source</a>]

</div>
</div>
Expand Down Expand Up @@ -263,7 +263,7 @@ <h2>
<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L16" target="_blank">View source</a>]
[<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/lib/distributions.cr#L16" target="_blank">View source</a>]

</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions docs/Statistics/Distributions/Normal.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ <h2>
</h2>


<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L21" target="_blank">
<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/lib/distributions.cr#L21" target="_blank">
lib/distributions.cr
</a>

Expand Down Expand Up @@ -248,7 +248,7 @@ <h2>
<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L25" target="_blank">View source</a>]
[<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/lib/distributions.cr#L25" target="_blank">View source</a>]

</div>
</div>
Expand Down Expand Up @@ -278,7 +278,7 @@ <h2>
<br/>
<div>

[<a href="https://github.com/lbarasti/statistics/blob/97da7c6c7422ab7208bdbf6822ef57ecd20dec27/src/lib/distributions.cr#L28" target="_blank">View source</a>]
[<a href="https://github.com/lbarasti/statistics/blob/79953a4cde1139aef09ab82c46d20a64ca15da72/src/lib/distributions.cr#L28" target="_blank">View source</a>]

</div>
</div>
Expand Down
Loading

0 comments on commit 189432e

Please sign in to comment.