nag_order_data (g10zac) (PDF version)
g10 Chapter Contents
g10 Chapter Introduction
NAG Library Manual

NAG Library Function Document

nag_order_data (g10zac)

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

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

2  Specification

#include <nag.h>
#include <nagg10.h>
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 x i , y i  for i = 1 , 2 , , 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 = = x j+k , a single observation x j  is returned with a corresponding y  and w , 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 , , 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:     n IntegerInput
On entry: the number of observations, n .
Constraint: n1 .
2:     x[n] const doubleInput
On entry: the values x i , for i=1,2,,n.
3:     y[n] const doubleInput
On entry: the values y i , for i=1,2,,n.
4:     weights[n] const doubleInput
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 weights[i-1] 0.0 , for i=1,2,,n;
  • at least one weights[i-1] > 0.0 , for some i .
5:     nord Integer *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  corresponding to the values in xord.
8:     wwt[n] doubleOutput
On exit: the first nord elements contain the values w  corresponding to the values of xord and yord.
9:     rss double *Output
On exit: the within group sum of squares for tied observations.
10:   fail NagError *Input/Output
The NAG error argument (see Section 2.7 in How to Use the NAG Library and its Documentation).

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, n=value.
Constraint: n1.
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, weights[value] = value.
Constraint: weights[i] 0 , for i=0,1,,n - 1.

7  Accuracy

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

8  Parallelism and Performance

nag_order_data (g10zac) is not threaded in any implementation.

9  Further Comments

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).

10  Example

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

10.1  Program Text

Program Text (g10zace.c)

10.2  Program Data

Program Data (g10zace.d)

10.3  Program Results

Program Results (g10zace.r)


nag_order_data (g10zac) (PDF version)
g10 Chapter Contents
g10 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2016