You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*StatsBase.jl* is a Julia package that provides basic support for statistics. Particularly, it implements a variety of statistics-related functions, such as scalar statistics, high-order moment computation, counting, ranking, covariances, sampling, and empirical density estimation.
If you need to build Julia from source with a git checkout of Statistics, then instead use `make DEPS_GIT=Statistics` when building Julia. The `Statistics` repo is in `stdlib/Statistics`, and created initially with a detached `HEAD`. If you're doing this from a pre-existing Julia repository, you may need to `make clean` beforehand.
Copy file name to clipboardExpand all lines: docs/src/weights.md
+81-2Lines changed: 81 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,15 +64,91 @@ w = ProbabilityWeights([0.2, 0.1, 0.3])
64
64
w =pweights([0.2, 0.1, 0.3])
65
65
```
66
66
67
+
### `UnitWeights`
68
+
69
+
Unit weights are a special case in which all observations are given a weight equal to `1`. Using such weights is equivalent to computing unweighted statistics.
70
+
71
+
This type can notably be used when implementing an algorithm so that a only a weighted variant has to be written. The unweighted variant is then obtained by passing a `UnitWeights` object. This is very efficient since no weights vector is actually allocated.
72
+
73
+
```julia
74
+
w =uweights(3)
75
+
w =uweights(Float64, 3)
76
+
```
77
+
67
78
### `Weights`
68
79
69
-
The `Weights` type describes a generic weights vector which does not support all operations possible for `FrequencyWeights`, `AnalyticWeights`and `ProbabilityWeights`.
80
+
The `Weights` type describes a generic weights vector which does not support all operations possible for `FrequencyWeights`, `AnalyticWeights`, `ProbabilityWeights`and `UnitWeights`.
70
81
71
82
```julia
72
83
w =Weights([1., 2., 3.])
73
84
w =weights([1., 2., 3.])
74
85
```
75
86
87
+
### Exponential weights: `eweights`
88
+
89
+
Exponential weights are a common form of temporal weights which assign exponentially decreasing
90
+
weights to past observations.
91
+
92
+
If `t` is a vector of temporal indices then for each index `i` we compute the weight as:
93
+
94
+
``λ (1 - λ)^{1 - i}``
95
+
96
+
``λ`` is a smoothing factor or rate parameter such that ``0 < λ ≤ 1``.
97
+
As this value approaches 0, the resulting weights will be almost equal,
98
+
while values closer to 1 will put greater weight on the tail elements of the vector.
99
+
100
+
For example, the following call generates exponential weights for ten observations with ``λ = 0.3``.
NOTE: This is equivalent to `eweights(something.(indexin(t, r)), 0.3)`, which is saying that for each value in `t` return the corresponding index for that value in `r`.
150
+
Since `indexin` returns `nothing` if there is no corresponding value from `t` in `r` we use `something` to eliminate that possibility.
151
+
76
152
## Methods
77
153
78
154
`AbstractWeights` implements the following methods:
0 commit comments