This help topic is for R version 2.0.0. For the current version of R, try https://stat.ethz.ch/R-manual/R-patched/library/stats/html/runmed.html
runmed {stats}R Documentation

Running Medians – Robust Scatter Plot Smoothing

Description

Compute running medians of odd span. This is the “most robust” scatter plot smoothing possible. For efficiency (and historical reason), you can use one of two different algorithms giving identical results.

Usage

runmed(x, k, endrule = c("median", "keep", "constant"),
       algorithm = NULL, print.level = 0)

Arguments

x

numeric vector, the “dependent” variable to be smoothed.

k

integer width of median window; must be odd. Turlach had a default of k <- 1 + 2 * min((n-1)%/% 2, ceiling(0.1*n)). Use k = 3 for “minimal” robust smoothing eliminating isolated outliers.

endrule

character string indicating how the values at the beginning and the end (of the data) should be treated.

"keep"

keeps the first and last k_2 values at both ends, where k_2 is the half-bandwidth k2 = k %/% 2, i.e., y[j] = x[j] for j \in \{1,\ldots,k_2; n-k_2+1,\ldots,n\};

"constant"

copies median(y[1:k2]) to the first values and analogously for the last ones making the smoothed ends constant;

"median"

the default, smoothes the ends by using symmetrical medians of subsequently smaller bandwidth, but for the very first and last value where Tukey's robust end-point rule is applied, see smoothEnds.

algorithm

character string (partially matching "Turlach" or "Stuetzle") or the default NULL, specifying which algorithm should be applied. The default choice depends on n = length(x) and k where "Turlach" will be used for larger problems.

print.level

integer, indicating verboseness of algorithm; should rarely be changed by average users.

Details

Apart from the end values, the result y = runmed(x, k) simply has y[j] = median(x[(j-k2):(j+k2)]) (k = 2*k2+1), computed very efficiently.

The two algorithms are internally entirely different:

"Turlach"