# NAG FL Interfaceg10zaf (data_​order)

## 1Purpose

g10zaf orders and weights data which is entered unsequentially, weighted or unweighted.

## 2Specification

Fortran Interface
 Subroutine g10zaf ( n, x, y, wt, nord, xord, yord, rss, iwrk,
 Integer, Intent (In) :: n Integer, Intent (Inout) :: ifail Integer, Intent (Out) :: nord, iwrk(n) Real (Kind=nag_wp), Intent (In) :: x(n), y(n), wt(*) Real (Kind=nag_wp), Intent (Out) :: xord(n), yord(n), wtord(n), rss Character (1), Intent (In) :: weight
#include <nag.h>
 void g10zaf_ (const char *weight, const Integer *n, const double x[], const double y[], const double wt[], Integer *nord, double xord[], double yord[], double wtord[], double *rss, Integer iwrk[], Integer *ifail, const Charlen length_weight)
The routine may be called by the names g10zaf or nagf_smooth_data_order.

## 3Description

Given a set of observations $\left({x}_{i},{y}_{i}\right)$, for $i=1,2,\dots ,n$, with corresponding weights ${w}_{i}$, g10zaf 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)).

## 4References

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

## 5Arguments

1: $\mathbf{weight}$Character(1) Input
On entry: indicates whether user-defined weights are to be used.
• If ${\mathbf{weight}}=\text{'W'}$, user-defined weights are to be used and must be supplied in wt.
• If ${\mathbf{weight}}=\text{'U'}$, the data is treated as unweighted.
Constraint: ${\mathbf{weight}}=\text{'W'}$ or $\text{'U'}$.
2: $\mathbf{n}$Integer Input
On entry: $n$, the number of observations.
Constraint: ${\mathbf{n}}\ge 1$.
3: $\mathbf{x}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the values, ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
4: $\mathbf{y}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the values ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
5: $\mathbf{wt}\left(*\right)$Real (Kind=nag_wp) array Input
Note: the dimension of the array wt must be at least ${\mathbf{n}}$ if ${\mathbf{weight}}=\text{'W'}$.
On entry: if ${\mathbf{weight}}=\text{'W'}$, wt must contain the $n$ weights. Otherwise wt is not referenced and unit weights are assumed.
Constraints:
• if ${\mathbf{weight}}=\text{'W'}$, ${\mathbf{wt}}\left(\mathit{i}\right)\ge 0.0$, for $\mathit{i}=1,2,\dots ,n$;
• if ${\mathbf{weight}}=\text{'W'}$, ${\sum }_{i=1}^{n}{\mathbf{wt}}\left(i\right)>0$.
6: $\mathbf{nord}$Integer Output
On exit: the number of distinct observations.
7: $\mathbf{xord}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: the first nord elements contain the ordered and distinct ${x}_{i}$.
8: $\mathbf{yord}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: the first nord elements contain the values ${y}^{\prime }$ corresponding to the values in xord.
9: $\mathbf{wtord}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Output
On exit: the first nord elements contain the values ${w}^{\prime }$ corresponding to the values of xord and yord.
10: $\mathbf{rss}$Real (Kind=nag_wp) Output
On exit: the within group sum of squares for tied observations.
11: $\mathbf{iwrk}\left({\mathbf{n}}\right)$Integer array Workspace
12: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, . If you are unfamiliar with this argument you should refer to Section 4 in the Introduction to the NAG Library FL Interface 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 $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{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:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 1$.
On entry, ${\mathbf{weight}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{weight}}=\text{'W'}$ or $\text{'U'}$.
${\mathbf{ifail}}=2$
On entry, all weights are zero.
On entry, $i=〈\mathit{\text{value}}〉$ and ${\mathbf{wt}}\left(i\right)=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{wt}}\left(i\right)\ge 0.0$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

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

## 8Parallelism and Performance

g10zaf is not threaded in any implementation.

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

## 10Example

A set of unweighted observations are input and g10zaf used to produce a set of strictly increasing weighted observations.

### 10.1Program Text

Program Text (g10zafe.f90)

### 10.2Program Data

Program Data (g10zafe.d)

### 10.3Program Results

Program Results (g10zafe.r)