sourcelib/Stats.xtl
1⍝# Stats: a small statistics library (a standard library, built into
2⍝# xetal). Import it with an alias of your choice: "s:" u_se< "Stats".
3⍝# It is a demo library, loaded only by that import: a small subset of
4⍝# X_eTaL-libraries' Statistics, which has much more (a program may use
5⍝# either).
6⍝# Names with l: are exported; the others are private to this file.
7
8⍝# The arithmetic mean, of Int or Float numbers.
9⍝# >> "s:" u_se< "Stats"
10⍝# >> s:m_ean 2 4 4 4 5 5 7 9
11⍝# 5.0
12ˡm̲ean ← [[f̲loat '+ r̲/] ÷ [f̲loat t̲ally]]
13
14s̲quare ← { ⍵ × ⍵ } ⍝ private: not visible outside
15d̲eviations ← [f̲loat − ˡm̲ean]
16
17⍝# The variance: the mean squared deviation from the mean.
18⍝# >> "s:" u_se< "Stats"
19⍝# >> s:v_ariance 2 4 4 4 5 5 7 9
20⍝# 4.0
21ˡv̲ariance ← [ˡm̲ean [s̲quare d̲eviations]]
22
23⍝# The standard deviation: the square root of the variance.
24⍝# >> "s:" u_se< "Stats"
25⍝# >> s:s_d 2 4 4 4 5 5 7 9
26⍝# 2.0
27ˡs̲d ← { (ˡv̲ariance ⍵) ^ 0.5 }
28
29⍝# The range: the largest minus the smallest.
30⍝# >> "s:" u_se< "Stats"
31⍝# >> s:r_ange 2 4 4 4 5 5 7 9
32⍝# 7
33ˡr̲ange ← ['m̲ax r̲/ − 'm̲in r̲/]