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_correg_linregs_noconst (g02cb)

Purpose

nag_correg_linregs_noconst (g02cb) performs a simple linear regression with no constant, with dependent variable yy and independent variable xx.

Syntax

[result, ifail] = g02cb(x, y, 'n', n)
[result, ifail] = nag_correg_linregs_noconst(x, y, 'n', n)

Description

nag_correg_linregs_noconst (g02cb) fits a straight line of the form
y = bx
y=bx
to the data points
(x1,y1),(x2,y2),,(xn,yn) ,
(x1,y1),(x2,y2),,(xn,yn) ,
such that
yi = bxi + ei,  i = 1,2,,n(n2).
yi=bxi+ei,  i=1,2,,n(n2).
The function calculates the regression coefficient, bb, and the various other statistical quantities by minimizing
n
ei2.
i = 1
i=1nei2.
The input data consists of the nn pairs of observations (x1,y1),(x2,y2),,(xn,yn)(x1,y1),(x2,y2),,(xn,yn) on the independent variable xx and the dependent variable yy.
The quantities calculated are:
(a) Means:
n n
x = 1/nxi;  y = 1/nyi.
i = 1 i = 1
x-=1ni=1nxi;  y-=1ni=1nyi.
(b) Standard deviations:
sx = sqrt(1/(n 1)i = 1n(xix)2);   sy = sqrt(1/(n 1)i = 1n(yiy)2).
sx=1n- 1 i= 1n (xi-x-) 2;   sy=1n- 1 i= 1n (yi-y-) 2.
(c) Pearson product-moment correlation coefficient:
r = (i = 1n(xix)(yiy))/(sqrt(i = 1n(xix)2i = 1n(yiy)2)).
r=i=1n(xi-x-)(yi-y-) i=1n (xi-x-) 2i=1n (yi-y-) 2 .
(d) The regression coefficient, bb:
b = (i = 1nxiyi)/(i = 1nxi2).
b=i=1nxiyi i=1nxi2 .
(e) The sum of squares attributable to the regression, SSRSSR, the sum of squares of deviations about the regression, SSDSSD, and the total sum of squares, SSTSST:
n n
SST = yi2;  SSD = (yibxi)2,  SSR = SSTSSD.
i = 1 i = 1
SST=i=1nyi2;   SSD=i=1n (yi-bxi)2,   SSR=SST-SSD.
(f) The degrees of freedom attributable to the regression, DFRDFR, the degrees of freedom of deviations about the regression, DFDDFD, and the total degrees of freedom, DFTDFT:
DFT = n;  DFD = n1,  DFR = 1.
DFT=n;  DFD=n-1,  DFR=1.
(g) The mean square attributable to the regression, MSRMSR, and the mean square of deviations about the regression, MSD.MSD. 
MSR = SSR / DFR;  MSD = SSD / DFD.
MSR=SSR/DFR;  MSD=SSD/DFD.
(h) The FF value for the analysis of variance:
F = MSR / MSD.
F=MSR/MSD.
(i) The standard error of the regression coefficient:
se(b) = sqrt((MSD)/(i = 1nxi2)).
se(b)=MSD i= 1nxi2 .
(j) The tt value for the regression coefficient:
t(b) = b/(se(b)).
t(b)=bse(b) .

References

Draper N R and Smith H (1985) Applied Regression Analysis (2nd Edition) Wiley

Parameters

Compulsory Input Parameters

1:     x(n) – double array
n, the dimension of the array, must satisfy the constraint n2n2.
x(i)xi must contain xixi, for i = 1,2,,ni=1,2,,n.
2:     y(n) – double array
n, the dimension of the array, must satisfy the constraint n2n2.
y(i)yi must contain 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 pairs of observations.
Constraint: n2n2.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     result(2020) – double array
The following information:
result(1)result1 xx-, the mean value of the independent variable, xx;
result(2)result2 yy-, the mean value of the dependent variable, yy;
result(3)result3 sxsx, the standard deviation of the independent variable, xx;
result(4)result4 sysy, the standard deviation of the dependent variable, yy;
result(5)result5 rr, the Pearson product-moment correlation between the independent variable xx and the dependent variable yy;
result(6)result6 bb, the regression coefficient;
result(7)result7 the value 0.00.0;
result(8)result8 se(b)se(b), the standard error of the regression coefficient;
result(9)result9 the value 0.00.0;
result(10)result10 t(b)t(b), the tt value for the regression coefficient;
result(11)result11 the value 0.00.0;
result(12)result12 SSRSSR, the sum of squares attributable to the regression;
result(13)result13 DFRDFR, the degrees of freedom attributable to the regression;
result(14)result14 MSRMSR, the mean square attributable to the regression;
result(15)result15 FF, the FF value for the analysis of variance;
result(16)result16 SSDSSD, the sum of squares of deviations about the regression;
result(17)result17 DFDDFD, the degrees of freedom of deviations about the regression;
result(18)result18 MSDMSD, the mean square of deviations about the regression;
result(19)result19 SSTSST, the total sum of squares;
result(20)result20 DFTDFT, the total degrees of freedom.
2:     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,n < 2n<2.
  ifail = 2ifail=2
On entry,all n values of at least one of the variables xx and yy are identical.

Accuracy

nag_correg_linregs_noconst (g02cb) does not use additional precision arithmetic for the accumulation of scalar products, so there may be a loss of significant figures for large nn.
If, in calculating FF or t(b)t(b)  (see Section [Description]), the numbers involved are such that the result would be outside the range of numbers which can be stored by the machine, then the answer is set to the largest quantity which can be stored as a double variable, by means of a call to nag_machine_real_largest (x02al).

Further Comments

Computation time depends on nn.
nag_correg_linregs_noconst (g02cb) uses a two-pass algorithm.

Example

function nag_correg_linregs_noconst_example
x = [1;
     0;
     4;
     7.5;
     2.5;
     0;
     10;
     5];
y = [20;
     15.5;
     28.3;
     45;
     24.5;
     10;
     99;
     31.2];
[result, ifail] = nag_correg_linregs_noconst(x, y)
 

result =

   1.0e+04 *

    0.0004
    0.0034
    0.0004
    0.0028
    0.0001
    0.0008
         0
    0.0001
         0
    0.0009
         0
    1.3768
    0.0001
    1.3768
    0.0082
    0.1173
    0.0007
    0.0168
    1.4941
    0.0008


ifail =

                    0


function g02cb_example
x = [1;
     0;
     4;
     7.5;
     2.5;
     0;
     10;
     5];
y = [20;
     15.5;
     28.3;
     45;
     24.5;
     10;
     99;
     31.2];
[result, ifail] = g02cb(x, y)
 

result =

   1.0e+04 *

    0.0004
    0.0034
    0.0004
    0.0028
    0.0001
    0.0008
         0
    0.0001
         0
    0.0009
         0
    1.3768
    0.0001
    1.3768
    0.0082
    0.1173
    0.0007
    0.0168
    1.4941
    0.0008


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