Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_smooth_data_runningmedian (g10ca)

## Purpose

nag_smooth_data_runningmedian (g10ca) computes a smoothed data sequence using running median smoothers.

## Syntax

[smooth, rough, ifail] = g10ca(itype, y, 'n', n)
[smooth, rough, ifail] = nag_smooth_data_runningmedian(itype, y, 'n', n)

## Description

Given a sequence of n$n$ observations recorded at equally spaced intervals, nag_smooth_data_runningmedian (g10ca) 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. $Data=Smooth+Rough.$
The two smoothers are:
1. 4253H,twice consisting of a running median of 4$4$, then 2$2$, then 5$5$, then 3$3$ followed by hanning. Hanning is a running weighted average, the weights being 1 / 4$1/4$, 1 / 2$1/2$ and 1 / 4$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$3$, two splitting operations named S to improve the smooth sequence, each of which is followed by a running median of 3$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.

## 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

## Parameters

### Compulsory Input Parameters

1:     itype – int64int32nag_int scalar
Specifies the method to be used.
• If itype = 0${\mathbf{itype}}=0$, 4253H,twice is used.
• If itype = 1${\mathbf{itype}}=1$, 3RSSH,twice is used.
Constraint: itype = 0${\mathbf{itype}}=0$ or 1$1$.
2:     y(n) – double array
n, the dimension of the array, must satisfy the constraint n > 6${\mathbf{n}}>6$.
The sample observations.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the array y.
n$n$, the number of observations.
Constraint: n > 6${\mathbf{n}}>6$.

None.

### Output Parameters

1:     smooth(n) – double array
Contains the smooth.
2:     rough(n) – double array
Contains the rough.
3:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
 On entry, itype < 0${\mathbf{itype}}<0$, or itype > 1${\mathbf{itype}}>1$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, n ≤ 6${\mathbf{n}}\le 6$.

## Accuracy

Not applicable.

Alternative methods of smoothing include the use of splines; see nag_smooth_fit_spline (g10ab) and nag_smooth_fit_spline_parest (g10ac).

## Example

```function nag_smooth_data_runningmedian_example
itype = int64(1);
y = [569;
416;
422;
565;
484;
520;
573;
518;
501;
505;
468;
382;
310;
334;
359;
372;
439;
446;
349;
395;
461;
511;
583;
590;
620;
578;
534;
631;
600;
438;
516;
534;
467;
457;
392;
467;
500;
493;
410;
412;
416;
403;
422;
459;
467;
512;
534;
552;
545];
[smooth, rough, ifail] = nag_smooth_data_runningmedian(itype, y)
```
```

smooth =

416.0000
416.0000
431.5000
473.0000
509.5000
520.6875
521.5625
518.0000
510.0000
496.5000
455.2500
387.5000
339.7500
334.9375
353.9375
376.1250
392.2500
396.2500
403.0000
427.2500
461.3750
513.3125
567.5625
590.0000
593.5000
595.2500
590.9375
566.8125
531.5000
516.0000
516.0000
501.8750
473.6250
457.0000
452.0000
440.1250
421.3750
412.0000
412.0000
412.0000
411.0625
410.6875
422.0000
446.6250
476.3750
509.0000
534.0000
545.0000
547.7500

rough =

153.0000
0
-9.5000
92.0000
-25.5000
-0.6875
51.4375
0
-9.0000
8.5000
12.7500
-5.5000
-29.7500
-0.9375
5.0625
-4.1250
46.7500
49.7500
-54.0000
-32.2500
-0.3750
-2.3125
15.4375
0
26.5000
-17.2500
-56.9375
64.1875
68.5000
-78.0000
0
32.1250
-6.6250
0
-60.0000
26.8750
78.6250
81.0000
-2.0000
0
4.9375
-7.6875
0
12.3750
-9.3750
3.0000
0
7.0000
-2.7500

ifail =

0

```
```function g10ca_example
itype = int64(1);
y = [569;
416;
422;
565;
484;
520;
573;
518;
501;
505;
468;
382;
310;
334;
359;
372;
439;
446;
349;
395;
461;
511;
583;
590;
620;
578;
534;
631;
600;
438;
516;
534;
467;
457;
392;
467;
500;
493;
410;
412;
416;
403;
422;
459;
467;
512;
534;
552;
545];
[smooth, rough, ifail] = g10ca(itype, y)
```
```

smooth =

416.0000
416.0000
431.5000
473.0000
509.5000
520.6875
521.5625
518.0000
510.0000
496.5000
455.2500
387.5000
339.7500
334.9375
353.9375
376.1250
392.2500
396.2500
403.0000
427.2500
461.3750
513.3125
567.5625
590.0000
593.5000
595.2500
590.9375
566.8125
531.5000
516.0000
516.0000
501.8750
473.6250
457.0000
452.0000
440.1250
421.3750
412.0000
412.0000
412.0000
411.0625
410.6875
422.0000
446.6250
476.3750
509.0000
534.0000
545.0000
547.7500

rough =

153.0000
0
-9.5000
92.0000
-25.5000
-0.6875
51.4375
0
-9.0000
8.5000
12.7500
-5.5000
-29.7500
-0.9375
5.0625
-4.1250
46.7500
49.7500
-54.0000
-32.2500
-0.3750
-2.3125
15.4375
0
26.5000
-17.2500
-56.9375
64.1875
68.5000
-78.0000
0
32.1250
-6.6250
0
-60.0000
26.8750
78.6250
81.0000
-2.0000
0
4.9375
-7.6875
0
12.3750
-9.3750
3.0000
0
7.0000
-2.7500

ifail =

0

```