hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_smooth_data_order (g10za)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_smooth_data_order (g10za) orders and weights data which is entered unsequentially, weighted or unweighted.

Syntax

[nord, xord, yord, wtord, rss, ifail] = g10za(x, y, 'n', n, 'wt', wt)
[nord, xord, yord, wtord, rss, ifail] = nag_smooth_data_order(x, y, 'n', n, 'wt', wt)
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 24: weight was removed from the interface; wt was made optional

Description

Given a set of observations xi,yi, for i=1,2,,n, with corresponding weights wi, nag_smooth_data_order (g10za) 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)).

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

Parameters

Compulsory Input Parameters

1:     xn – double array
The values, xi, for i=1,2,,n.
2:     yn – double array
The values yi, for i=1,2,,n.

Optional Input Parameters

1:     n int64int32nag_int scalar
Default: the dimension of the arrays x, y. (An error is raised if these dimensions are not equal.)
n, the number of observations.
Constraint: n1.
2:     wt: – double array
The dimension of the array wt must be at least n if weight='W'
If weight='W', wt must contain the n weights. Otherwise wt is not referenced and unit weights are assumed.
Constraints:
  • if weight='W', wti>0.0, for i=1,2,,n;
  • if weight='W', i=1nwti>0.

Output Parameters

1:     nord int64int32nag_int scalar
The number of distinct observations.
2:     xordn – double array
The first nord elements contain the ordered and distinct xi.
3:     yordn – double array
The first nord elements contain the values y corresponding to the values in xord.
4:     wtordn – double array
The first nord elements contain the values w corresponding to the values of xord and yord.
5:     rss – double scalar
The within group sum of squares for tied observations.
6:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
   ifail=1
On entry,weight'W' or 'U',
orn<1.
   ifail=2
On entry,weight='W' and at least one element of wt is <0.0, or all elements of wt are 0.0.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

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

Further Comments

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

Example

A set of unweighted observations are input and nag_smooth_data_order (g10za) used to produce a set of strictly increasing weighted observations.
function g10za_example


fprintf('g10za example results\n\n');

x = [1; 3; 5; 5; 3; 4; 9; 6; 9; 9];
y = [4; 4; 1; 2; 5; 3; 4; 9; 7; 4];

% Reorder data
[nord, xord, yord, wtord, rss, ifail] =  ...
  g10za(x, y);

% Display results
fprintf('Number of distinct observations = %7d\n', nord);
fprintf('Residual sum of squares         = %13.5f\n\n', rss);
fprintf('%16s%18s%19s\n', 'x', 'y', 'wt');
results = [xord(1:nord) yord(1:nord) wtord(1:nord)];
fprintf('%17.1f%18.1f%18.1f\n', results');


g10za example results

Number of distinct observations =       6
Residual sum of squares         =       7.00000

               x                 y                 wt
              1.0               4.0               1.0
              3.0               4.5               2.0
              4.0               3.0               1.0
              5.0               1.5               2.0
              6.0               9.0               1.0
              9.0               5.0               3.0

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015