Skip to content

Commit 41b00c4

Browse files
committed
Import weighted stats and moments from StatsBase to Statistics
This includes methods for mean, quantile, median, var, std, cov and cor, plus new functions skewness and kurtosis, and weight types. Code is copied from StatsBase with some cleanup where needed, in particular for dispatch, to move from `@nloops`/`@nrefs` to cartesian indexing and to be closer to the mapreducedim code. Weights are now passed via a keyword argument rather than by dispatching on AbstractWeights, so as to support any array where all weights types give the same result.
1 parent edac940 commit 41b00c4

File tree

9 files changed

+1075
-1289
lines changed

9 files changed

+1075
-1289
lines changed

docs/src/index.md

Lines changed: 74 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,86 @@
11
# Statistics
22

3-
The Statistics module contains basic statistics functionality.
3+
```@meta
4+
DocTestSetup = :(using Statistics)
5+
```
46

5-
!!! note
6-
To use any of the examples described below, run `using Statistics` and then the code from the example.
7+
The Statistics module contains basic statistics functionality: mean, median, quantiles,
8+
standard deviation, variance, skewness, kurtosis, correlation and covariance.
9+
Statistics can be weighted, and several weights types are distinguished to apply appropriate
10+
corrections where necessary.
11+
12+
## Mean, median and quantiles
13+
14+
```@docs
15+
Statistics.mean
16+
Statistics.mean!
17+
Statistics.median
18+
Statistics.median!
19+
Statistics.middle
20+
Statistics.quantile
21+
Statistics.quantile!
22+
```
23+
24+
## Moments
725

826
```@docs
927
Statistics.std
1028
Statistics.stdm
1129
Statistics.var
1230
Statistics.varm
31+
Statistics.skewness
32+
Statistics.kurtosis
33+
```
34+
35+
## Correlation and covariance
36+
37+
```@docs
1338
Statistics.cor
1439
Statistics.cov
15-
Statistics.mean!
16-
Statistics.mean
17-
Statistics.median!
18-
Statistics.median
19-
Statistics.middle
20-
Statistics.quantile!
21-
Statistics.quantile
40+
```
41+
42+
## Weights types
43+
44+
Four statistical weights types are provided which inherit from the `AbstractWeights` type:
45+
46+
- `Weights` is a generic type for arbitary weights. Using this type will trigger an error
47+
with functions which rely on assumptions about a particular definition of weights.
48+
- `AnalyticWeights` describe the relative importance for each observation.
49+
These weights may also be referred to as reliability weights, precision weights
50+
or inverse variance weights. These are typically used when the observations
51+
are aggregate values (e.g. averages) with differing variances.
52+
- `FrequencyWeights` describe the number of times (or frequency) each observation
53+
was observed. These weights may also be referred to as case weights or repeat weights.
54+
- `ProbabilityWeights` represent the inverse of the sampling probability
55+
for each observation, providing a correction mechanism for under- or over-sampling
56+
certain population groups. These weights may also be referred to as sampling weights.
57+
58+
The choice of weights impacts how bias is corrected in several methods.
59+
See the [`var`](@ref), [`std`](@ref), [`cov`](@ref) and [`quantile`](@ref)
60+
docstrings for more details.
61+
62+
Short-hand constructors `weights`, `aweights`, `fweights` and `pweights`
63+
are provided for convenience.
64+
65+
!!! note
66+
- The weight vector is a light-weight wrapper of the input vector.
67+
The input vector is NOT copied during construction.
68+
- The weight vector maintains the sum of weights, which is computed upon construction.
69+
If the value of the sum is pre-computed, one can supply it as the second argument
70+
to the constructor and save the time of computing the sum again.
71+
72+
```@docs
73+
Statistics.AbstractWeights
74+
Statistics.Weights
75+
Statistics.AnalyticWeights
76+
Statistics.FrequencyWeights
77+
Statistics.ProbabilityWeights
78+
Statistics.weights
79+
Statistics.aweights
80+
Statistics.fweights
81+
Statistics.pweights
82+
```
83+
84+
```@meta
85+
DocTestSetup = nothing
2286
```

0 commit comments

Comments
 (0)