Overview
Directional statistics package for Julia. Currently includes several circular and spatial descriptive statistics, see reference below for details.
Usage
Package contains submodules, and many functions are indended to be qualified on call. This lets us use names such as mean()
and still have no conflicts with functions in Statistics
or StatsBase
.
using DirectionalStatistics
Circular.mean(...)
All circular statistics operate in a 2π range by default, that corresponds to the natural range of angles. Arbitrary ranges are supported and can be specified as an interval:
using IntervalSets
Circular.mean(array, 0..π)
Circular.mean(array, -180..+180)
Reference
#
DirectionalStatistics.Circular.center_angle
— Method.
Center angular value x
to be within a symmetric range of length range
around at
, from at - range/2
to at + range/2
. Assumes circular structure: x + range
is equivalent to x
.
julia> Circular.center_angle(0)
0.0
julia> Circular.center_angle(4π + 1)
1.0
julia> Circular.center_angle(4π - 1)
-1.0
julia> Circular.center_angle(10, at=0, range=3)
1.0
#
DirectionalStatistics.Circular.distance
— Method.
Distance between two angles, x
and y
. Assumes circular structure: x + range
is equivalent to x
.
julia> Circular.distance(0, 1)
1.0
julia> Circular.distance(0, 4π + 1)
1.0
julia> Circular.distance(0, 5.5, range=3)
0.5
#
DirectionalStatistics.Circular.mad
— Method.
Median absolute deviation (MAD) of a collection of circular data.
julia> Circular.mad([0])
0.0
julia> Circular.mad([0, 1, 2])
1.0
julia> Circular.mad([0, 2π + 1, 2])
1.0
julia> Circular.mad([0, 1, 2], -2..4) ≈ 1
true
#
DirectionalStatistics.Circular.mean
— Method.
Mean of a collection of circular data.
julia> Circular.mean([0, 1, 2, 3])
1.5
julia> Circular.mean([1, 2π]) ≈ 0.5
true
julia> Circular.mean([1, 5], 0..4) ≈ 1
true
#
DirectionalStatistics.Circular.median
— Method.
Median of a collection of circular data.
Computes the median that minimizes the sum of arc distances sense. Always returns one of the datapoints, so the result is a medoid.
For discussion of different circular medians see e.g. https://hci.iwr.uni-heidelberg.de/sites/default/files/profiles/mstorath/files/storath2017fast.pdf.
julia> Circular.median([0, 1, 2])
1
julia> Circular.median([0.05, 2π - 0.1, 6π + 0.1])
0.05
julia> Circular.median([0, 1, 2], -2..4)
1.0
#
DirectionalStatistics.Circular.sample_range
— Method.
Sample range - the shortest arc distance encompassing all of the data in the collection.
julia> Circular.sample_range([-1, 0, 2])
3.0
julia> Circular.sample_range([-1, 0, 1, 2, 3, 4])
5.0
julia> Circular.sample_range([-1, 0, 2, 3, 4])
4.283185307179586
julia> Circular.sample_range([-1, 0, 2, 5, 6])
3.2831853071795862
julia> Circular.sample_range([-1, 4π])
1.0
julia> Circular.sample_range([0, 1], 0..π)
1.0
#
DirectionalStatistics.Circular.std
— Method.
Standard deviation of a collection of circular data.
julia> Circular.std([0])
0.0
julia> Circular.std([0, 1, 2, 3])
1.2216470118898806
julia> Circular.std([0, 2π])
0.0
julia> Circular.std([0, 1, 2, 3], -10..10)
1.126024231452878
#
DirectionalStatistics.Circular.to_range
— Method.
Transform x
to be within the range rng
assuming circular structure: x + width(rng)
is equivalent to x
. In effect, this adds the necessary multiple of width(rng)
to x
so that it falls into rng
.
julia> Circular.to_range(0, 0..2π)
0.0
julia> Circular.to_range(4π + 1, 0..2π)
1.0
julia> Circular.to_range(5.5, -1..1)
-0.5
#
DirectionalStatistics.Circular.var
— Method.
Variance of a collection of circular data.
#
DirectionalStatistics.geometric_mad
— Method.
Geometric Median absolute deviation (MAD) of a collection of points.
See [https://en.wikipedia.org/wiki/Medianabsolutedeviation#Geometricmedianabsolute_deviation].
#
DirectionalStatistics.geometric_median
— Method.
Geometric median of a collection of points. Points can be specified as real numbers (1d), complex numbers (2d), or arbitrary vectors.
See [https://en.wikipedia.org/wiki/Geometric_median].
julia> geometric_median([1, 2, 3])
2.0
julia> geometric_median([0, 1, 1im, 1+1im]) ≈ 0.5+0.5im
true
julia> geometric_median([[0, 0], [0, 1], [1, 0], [1, 1]]) ≈ [0.5, 0.5]
true
#
DirectionalStatistics.most_distant_points
— Method.
Select a pair of most distant points in the collection. Points can be specified as real numbers (1d), complex numbers (2d), or arbitrary vectors.
julia> most_distant_points([1, 2, 3])
(3, 1)
julia> most_distant_points([0, 1, 1+1im])
(1 + 1im, 0 + 0im)
julia> most_distant_points([[0, 0], [0, 1], [1, 1]])
([1, 1], [0, 0])
#
DirectionalStatistics.most_distant_points_ix
— Method.
Select indices of a pair of most distant points in the collection. Points can be specified as real numbers (1d), complex numbers (2d), or arbitrary vectors.
julia> most_distant_points_ix([1, 2, 3])
(3, 1)
julia> most_distant_points_ix([0, 1, 1+1im])
(3, 1)
julia> most_distant_points_ix([[0, 0], [0, 1], [1, 1]])
(3, 1)