Weighted mean of angles
Weighted mean of angles
Work-related question:
I have a group of several closely spaced angles, and an uncertainty/accuracy estimate for each angle. I want to find the average of the angles, and I want the average weighted by the uncertainties. For most quantities it's just Sum(i/uncertainty(i))/Sum(1/uncertainty(i), but for angles the simple implementation breaks down around 0 degrees (1+359/2 = 180 != mean). Is there an elegant and strightforward way to calculate a weighted mean of a wrapped quantity?
My current hack fix is to subtract off the first angle from all of the angles before applying the formula, thus getting deltas hopefully between -180 and 180. Then after computing the average of the deltas, I add the base angle back on. This seems to work, but is there a better way?
I have a group of several closely spaced angles, and an uncertainty/accuracy estimate for each angle. I want to find the average of the angles, and I want the average weighted by the uncertainties. For most quantities it's just Sum(i/uncertainty(i))/Sum(1/uncertainty(i), but for angles the simple implementation breaks down around 0 degrees (1+359/2 = 180 != mean). Is there an elegant and strightforward way to calculate a weighted mean of a wrapped quantity?
My current hack fix is to subtract off the first angle from all of the angles before applying the formula, thus getting deltas hopefully between -180 and 180. Then after computing the average of the deltas, I add the base angle back on. This seems to work, but is there a better way?
I feel like I just beat a kitten to death... with a bag of puppies.
-
- Grand Pooh-Bah
- Posts: 6722
- Joined: Tue Sep 19, 2006 8:45 pm
- Location: Portland, OR
- Contact:
There will be a discontinuity at -90 or -180 or wherever you choose to push it back to. Making no assumptions about your dataset, the only robust way to do this is to perform vector addition.
If you can guarantee all your angles will be within a single quadrant or two adjacent quadrants, then you can make these simplifications.
If you can guarantee all your angles will be within a single quadrant or two adjacent quadrants, then you can make these simplifications.
So does that mean use unit vectors with the appropriate angles? That seems to work for the couple cases I just sketched. Still, I think I'll avoid doing that, since computing sinusoids is a lot more expensive than its probably worth.Dwindlehop wrote:Yes. You're not trying to average scalars, you're trying to average vectors. Treat your weighted angles like vectors and you won't have this problem.
Hmm, I'll need to play around to figure out why this works. Subtracting the first angle seemed obvious because the resulting angles were all plus or minus a couple degrees. Once I convince myself subtracting a constant works, I'll probably use it instead.Dwindlehop wrote:Subtracting 180 or 90 is cleaner than subtracting the first angle.
Yes, of course, all of the calculations are actually done in radians, but I find degrees easier to think about.Peijen wrote:PI?
While I rarely admit to remembering anything from physics, I do remember how to compute the uncertainty of a calculated value. However, this is a different problem. I'm trying to compute the most-likely mean angle by minimizing chi-squared.Jason wrote:Seriously though, don't you remember from physics lab, you can't just add uncertainties. I think you're supposed to take the square root of the sum of the squares of the uncertainties.
I feel like I just beat a kitten to death... with a bag of puppies.
-
- Grand Pooh-Bah
- Posts: 6722
- Joined: Tue Sep 19, 2006 8:45 pm
- Location: Portland, OR
- Contact:
By subtracting 180 or 90, what I really mean is force your values into the range [-90,270) or [-180,180). Move the discontinuity away from your angles.
Regarding sinusoids: premature optimization is the root of all evil.
Yes, unit vectors. Scaling them by your uncertainties is bonus.
2 has certain qualities, I have to admit.
Regarding sinusoids: premature optimization is the root of all evil.
Yes, unit vectors. Scaling them by your uncertainties is bonus.
2 has certain qualities, I have to admit.