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_angleMethod.

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

source

# DirectionalStatistics.Circular.distanceMethod.

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

source

# DirectionalStatistics.Circular.madMethod.

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

source

# DirectionalStatistics.Circular.meanMethod.

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

source

# DirectionalStatistics.Circular.medianMethod.

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

source

# DirectionalStatistics.Circular.sample_rangeMethod.

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

source

# DirectionalStatistics.Circular.stdMethod.

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

source

# DirectionalStatistics.Circular.to_rangeMethod.

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

source

# DirectionalStatistics.Circular.varMethod.

Variance of a collection of circular data.

source

# DirectionalStatistics.geometric_madMethod.

Geometric Median absolute deviation (MAD) of a collection of points.

See [https://en.wikipedia.org/wiki/Medianabsolutedeviation#Geometricmedianabsolute_deviation].

source

# DirectionalStatistics.geometric_medianMethod.

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

source

# DirectionalStatistics.most_distant_pointsMethod.

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])

source

# DirectionalStatistics.most_distant_points_ixMethod.

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)

source