Hello, Once again, I posted a message without a subject line. Sorry.... here is the question again. Is there a simple way to modify the circ.mean function in the CircStats package to include a vector of weights to obtain a weighted average angle? Thanks! Martin -- Martin Biuw Sea Mammal Research Unit Gatty Marine Laboratory, University of St Andrews St Andrews, Fife KY16 8PA Scotland Ph: +44-(0)1334-462637 Fax: +44-(0)1334-462632 Web: http://smub.st.and.ac.uk
On Wed, 20 Aug 2003 19:37:59 +0100, Martin Biuw <emb7 at st-andrews.ac.uk> wrote :>Hello, >Is there a simple way to modify the circ.mean function in the CircStats >package to include a vector of weights to obtain a weighted average angle?This should do it: circ.weighted.mean <- function (x,w) { sinr <- sum(w*sin(x)) cosr <- sum(w*cos(x)) circmean <- atan(sinr, cosr) circmean } I was surprised that atan worked with 2 arguments; it's documented to use only 1. According to the docs, you're supposed to use atan2 if you want the two argument arctangent. Duncan Murdoch
Martin Biuw wrote:> Hello, > Once again, I posted a message without a subject line. Sorry.... here is > the question again. > > Is there a simple way to modify the circ.mean function in the CircStats > package to include a vector of weights to obtain a weighted average angle?Two comments: 1) > circ.mean function (x) { sinr <- sum(sin(x)) cosr <- sum(cos(x)) circmean <- atan(sinr, cosr) circmean } The function is not that hard to understand, so you might be able to answer your question yourself, don't you? 2) Please contact the author of a contributed package in order to submit a wishlist. He/she knows the functions much better and is the only one who can change things within the package, regularly. Uwe Ligges