Skip to content
Prev 28576 / 63468 Next

median methods

Brian. The example I have in mind is for functional data where there
are several ways to define a median. For example, it can be defined as
the pointwise median of a set of functions {f_j(x); j=1,...,n}. Or it
can be defined as m(x) = arg min_{g(x)} \sum_j |g(x) - f_j(x)| dx. The
latter can be calculated using several different algorithms, one of
which is the Hossjer-Croux algorithm.  So I want to write a function
of the form

median.fd <- function(x, method=c("hossjer-croux","pointwise"))

where x is of class "fd" (functional data). Without a ... argument in
the generic median function, I can't do this.

There are no doubt other similar examples where an additional argument
(or more) is required.

Furthermore, this would make it consistent with mean() and quantile().

You can easily retain existing code by defining generic median as
median(x,...). Then if an na.rm argument is passed without name, it
will go through to median.default(x,na.rm) without a hitch.  It should
not affect existing methods since they must all have na.rm as a second
argument also.

So I am suggesting median(x, ...) which makes it more flexible for
method writers, and I don't think it causes a problem for existing
code.

Best wishes,
Rob
On 27/04/2008, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote: