FAQ
Hi Mike,

You should think of "vector" sums rather than arithmetic sum. So the mean
is really the direction of the resultant vector of all the unit vectors.
When two unit vectors are exactly opposing each other (as in your example
with angles 45 and 225 degrees), they cancel each other out and the
resultant vector has length zero, and hence the direction is arbitrary and
undefined. However, there are two issues which give rise to seemingly
anomalous results: (1) due to finite numerical precision in computing the
sines and cosines, exact cancellation does not happen, and (2) discontinuity
in atan function due to branch-point (0, 0) and a branch cut along negative
real axis.

For example,
[1] -56.30993247402022
sx
[1] -1.665334536937735e-16
cx
[1] 1.110223024625157e-16
atan(sx,cx) # this should really be 0
[1] -0.9827937232473291
>
If you now look at the resultant vector it has components (sin(-0.9828),
cos(-0.9828)) = (-0.83,0.55), which is completely wrong.

However, the above example is only a minor perturbation away from the
following (where the resultant vector is not zero):
[1] -59.49999999999996
which is perfectly alright.

Hope this helps,
Ravi.

--------------------------------------------------------------------------
Assistant Professor, The Center on Aging and Health
Division of Geriatric Medicine and Gerontology
Johns Hopkins University
Ph: (410) 502-2619
Fax: (410) 614-9625
--------------------------------------------------------------------------
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-
bounces at stat.math.ethz.ch] On Behalf Of Michael Peckford
Sent: Tuesday, June 28, 2005 1:35 PM
To: r-help at stat.math.ethz.ch
Subject: [R] Circular Mean Question

Hi, a question about the circular mean function in the package
CircStats:

Can anyone shed some light on why the circ mean function seems to make
sense for the first 2 set of bearings and then the mean of 225 and 45
degrees gives an unexpected 180 deg.
[1] 315.5

Can anyone explain this???

This problem was first detected when I was trying to take the circ
weighted means of my data:

With 2 groups of bearings:
x <- c(270,180)
y <- c(45,270)

the circular mean of these bearings gives:
[1] 257.2356

When finding the weighted means I get this:
deg(circ.weighted.mean(c(meanx,meany),c(2,2)))%%360
[1] 281.25

The function for weighted mean I am using:

circ.weighted.mean <- function (x,w)
{
sinr <- sum(w*sin(x))
cosr <- sum(w*cos(x))
circmean <- atan(sinr, cosr)
circmean
}

I am assuming that the problem that mention above is the cause of the
different mean bearings.

Am I missing something fundamental here?

Thanks,
Mike

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
guide.html

## Related Discussions

 view thread | post posts ‹ prev | 2 of 2 | next ›
Discussion Overview
 group r-help categories r posted Jun 28, '05 at 5:34p active Jun 28, '05 at 7:36p posts 2 users 2 website r-project.org irc #r

### 2 users in discussion

Content

People

Support

Translate

site design / logo © 2018 Grokbase