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_order (g10za)

## Purpose

nag_smooth_data_order (g10za) orders and weights data which is entered unsequentially, weighted or unweighted.

## Syntax

[nord, xord, yord, wtord, rss, ifail] = g10za(x, y, 'n', n, 'wt', wt)
[nord, xord, yord, wtord, rss, ifail] = nag_smooth_data_order(x, y, 'n', n, 'wt', wt)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 24: drop weight, wt optional
.

## Description

Given a set of observations (xi,yi)$\left({x}_{i},{y}_{i}\right)$, for i = 1,2,,n$i=1,2,\dots ,n$, with corresponding weights wi${w}_{i}$, nag_smooth_data_order (g10za) rearranges the observations so that the xi${x}_{i}$ are in ascending order.
For any equal xi${x}_{i}$ in the ordered set, say xj = xj + 1 = = xj + k${x}_{j}={x}_{j+1}=\cdots ={x}_{j+k}$, a single observation xj${x}_{j}$ is returned with a corresponding y${y}^{\prime }$ and w${w}^{\prime }$, calculated as
 k w′ = ∑ wi + l l = 0
$w′=∑l=0kwi+l$
and
 y′ = ( ∑ l = 0kwi + lyi + l)/(w′). $y′=∑l= 0kwi+lyi+l w′ .$
Observations with zero weight are ignored. If no weights are supplied by you, then unit weights are assumed; that is wi = 1${w}_{\mathit{i}}=1$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
In addition, the within group sum of squares is computed for the tied observations using West's algorithm (see West (1979)).

## References

Draper N R and Smith H (1985) Applied Regression Analysis (2nd Edition) Wiley
West D H D (1979) Updating mean and variance estimates: An improved method Comm. ACM 22 532–555

## Parameters

### Compulsory Input Parameters

1:     x(n) – double array
n, the dimension of the array, must satisfy the constraint n1${\mathbf{n}}\ge 1$.
The values, xi${x}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
2:     y(n) – double array
n, the dimension of the array, must satisfy the constraint n1${\mathbf{n}}\ge 1$.
The values yi${y}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the arrays x, y. (An error is raised if these dimensions are not equal.)
n$n$, the number of observations.
Constraint: n1${\mathbf{n}}\ge 1$.
2:     wt( : $:$) – double array
Note: the dimension of the array wt must be at least n${\mathbf{n}}$ if weight = 'W'$\mathit{weight}=\text{'W'}$.
If weight = 'W'$\mathit{weight}=\text{'W'}$, wt must contain the n$n$ weights. Otherwise wt is not referenced and unit weights are assumed.
Constraints:
• if weight = 'W'$\mathit{weight}=\text{'W'}$, wt(i) > 0.0${\mathbf{wt}}\left(\mathit{i}\right)>0.0$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$;
• if weight = 'W'$\mathit{weight}=\text{'W'}$, i = 1nwt(i) > 0${\sum }_{i=1}^{n}{\mathbf{wt}}\left(i\right)>0$.

weight iwrk

### Output Parameters

1:     nord – int64int32nag_int scalar
The number of distinct observations.
2:     xord(n) – double array
The first nord elements contain the ordered and distinct xi${x}_{i}$.
3:     yord(n) – double array
The first nord elements contain the values y${y}^{\prime }$ corresponding to the values in xord.
4:     wtord(n) – double array
The first nord elements contain the values w${w}^{\prime }$ corresponding to the values of xord and yord.
The within group sum of squares for tied observations.
6:     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, weight ≠ 'W'$\mathit{weight}\ne \text{'W'}$ or 'U'$\text{'U'}$, or n < 1${\mathbf{n}}<1$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, weight = 'W'$\mathit{weight}=\text{'W'}$ and at least one element of wt is < 0.0$\text{}<0.0$, or all elements of wt are 0.0$0.0$.

## Accuracy

For a discussion on the accuracy of the algorithm for computing mean and variance see West (1979).

nag_smooth_data_order (g10za) may be used to compute the pure error sum of squares in simple linear regression along with nag_correg_linregm_fit (g02da); see Draper and Smith (1985).

## Example

```function nag_smooth_data_order_example
x = [1;
3;
5;
5;
3;
4;
9;
6;
9;
9];
y = [4;
4;
1;
2;
5;
3;
4;
9;
7;
4];
[nord, xord, yord, wtord, rss, ifail] = nag_smooth_data_order(x, y)
```
```

nord =

6

xord =

1
3
4
5
6
9
6
9
9
9

yord =

4.0000
4.5000
3.0000
1.5000
9.0000
5.0000
9.0000
4.0000
7.0000
4.0000

wtord =

1
2
1
2
1
3
0
0
0
0

7

ifail =

0

```
```function g10za_example
x = [1;
3;
5;
5;
3;
4;
9;
6;
9;
9];
y = [4;
4;
1;
2;
5;
3;
4;
9;
7;
4];
[nord, xord, yord, wtord, rss, ifail] = g10za(x, y)
```
```

nord =

6

xord =

1
3
4
5
6
9
6
9
9
9

yord =

4.0000
4.5000
3.0000
1.5000
9.0000
5.0000
9.0000
4.0000
7.0000
4.0000

wtord =

1
2
1
2
1
3
0
0
0
0

7

ifail =

0

```