Best way to average cyclical/repeating data (angle)

I hope I’m not missing something completely obvious. I have some data in the form of degree angles, so 360° = 0° I want the average (mean), and any variability in data is error, so data represent the same measurement. With much of it, it’s easy e.g. MEAN(45 50 61) = 52. But if I have (10 15 355) I’ll get 126.67, which is not representative. I can either add or subtract 360 before dividing (is one better?), which is closer to what I want. But at that point it becomes somewhat arbitrary as I’m just trying to get the numbers to be close to each other, but what if 355 were 310 or something and I have to make a value judgment? Also is there any automated way (e.g. Excel) to do this without double checking every equation?

What you’re discovering is that it’s just not appropriate to use an arithmetic average of the angles themselves. It can’t be. I mean, consider trying to average, say, 0 degrees, 90 degrees, 180 degrees, and 270 degrees. It’d be silly to pick any particular angle as their average, when the whole thing is symmetric under 90 degree rotation.

But you can average, say, the vectors these angles correspond to. So, for example, unit vectors oriented at 10, 15, and 355 degrees will average to a vector of magnitude about 0.99 at about 6.68 degrees.

(And that paradoxical case we considered before? Well, unit vectors uniformly distributed in angle would average to the zero vector, with no particular angle. As is only appropriate…)

Whether this technique is actually appropriate depends on why exactly you want these averages. But it certainly produces results which are “representative”, in a reasonable sense.

The way I would probably do this is to map each angle to its corresponding point on the unit circle (mapping the angle v to the point (cos v, sin v)), average those, and then find the angle corresponding to the averaged point using atan2(x,y). I don’t know much about Excel, though, so I can’t give too specific instructions. Make sure to convert your angles to/from radians, though. :slight_smile:

Of course as it happens, I spend a furious half hour googling, post this, and think of a better search term so I found some ideas. But help is appreciated. Would this work? (Excel):

Data = 5° and 355°, so final answer should be zero.

Use =COS(RADIANS(data) and =SIN(RADIANS(data) to get 2 x,y pairs. I’m not concerned with vector so assume r = 1, otherwise multiply by that
Average all x and y values separately (I think you can sum instead too?)

=DEGREES(ATAN2(xsum,ysum)) = 0°

I tried that with a bunch of data and it looks good, e.g. will average 50° and 60° as 55°. Sometimes I get a negative angle. It looks like that is relative to 0°, so if I get -160° I should assume (360+(-160)) = 200° ? And from what I know, I should use ATAN2 in preference to ATAN.

Yes, that looks right to me. :slight_smile:

Atan2 is better because it takes x and y as separate parameters. The way you’d use atan is to send it y/x as the parameter, except you’d have to make a bunch of special cases to handle x being zero, and to check the sign of x and y. Atan2 simply does those special cases for you. It returns angles in the interval -pi to pi, so yes, if you want positive angles, adding 360 degrees to any negative angles is the correct conversion.

Reference

Thanks a bunch guys! One last question, does this look right for SD/SEM/Variance/etc.?

Get atan2, convert to positive by adding 360 if needed.
Get the deviations of each original angle from the mean.
If statement (I think this is it?). For each deviation:
[ul]
[li]If the deviation is <-180, add 360[/li][li]If it’s >+180, subtract 360[/li][li]Otherwise leave it alone[/li][/ul]

Use the above to calculate SD doing whatever method. The calculated deviations are new scores used to find SD, and not the deviations needed to find sums of squares.
If N = 2 and I want to find sample (N - 1) statistics, then var max = 16200 and SD max = 127.28 (for illustration, real data has higher N of course).

It’s impossible to say whether that looks right without knowing why you want to do this.

If your data doesn’t wrap a full 360 degrees, you can redefine the angles so that your data falls over a continuous set of angles. If you don’t know that you have a gap, you’ll only be able to get an imperfect answer.

For example, if your data peaks near 150 degrees, and you’ve got data between 100 and 180, and also between -180 and -160, and a big gap with no data between -160 and +100, it would be reasonable to think the -180 to -160 data really belongs between 180 and 200. You can then get your mean and standard deviation.

If you have data everywhere, which peaks at +90, but still with data points near -90, you could break the data at -90, having it cover -90 to +270. But you wouldn’t know if some of the data near -90 should “really” be above 270, and vice-versa. Your mean might not be off by much, but your standard deviation would be underestimated.

This.

There is a clue in your title that suggests you are actually measuring phase angle, but without understanding the underlying needs there is no useful way of providing an answer.

This is what Wikipedia recommends.

Nothing complex and nothing to do with electricity or anything. Radius always = 1. Possible angles are 0 to 359. For simplicity’s sake, pretend that users are judging the direction is object is traveling. The speed and the trajectory are constant. Say that it is moving 30°. You might expect them to say 25, 30, 35, and so on degrees on a given trial (error). The SD there is 5. Say that instead a different trial was 353, 358, 3°. Getting the SD of that would be 203.53 and the mean 238 which is obviously wrong. It should be 5. I think I might have a way I just want to make sure that it will work in all situations/quadrant combinations.

ZenBeam, Ideally it doesn’t go 360° (within a single trial, others may be on the opposite side). Occasionally one point is way off. Your idea is intriguing, still trying to figure out how to do that here.

Normalise to the actual angle and average the errors in the estimates. If you want it back in the original space, just add back the actual angle to the average.

This is actually a pretty well-studied topic known as directional statistics. The method that Sofis recommended and that I endorsed is one of the standard measures of central tendency for that sort of data. If you’re using something else in place of that, you’d better have a good reason.

It really depends on the range of angles covered, and whether he truly needs the mean of the angles, or just something similar or close enough.

I was playing around comparing the given formula with just taking the mean of angles, for sets of angles found randomly over a uniform range of angles with the range centered at 0, and covering less than 360 degrees total. Taking the mean of the angles is well-defined, since there are no +/-180 degree discontinuities. I used samples with 200 points. I just ran a few cases, to see what typical errors I would get.

For a 100 degree range (so -50 to +50 degrees), the typical error in the mean given by the formula is up to about .1 to 0.25 degrees. For a 200 degree range, it’s up to 1 to 2 degrees. For a 300 degree range, the error got up to 15 degrees.

So if the OP has a small range, or if a few degrees of error don’t really matter, he can just use the formula since it’s simple to implement. But if he had a large range (which he said he didn’t), or if he really needs an accurate mean of the angles, he might need to find where the gap is. Of course, if there isn’t a clear gap, that formula might be the best he can do.