NAG FL Interface
g10zaf (data_​order)

Settings help

FL Name Style:


FL Specification Language:


1 Purpose

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

2 Specification

Fortran Interface
Subroutine g10zaf ( weight, n, x, y, wt, nord, xord, yord, wtord, rss, iwrk, ifail)
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
C Header Interface
#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.

3 Description

Given a set of observations (xi,yi), for i=1,2,,n, with corresponding weights wi, g10zaf rearranges the observations so that the xi are in ascending order.
For any equal xi in the ordered set, say xj=xj+1==xj+k, a single observation xj is returned with a corresponding y and w, 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 wi=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: weight Character(1) Input
On entry: indicates whether user-defined weights are to be used.
  • If weight='W', user-defined weights are to be used and must be supplied in wt.
  • If weight='U', the data is treated as unweighted.
Constraint: weight='W' or 'U'.
2: n Integer Input
On entry: n, the number of observations.
Constraint: n1.
3: x(n) Real (Kind=nag_wp) array Input
On entry: the values, xi, for i=1,2,,n.
4: y(n) Real (Kind=nag_wp) array Input
On entry: the values yi, for i=1,2,,n.
5: wt(*) Real (Kind=nag_wp) array Input
Note: the dimension of the array wt must be at least n if weight='W'.
On entry: if weight='W', wt must contain the n weights. Otherwise wt is not referenced and unit weights are assumed.
Constraints:
  • if weight='W', wt(i)0.0, for i=1,2,,n;
  • if weight='W', i=1nwt(i)>0.
6: nord Integer Output
On exit: the number of distinct observations.
7: xord(n) Real (Kind=nag_wp) array Output
On exit: the first nord elements contain the ordered and distinct xi.
8: yord(n) Real (Kind=nag_wp) array Output
On exit: the first nord elements contain the values y corresponding to the values in xord.
9: wtord(n) Real (Kind=nag_wp) array Output
On exit: the first nord elements contain the values w corresponding to the values of xord and yord.
10: rss Real (Kind=nag_wp) Output
On exit: the within group sum of squares for tied observations.
11: iwrk(n) Integer array Workspace
12: ifail Integer Input/Output
On entry: ifail must be set to 0, −1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of −1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value −1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry 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:
ifail=1
On entry, n=value.
Constraint: n1.
On entry, weight=value.
Constraint: weight='W' or 'U'.
ifail=2
On entry, all weights are zero.
On entry, i=value and wt(i)=value.
Constraint: wt(i)0.0.
ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
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.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

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

8 Parallelism and Performance

g10zaf is not threaded in any implementation.

9 Further Comments

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

10 Example

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

10.1 Program Text

Program Text (g10zafe.f90)

10.2 Program Data

Program Data (g10zafe.d)

10.3 Program Results

Program Results (g10zafe.r)