# NAG FL Interfaceg10caf (data_​runningmedian)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

g10caf computes a smoothed data sequence using running median smoothers.

## 2Specification

Fortran Interface
 Subroutine g10caf ( n, y,
 Integer, Intent (In) :: itype, n Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: y(n) Real (Kind=nag_wp), Intent (Out) :: smooth(n), rough(n)
#include <nag.h>
 void g10caf_ (const Integer *itype, const Integer *n, const double y[], double smooth[], double rough[], Integer *ifail)
The routine may be called by the names g10caf or nagf_smooth_data_runningmedian.

## 3Description

Given a sequence of $n$ observations recorded at equally spaced intervals, g10caf fits a smooth curve through the data using one of two smoothers. The two smoothers are based on the use of running medians and averages to summarise overlapping segments. The fit and the residuals are called the smooth and the rough respectively. They obey the following:
 $Data=Smooth+Rough.$
The two smoothers are:
1. 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. 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.
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

## 5Arguments

1: $\mathbf{itype}$Integer Input
On entry: specifies the method to be used.
• If ${\mathbf{itype}}=0$, 4253H,twice is used.
• If ${\mathbf{itype}}=1$, 3RSSH,twice is used.
Constraint: ${\mathbf{itype}}=0$ or $1$.
2: $\mathbf{n}$Integer Input
On entry: $n$, the number of observations.
Constraint: ${\mathbf{n}}>6$.
3: $\mathbf{y}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the sample observations.
4: $\mathbf{smooth}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: contains the smooth.
5: $\mathbf{rough}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: contains the rough.
6: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{itype}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{itype}}=0$ or $1$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}>6$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

Not applicable.

## 8Parallelism and Performance

g10caf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

Alternative methods of smoothing include the use of splines; see g10abf and g10acf.

## 10Example

This example reads in a sequence of $49$ observations on bituminous coal production (in millions of net tons per year) in the USA., 1920–1968 and is taken from Tukey (1977). For comparison purposes, both smoothers are applied to the data and the results are printed.

### 10.1Program Text

Program Text (g10cafe.f90)

### 10.2Program Data

Program Data (g10cafe.d)

### 10.3Program Results

Program Results (g10cafe.r)