G10CAF (PDF version)
G10 Chapter Contents
G10 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G10CAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

G10CAF computes a smoothed data sequence using running median smoothers.

2  Specification

SUBROUTINE G10CAF ( ITYPE, N, Y, SMOOTH, ROUGH, IFAIL)
INTEGER  ITYPE, N, IFAIL
REAL (KIND=nag_wp)  Y(N), SMOOTH(N), ROUGH(N)

3  Description

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. 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  Parameters

1:     ITYPE – INTEGERInput
On entry: specifies the method to be used.
  • If ITYPE=0, 4253H,twice is used.
  • If ITYPE=1, 3RSSH,twice is used.
Constraint: ITYPE=0 or 1.
2:     N – INTEGERInput
On entry: n, the number of observations.
Constraint: N>6.
3:     YN – REAL (KIND=nag_wp) arrayInput
On entry: the sample observations.
4:     SMOOTHN – REAL (KIND=nag_wp) arrayOutput
On exit: contains the smooth.
5:     ROUGHN – REAL (KIND=nag_wp) arrayOutput
On exit: contains the rough.
6:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry 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:
IFAIL=1
On entry,ITYPE<0,
orITYPE>1.
IFAIL=2
On entry,N6.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

7  Accuracy

Not applicable.

8  Parallelism and Performance

G10CAF is not threaded by NAG in any implementation.
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.

9  Further Comments

Alternative methods of smoothing include the use of splines; see G10ABF and G10ACF.

10  Example

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.1  Program Text

Program Text (g10cafe.f90)

10.2  Program Data

Program Data (g10cafe.d)

10.3  Program Results

Program Results (g10cafe.r)

GnuplotProduced by GNUPLOT 4.6 patchlevel 3 300 350 400 450 500 550 600 650 0 5 10 15 20 25 30 35 40 45 50 y Observation Number Example Program Running Median Smoothers gnuplot_plot_1 Observed data gnuplot_plot_2 Smoothed using 3RSSH gnuplot_plot_3 Smoothed using 4253H

G10CAF (PDF version)
G10 Chapter Contents
G10 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2015