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

PDF version (NAG web site, 64-bit version, 64-bit version)
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:
 At Mark 24: weight was removed from the interface; wt was made optional

## Description

Given a set of observations $\left({x}_{i},{y}_{i}\right)$, for $i=1,2,\dots ,n$, with corresponding weights ${w}_{i}$, nag_smooth_data_order (g10za) rearranges the observations so that the ${x}_{i}$ are in ascending order.
For any equal ${x}_{i}$ in the ordered set, say ${x}_{j}={x}_{j+1}=\cdots ={x}_{j+k}$, a single observation ${x}_{j}$ is returned with a corresponding ${y}^{\prime }$ and ${w}^{\prime }$, calculated as
 $w′=∑l=0kwi+l$
and
 $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 ${w}_{\mathit{i}}=1$, for $\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:     $\mathrm{x}\left({\mathbf{n}}\right)$ – double array
The values, ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
2:     $\mathrm{y}\left({\mathbf{n}}\right)$ – double array
The values ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.

### Optional Input Parameters

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

### Output Parameters

1:     $\mathrm{nord}$int64int32nag_int scalar
The number of distinct observations.
2:     $\mathrm{xord}\left({\mathbf{n}}\right)$ – double array
The first nord elements contain the ordered and distinct ${x}_{i}$.
3:     $\mathrm{yord}\left({\mathbf{n}}\right)$ – double array
The first nord elements contain the values ${y}^{\prime }$ corresponding to the values in xord.
4:     $\mathrm{wtord}\left({\mathbf{n}}\right)$ – double array
The first nord elements contain the values ${w}^{\prime }$ corresponding to the values of xord and yord.
5:     $\mathrm{rss}$ – double scalar
The within group sum of squares for tied observations.
6:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{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:
${\mathbf{ifail}}=1$
 On entry, $\mathit{weight}\ne \text{'W'}$ or $\text{'U'}$, or ${\mathbf{n}}<1$.
${\mathbf{ifail}}=2$
 On entry, $\mathit{weight}=\text{'W'}$ and at least one element of wt is $\text{}<0.0$, or all elements of wt are $0.0$.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

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

A set of unweighted observations are input and nag_smooth_data_order (g10za) used to produce a set of strictly increasing weighted observations.
```function g10za_example

fprintf('g10za example results\n\n');

x = [1; 3; 5; 5; 3; 4; 9; 6; 9; 9];
y = [4; 4; 1; 2; 5; 3; 4; 9; 7; 4];

% Reorder data
[nord, xord, yord, wtord, rss, ifail] =  ...
g10za(x, y);

% Display results
fprintf('Number of distinct observations = %7d\n', nord);
fprintf('Residual sum of squares         = %13.5f\n\n', rss);
fprintf('%16s%18s%19s\n', 'x', 'y', 'wt');
results = [xord(1:nord) yord(1:nord) wtord(1:nord)];
fprintf('%17.1f%18.1f%18.1f\n', results');

```
```g10za example results

Number of distinct observations =       6
Residual sum of squares         =       7.00000

x                 y                 wt
1.0               4.0               1.0
3.0               4.5               2.0
4.0               3.0               1.0
5.0               1.5               2.0
6.0               9.0               1.0
9.0               5.0               3.0
```

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

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