nag_running_median_smoother (g10cac) (PDF version)
g10 Chapter Contents
g10 Chapter Introduction
NAG Library Manual

NAG Library Function Documentnag_running_median_smoother (g10cac)

1  Purpose

nag_running_median_smoother (g10cac) computes a smoothed data sequence using running median smoothers.

2  Specification

 #include #include
 void nag_running_median_smoother (Nag_Smooth_Type smoother, Integer n, const double y[], double smooth[], double rough[], NagError *fail)

3  Description

Given a sequence of $n$ observations recorded at equally spaced intervals, nag_running_median_smoother (g10cac) fits a smooth curve through the data using one of two smoothers. They are based on the use of running medians and averages to summarise the overlapping segments. The fit is called the smooth, the residuals the rough and they obey the following:
Data = Smooth + Rough
The two smoothers are :
 1 4253H, twice consisting of a running median of 4, then 2, then 5, then 3 followed by Hanning. Hanning is a running weighted average, the weights being 1/4, 1/2 and 1/4. The result of this smoothing is then reroughed by computing residuals, applying the same smoother to them and adding the result to the smooth of the first pass. 2 3RSSH, twice consisting of a running median of 3, two splitting operations named S to improve the smooth sequence, each of which is followed by a running median of 3, and finally Hanning. The end points are dealt with using the method described by Velleman and Hoaglin (1981). The full smoother 3RSSH, twice is produced by reroughing as described above.
The compound smoother 4253H, twice is recommended. The smoother 3RSSH, twice is popular when calculating by hand as it requires simpler computations and is included for comparison purposes.

4  References

Tukey J W (1977) Exploratory Data Analysis Addison–Wesley
Velleman P F and Hoaglin D C (1981) Applications, Basics, and Computing of Exploratory Data Analysis Duxbury Press, Boston, MA

5  Arguments

1:    $\mathbf{smoother}$Nag_Smooth_TypeInput
On entry: smoother must specify the method to be used.
${\mathbf{smoother}}=\mathrm{Nag_4253H}$
4253H, twice is used.
${\mathbf{smoother}}=\mathrm{Nag_3RSSH}$
3RSSH, twice is used.
Constraint: ${\mathbf{smoother}}=\mathrm{Nag_4253H}$ or $\mathrm{Nag_3RSSH}$.
2:    $\mathbf{n}$IntegerInput
On entry: the number, $n$, of the observations.
Constraint: ${\mathbf{n}}>6$.
If ${\mathbf{n}}\le 6$ then the sequence is not long enough to carry out smoothing.
3:    $\mathbf{y}\left[{\mathbf{n}}\right]$const doubleInput
On entry: the sample observations.
4:    $\mathbf{smooth}\left[{\mathbf{n}}\right]$doubleOutput
On exit: contains the smooth.
5:    $\mathbf{rough}\left[{\mathbf{n}}\right]$doubleOutput
On exit: contains the rough.
6:    $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error Indicators and Warnings

NE_BAD_PARAM
On entry, argument smoother had an illegal value.
NE_INT_ARG_LE
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}>6$.

Not applicable.

Not applicable.

9  Further Comments

Internal changes have been made to this function as follows:
• At Mark 25: nag_running_median_smoother (g10cac) is a smoothing function with two possible smoothing methods. The function was previously using the incorrect method (i.e., if you asked for method A you would get method B, and vice versa).

10  Example

The example program reads in a sequence of 49 data taken from Tukey (1977), above. Results are obtained using the two smoothing methods described.

10.1  Program Text

Program Text (g10cace.c)

10.2  Program Data

Program Data (g10cace.d)

10.3  Program Results

Program Results (g10cace.r)

nag_running_median_smoother (g10cac) (PDF version)
g10 Chapter Contents
g10 Chapter Introduction
NAG Library Manual