NAG Library Routine Document
G10CAF computes a smoothed data sequence using running median smoothers.
||ITYPE, N, IFAIL
||Y(N), SMOOTH(N), ROUGH(N)
Given a sequence of
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:
The two smoothers are:
- 4253H,twice consisting of a running median of , then , then , then followed by hanning. Hanning is a running weighted average, the weights being , and . 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.
- 3RSSH,twice consisting of a running median of , two splitting operations named S to improve the smooth sequence, each of which is followed by a running median of , 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
- 1: ITYPE – INTEGERInput
: specifies the method to be used.
- If , 4253H,twice is used.
- If , 3RSSH,twice is used.
- 2: N – INTEGERInput
On entry: , the number of observations.
- 3: Y(N) – REAL (KIND=nag_wp) arrayInput
On entry: the sample observations.
- 4: SMOOTH(N) – REAL (KIND=nag_wp) arrayOutput
On exit: contains the smooth.
- 5: ROUGH(N) – REAL (KIND=nag_wp) arrayOutput
On exit: contains the rough.
- 6: IFAIL – INTEGERInput/Output
must be set to
. 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
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
. When the value is used it is essential to test the value of IFAIL on exit.
unless the routine detects an error or a warning has been flagged (see Section 6
6 Error Indicators and Warnings
If on entry
, explanatory error messages are output on the current error message unit (as defined by X04AAF
Errors or warnings detected by the routine:
Alternative methods of smoothing include the use of splines; see G10ABF
This example reads in a sequence of
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.
9.1 Program Text
Program Text (g10cafe.f90)
9.2 Program Data
Program Data (g10cafe.d)
9.3 Program Results
Program Results (g10cafe.r)