Circular mean
In mathematics and statistics, a circular mean or angular mean is a mean designed for angles and similar cyclic quantities, such as times of day, and fractional parts of real numbers.
This is necessary since most of the usual means may not be appropriate on angle-like quantities. For example, the arithmetic mean of 0° and 360° is 180°, which is misleading because 360° equals 0° modulo a full cycle. As another example, the "average time" between 11 PM and 1 AM is either midnight or noon, depending on whether the two times are part of a single night or part of a single calendar day.
The circular mean is one of the simplest examples of directional statistics and of statistics of non-Euclidean spaces.
This computation produces a different result than the arithmetic mean, with the difference being greater when the angles are widely distributed. For example, the arithmetic mean of the three angles 0°, 0°, and 90° is / 3 = 30°, but the vector mean is arctan = 26.565°. Moreover, with the arithmetic mean the circular variance is only defined ±180°.
Definition
Since the arithmetic mean is not always appropriate for angles, the following method can be used to obtain both a mean value and measure for the variance of the angles:Convert all angles to corresponding points on the unit circle, e.g., to. That is, convert polar coordinates to Cartesian coordinates. Then compute the arithmetic mean of these points. The resulting point will lie within the unit disk but generally not on the unit circle. Convert that point back to polar coordinates. The angle is a reasonable mean of the input angles. The resulting radius will be 1 if all angles are equal. If the angles are uniformly distributed on the circle, then the resulting radius will be 0, and there is no circular mean. In other words, the radius measures the concentration of the angles.
Given the angles a common formula of the mean using the atan2 variant of the arctangent function is
Using complex arithmetic
An equivalent definition can be formulated using complex numbers:In order to match the above derivation using arithmetic means of points, the sums would have to be divided by. However, the scaling does not matter for and, thus it can be omitted.
This may be more succinctly stated by realizing that directional data are in fact vectors of unit length. In the case of one-dimensional data, these data points can be represented conveniently as complex numbers of unit magnitude, where is the measured angle. The mean resultant vector for the sample is then:
The sample mean angle is then the argument of the mean resultant:
The length of the sample mean resultant vector is:
and will have a value between 0 and 1. Thus the sample mean resultant vector can be represented as:
Similar calculations are also used to define the circular variance.
Properties
The circular mean,- maximizes the likelihood of the mean parameter of the von Mises distribution and
- minimizes the sum of a certain distance on the circle, more precisely
Example
Implementation
In this python code we use day hours to find circular average of them:import math
def circular_mean:
# Convert hours to radians
# To convert from hours to degrees, we need to
# multiply hour by 360/24 = 15.
radians =
# Calculate the sum of sin and cos values
sin_sum = sum
cos_sum = sum
# Calculate the circular mean using arctan2
mean_rad = math.atan2
# Convert the mean back to hours
mean_hour = % 24
return mean_hour
- Example usage:
mean_hour = circular_mean
hours =
mean_hour = circular_mean
hours =
mean_hour = circular_mean