Stylianos Papaioannou sent me an email asking how to take the mean of several angles. These angles are actually phases derived from a Hilbert transform. So let’s say that you have a vector of angles x where the values are between 0 and 2pi. It’s not possible to take mean(x) as the mean of the angles, because this doesn’t take into account the circular nature of the data.
This type of problem is the subject of circular statistics. There’s an article in J. Statistical Software from Philipp Berens that covers this subject in the context of a Matlab toolbox called CircStat. Helpfully, Berens’ examples are taken from neuroscience.
The basic idea behind circular statistics is straightforward. To get a meaningful measure of centrality with angular data, you need to to transform the data into 2d vectors. Then these vectors can be averaged together, and then you can take the angle of the mean vector as the mean angle. For example, this will compute the mean angle of the angles x:
meanx = atan2(mean(sin(x)),mean(cos(x)));
It is also possible to derive a measure of spread from the length of the sum of these little vectors. The idea is that if you sum the vectors together and they are all pointing in the same direction (low variance), then the resulting vector will be quite long. However if the vectors are pointing in completely different directions (high variance), then the resulting vector will be much shorter then the sum of the lengths of the individual vectors. So the circular variance in the case above can be computed as:
varx = 1-sqrt(mean(sin(x)).^2 + mean(cos(x)).^2);
Here the variance is bounded between 0 and 1. Read the article for other case scenarios.