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)

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:
Mark 24: drop weight, wt optional
.

Description

Given a set of observations (xi,yi)(xi,yi), for i = 1,2,,ni=1,2,,n, with corresponding weights wiwi, nag_smooth_data_order (g10za) rearranges the observations so that the xixi are in ascending order.
For any equal xixi in the ordered set, say xj = xj + 1 = = xj + kxj=xj+1==xj+k, a single observation xjxj is returned with a corresponding yy and ww, calculated as
k
w = wi + l
l = 0
w=l=0kwi+l
and
y = (l = 0kwi + lyi + l)/(w).
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 = 1wi=1, for i = 1,2,,ni=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:     x(n) – double array
n, the dimension of the array, must satisfy the constraint n1n1.
The values, xixi, for i = 1,2,,ni=1,2,,n.
2:     y(n) – double array
n, the dimension of the array, must satisfy the constraint n1n1.
The values yiyi, for i = 1,2,,ni=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.)
nn, the number of observations.
Constraint: n1n1.
2:     wt( : :) – double array
Note: the dimension of the array wt must be at least nn if weight = 'W'weight='W'.
If weight = 'W'weight='W', wt must contain the nn weights. Otherwise wt is not referenced and unit weights are assumed.
Constraints:
  • if weight = 'W'weight='W', wt(i) > 0.0wti>0.0, for i = 1,2,,ni=1,2,,n;
  • if weight = 'W'weight='W', i = 1nwt(i) > 0i=1nwti>0.

Input Parameters Omitted from the MATLAB Interface

weight iwrk

Output Parameters

1:     nord – int64int32nag_int scalar
The number of distinct observations.
2:     xord(n) – double array
The first nord elements contain the ordered and distinct xixi.
3:     yord(n) – double array
The first nord elements contain the values yy corresponding to the values in xord.
4:     wtord(n) – double array
The first nord elements contain the values ww 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 = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,weight'W'weight'W' or 'U''U',
orn < 1n<1.
  ifail = 2ifail=2
On entry,weight = 'W'weight='W' and at least one element of wt is < 0.0<0.0, or all elements of wt are 0.00.0.

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

function nag_smooth_data_order_example
x = [1;
     3;
     5;
     5;
     3;
     4;
     9;
     6;
     9;
     9];
y = [4;
     4;
     1;
     2;
     5;
     3;
     4;
     9;
     7;
     4];
[nord, xord, yord, wtord, rss, ifail] = nag_smooth_data_order(x, y)
 

nord =

                    6


xord =

     1
     3
     4
     5
     6
     9
     6
     9
     9
     9


yord =

    4.0000
    4.5000
    3.0000
    1.5000
    9.0000
    5.0000
    9.0000
    4.0000
    7.0000
    4.0000


wtord =

     1
     2
     1
     2
     1
     3
     0
     0
     0
     0


rss =

     7


ifail =

                    0


function g10za_example
x = [1;
     3;
     5;
     5;
     3;
     4;
     9;
     6;
     9;
     9];
y = [4;
     4;
     1;
     2;
     5;
     3;
     4;
     9;
     7;
     4];
[nord, xord, yord, wtord, rss, ifail] = g10za(x, y)
 

nord =

                    6


xord =

     1
     3
     4
     5
     6
     9
     6
     9
     9
     9


yord =

    4.0000
    4.5000
    3.0000
    1.5000
    9.0000
    5.0000
    9.0000
    4.0000
    7.0000
    4.0000


wtord =

     1
     2
     1
     2
     1
     3
     0
     0
     0
     0


rss =

     7


ifail =

                    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–2013