# NAG CL Interfaceg10zac (data_​order)

Settings help

CL Name Style:

## 1Purpose

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

## 2Specification

 #include
 void g10zac (Integer n, const double x[], const double y[], const double weights[], Integer *nord, double xord[], double yord[], double wwt[], double *rss, NagError *fail)
The function may be called by the names: g10zac, nag_smooth_data_order or nag_order_data.

## 3Description

Given a set of observations $\left({x}_{i},{y}_{i}\right)$ for $i=1,2,\dots ,n$, with corresponding weights ${w}_{i}$, g10zac 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=0 k w i+l$
and
 $y ′ = ∑ l=0 k w i+l y i+l w ′ .$
Observations with zero weight are ignored. If no weights are supplied by you, then unit weights are assumed; that is ${w}_{i}=1$, for $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{n}$Integer Input
On entry: the number of observations, $n$.
Constraint: ${\mathbf{n}}\ge 1$.
2: $\mathbf{x}\left[{\mathbf{n}}\right]$const double Input
On entry: the values ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
3: $\mathbf{y}\left[{\mathbf{n}}\right]$const double Input
On entry: the values ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
4: $\mathbf{weights}\left[{\mathbf{n}}\right]$const double Input
On entry: weights must contain the $n$ weights, if they are required. Otherwise, weights must be set to NULL.
Constraints:
• if weights are required, then ${\mathbf{weights}}\left[\mathit{i}-1\right]\ge 0.0$, for $\mathit{i}=1,2,\dots ,n$;
• at least one ${\mathbf{weights}}\left[\mathit{i}-1\right]>0.0$, for some $\mathit{i}$.
5: $\mathbf{nord}$Integer * Output
On exit: the number of distinct observations.
6: $\mathbf{xord}\left[{\mathbf{n}}\right]$double Output
On exit: the first nord elements contain the ordered and distinct ${x}_{i}$.
7: $\mathbf{yord}\left[{\mathbf{n}}\right]$double Output
On exit: the first nord elements contain the values ${y}^{\prime }$ corresponding to the values in xord.
8: $\mathbf{wwt}\left[{\mathbf{n}}\right]$double Output
On exit: the first nord elements contain the values ${w}^{\prime }$ corresponding to the values of xord and yord.
9: $\mathbf{rss}$double * Output
On exit: the within group sum of squares for tied observations.
10: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
NE_ARRAY_CONS
The contents of array weights are not valid.
Constraint: at least one element of weights must be $>0$.
NE_INT_ARG_LT
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 1$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_REAL_ARRAY_CONS
On entry, ${\mathbf{weights}}\left[⟨\mathit{\text{value}}⟩\right]=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{weights}}\left[\mathit{i}\right]\ge 0$, for $\mathit{i}=0,1,\dots ,n-1$.

## 7Accuracy

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

## 8Parallelism and Performance

g10zac is not threaded in any implementation.

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

## 10Example

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

### 10.1Program Text

Program Text (g10zace.c)

### 10.2Program Data

Program Data (g10zace.d)

### 10.3Program Results

Program Results (g10zace.r)