g10 Chapter Contents
g10 Chapter Introduction
NAG C Library Manual

NAG Library Function Documentnag_order_data (g10zac)

1  Purpose

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

2  Specification

 #include #include
 void nag_order_data (Integer n, const double x[], const double y[], const double weights[], Integer *nord, double xord[], double yord[], double wwt[], double *rss, NagError *fail)

3  Description

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

4  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

5  Arguments

1:     nIntegerInput
On entry: the number of observations, $n$.
Constraint: ${\mathbf{n}}\ge 1$.
2:     x[n]const doubleInput
On entry: the values ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
3:     y[n]const doubleInput
On entry: the values ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
4:     weights[n]const doubleInput
On entry: weights must contain the $n$ weights, if they are required. Otherwise, weights must be set to the null pointer (double *)0.
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:     nordInteger *Output
On exit: the number of distinct observations.
6:     xord[n]doubleOutput
On exit: the first nord elements contain the ordered and distinct ${x}_{i}$.
7:     yord[n]doubleOutput
On exit: the first nord elements contain the values ${y}^{\prime }$ corresponding to the values in xord.
8:     wwt[n]doubleOutput
On exit: the first nord elements contain the values ${w}^{\prime }$ corresponding to the values of xord and yord.
On exit: the within group sum of squares for tied observations.
10:   failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

6  Error 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$.

7  Accuracy

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

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

9  Example

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

9.1  Program Text

Program Text (g10zace.c)

9.2  Program Data

Program Data (g10zace.d)

9.3  Program Results

Program Results (g10zace.r)