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.[1] 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 (0° + 0° + 90°) / 3 = 30°, but the vector mean is arctan(1/2) = 26.565°. Moreover, with the arithmetic mean the circular variance is only defined ±180°.
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.,
\alpha
(\cos\alpha,\sin\alpha)
Given the angles
\alpha1,...,\alphan
\bar{\alpha}=\operatorname{atan2}\left(
1 | |
n |
n | |
\sum | |
j=1 |
\sin\alphaj,
1 | |
n |
n | |
\sum | |
j=1 |
\cos\alphaj\right)=
n | |
\operatorname{atan2}\left(\sum | |
j=1 |
\sin\alphaj,
n | |
\sum | |
j=1 |
\cos\alphaj\right)
An equivalent definition can be formulated using complex numbers:
\bar{\alpha}=\arg\left(
1 | |
n |
n | |
\sum | |
j=1 |
\exp(i ⋅ \alphaj)\right)=
n | |
\arg\left(\sum | |
j=1 |
\exp(i ⋅ \alphaj)\right)
In order to match the above derivation using arithmetic means of points, the sums would have to be divided by
n
\operatorname{atan2}
\arg
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
z=\cos(\theta)+i\sin(\theta)=ei\theta
\theta
\overline{\rho
The sample mean angle is then the argument of the mean resultant:
\overline{\theta}=\operatorname{Arg}(\overline{\rho
The length of the sample mean resultant vector is:
\overline{R}=|\overline{\rho
and will have a value between 0 and 1. Thus the sample mean resultant vector can be represented as:
\overline{\rho
Similar calculations are also used to define the circular variance.
The circular mean,
\bar{\alpha}
\bar{\alpha}=\underset{\beta}{\operatorname{argmin}}
n | |
\sum | |
j=1 |
d(\alphaj,\beta),whered(\varphi,\beta)=1-\cos(\varphi-\beta).
The distance
d(\varphi,\beta)
\varphi
\beta
A simple way to calculate the mean of a series of angles (in the interval [0°, 360°)) is to calculate the mean of the cosines and sines of each angle, and obtain the angle by calculating the inverse tangent. Consider the following three angles as an example: 10, 20, and 30 degrees. Intuitively, calculating the mean would involve adding these three angles together and dividing by 3, in this case indeed resulting in a correct mean angle of 20 degrees. By rotating this system anticlockwise through 15 degrees the three angles become 355 degrees, 5 degrees and 15 degrees. The arithmetic mean is now 125 degrees, which is the wrong answer, as it should be 5 degrees. The vector mean can be calculated in the following way, using the mean sine and the mean cosine :
\bars=
1 | |
3 |
(\sin(355\circ)+\sin(5\circ)+\sin(15\circ))=
1 | |
3 |
(-0.087+0.087+0.259) ≈ 0.086
\barc=
1 | |
3 |
(\cos(355\circ)+\cos(5\circ)+\cos(15\circ))=
1 | |
3 |
(0.996+0.996+0.966) ≈ 0.986
\bar\theta= \left. \begin{cases} \arctan\left(
\bars | |
\barc |
\right)&\bars>0, \barc>0\\ \arctan\left(
\bars | |
\barc |
\right)+180\circ&\barc<0\\ \arctan\left(
\bars | |
\barc |
\right)+360\circ&\bars<0, \barc>0 \end{cases} \right\} =\arctan\left(
0.086 | |
0.986 |
\right)=\arctan(0.087)=5\circ.
In this python code we use day hours to find circular average of them:
def circular_mean(hours): # Convert hours to radians # To convert from hours to degrees, we need to # multiply hour by 360/24 = 15. radians = [math.radians(hour * 15) for hour in hours]
# Calculate the sum of sin and cos values sin_sum = sum([math.sin(rad) for rad in radians]) cos_sum = sum([math.cos(rad) for rad in radians])
# Calculate the circular mean using arctan2 mean_rad = math.atan2(sin_sum, cos_sum)
# Convert the mean back to hours mean_hour = (math.degrees(mean_rad) / 15) % 24
return mean_hour
hours = [0, 12, 18]mean_hour = circular_mean(hours)print("First Circular mean:", round(mean_hour, 2))
hours = [0, 12]mean_hour = circular_mean(hours)print("Second Circular mean:", round(mean_hour, 2))
hours = [0, 0, 12, 12, 24]mean_hour = circular_mean(hours)print("Third Circular mean:", round(mean_hour, 2))
A weighted spherical mean can be defined based on spherical linear interpolation.[2]