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_linregm_coeffs_const (g02cg)

Purpose

nag_correg_linregm_coeffs_const (g02cg) performs a multiple linear regression on a set of variables whose means, sums of squares and cross-products of deviations from means, and Pearson product-moment correlation coefficients are given.

Syntax

[result, coef, con, rinv, c, ifail] = g02cg(n, xbar, ssp, r, 'k1', k1)
[result, coef, con, rinv, c, ifail] = nag_correg_linregm_coeffs_const(n, xbar, ssp, r, 'k1', k1)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 23: k dropped from interface
.

Description

nag_correg_linregm_coeffs_const (g02cg) fits a curve of the form
y = a + b1x1 + b2x2 + + bkxk
y=a+b1x1+b2x2++bkxk
to the data points
(x11,x21,,xk1,y1)
(x12,x22,,xk2,y2)
(x1n,x2n,,xkn,yn)
(x11,x21,,xk1,y1) (x12,x22,,xk2,y2) (x1n,x2n,,xkn,yn)
such that
yi = a + b1x1i + b2x2i + + bkxki + ei,  i = 1,2,,n.
yi=a+b1x1i+b2x2i++bkxki+ei,  i=1,2,,n.
The function calculates the regression coefficients, b1,b2,,bkb1,b2,,bk, the regression constant, aa, and various other statistical quantities by minimizing
n
ei2.
i = 1
i=1nei2.
The actual data values (x1i,x2i,,xki,yi)(x1i,x2i,,xki,yi) are not provided as input to the function. Instead, input consists of:
(i) The number of cases, nn, on which the regression is based.
(ii) The total number of variables, dependent and independent, in the regression, (k + 1)(k+1).
(iii) The number of independent variables in the regression, kk.
(iv) The means of all k + 1k+1 variables in the regression, both the independent variables (x1,x2,,xk)(x1,x2,,xk) and the dependent variable (y)(y), which is the (k + 1)(k+1)th variable: i.e., x1,x2,,xk,yx-1,x-2,,x-k,y-.
(v) The (k + 1)(k+1) by (k + 1)(k+1) matrix [SijSij] of sums of squares and cross-products of deviations from means of all the variables in the regression; the terms involving the dependent variable, yy, appear in the (k + 1)(k+1)th row and column.
(vi) The (k + 1)(k+1) by (k + 1)(k+1) matrix [RijRij] of the Pearson product-moment correlation coefficients for all the variables in the regression; the correlations involving the dependent variable, yy, appear in the (k + 1)(k+1)th row and column.
The quantities calculated are:
(a) The inverse of the kk by kk partition of the matrix of correlation coefficients, [RijRij], involving only the independent variables. The inverse is obtained using an accurate method which assumes that this sub-matrix is positive definite.
(b) The modified inverse matrix, C = [cij]C=[cij], where
cij = (Rijrij)/(Sij),  i,j = 1,2,,k,
cij=RijrijSij,  i,j=1,2,,k,
where rijrij is the (i,j)(i,j)th element of the inverse matrix of [RijRij] as described in (a) above. Each element of CC is thus the corresponding element of the matrix of correlation coefficients multiplied by the corresponding element of the inverse of this matrix, divided by the corresponding element of the matrix of sums of squares and cross-products of deviations from means.
(c) The regression coefficients:
k
bi = cijSj(k + 1),  i = 1,2,,k,
j = i
bi=j=ikcijSj(k+1),  i=1,2,,k,
where Sj(k + 1)Sj(k+1) is the sum of cross-products of deviations from means for the independent variable xjxj and the dependent variable yy.
(d) 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:
  • SST = S(k + 1)(k + 1)SST=S(k+1)(k+1), the sum of squares of deviations from the mean for the dependent variable, yy;
  • SSR = j = 1kbjSj(k + 1);  SSD = SSTSSRSSR=j=1kbjSj(k+1);  SSD=SST-SSR
(e) 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:
DFR = k;  DFD = nk1;  DFT = n1.
DFR=k;  DFD=n-k-1;  DFT=n-1.
(f) The mean square attributable to the regression, MSRMSR, and the mean square of deviations about the regression, MSDMSD:
MSR = SSR / DFR;  MSD = SSD / DFD.
MSR=SSR/DFR;  MSD=SSD/DFD.
(g) The FF values for the analysis of variance:
F = MSR / MSD.
F=MSR/MSD.
(h) The standard error estimate:
s = sqrt(MSD).
s=MSD.
(i) The coefficient of multiple correlation, RR, the coefficient of multiple determination, R2R2 and the coefficient of multiple determination corrected for the degrees of freedom, R2R-2;
R = sqrt(1(SSD)/(SST));  R2 = 1(SSD)/(SST);  R2 = 1(SSD × DFT)/(SST × DFD).
R=1-SSD SST ;  R2=1-SSD SST ;  R-2=1-SSD×DFT SST×DFD .
(j) The standard error of the regression coefficients:
se(bi) = sqrt(MSD × cii),   i = 1,2,,k.
se(bi)=MSD×cii,   i= 1,2,,k.
(k) The tt values for the regression coefficients:
t(bi) = (bi)/(se(bi)),  i = 1,2,,k.
t(bi)=bi se(bi) ,  i=1,2,,k.
(l) The regression constant, aa, its standard error, se(a)se(a), and its tt value, t(a)t(a):
k
a = ybixi;  se(a) = sqrt(MSD ×
( kk )
1/n + xicijxj
i = 1j = 1
)
;  t(a) = a/(se(a)).
i = 1
a=y--i=1kbix-i;  se(a)=MSD×(1n+i=1kj=1kx-icijx-j) ;  t(a)=ase(a) .

References

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

Parameters

Compulsory Input Parameters

1:     n – int64int32nag_int scalar
The number of cases nn, used in calculating the sums of squares and cross-products and correlation coefficients.
2:     xbar(k1) – double array
k1, the dimension of the array, must satisfy the constraint 2k1 < n2k1<n.
xbar(i)xbari must be set to xix-i, the mean value of the iith variable, for i = 1,2,,k + 1i=1,2,,k+1; the mean of the dependent variable must be contained in xbar(k + 1)xbark+1.
3:     ssp(ldssp,k1) – double array
ldssp, the first dimension of the array, must satisfy the constraint ldsspk1ldsspk1.
ssp(i,j)sspij must be set to SijSij, the sum of cross-products of deviations from means for the iith and jjth variables, for i = 1,2,,k + 1i=1,2,,k+1 and j = 1,2,,k + 1j=1,2,,k+1; terms involving the dependent variable appear in row k + 1k+1 and column k + 1k+1.
4:     r(ldr,k1) – double array
ldr, the first dimension of the array, must satisfy the constraint ldrk1ldrk1.
r(i,j)rij must be set to RijRij, the Pearson product-moment correlation coefficient for the iith and jjth variables, for i = 1,2,,k + 1i=1,2,,k+1 and j = 1,2,,k + 1j=1,2,,k+1; terms involving the dependent variable appear in row k + 1k+1 and column k + 1k+1.

Optional Input Parameters

1:     k1 – int64int32nag_int scalar
Default: The dimension of the array xbar and the first dimension of the arrays ssp, r and the second dimension of the arrays ssp, r. (An error is raised if these dimensions are not equal.)
The total number of variables, independent and dependent, (k + 1)(k+1), in the regression.
Constraint: 2k1 < n2k1<n.

Input Parameters Omitted from the MATLAB Interface

k ldssp ldr ldcoef ldrinv ldc wkz ldwkz

Output Parameters

1:     result(1313) – double array
The following information:
result(1)result1 SSRSSR, the sum of squares attributable to the regression;
result(2)result2 DFRDFR, the degrees of freedom attributable to the regression;
result(3)result3 MSRMSR, the mean square attributable to the regression;
result(4)result4 FF, the FF value for the analysis of variance;
result(5)result5 SSDSSD, the sum of squares of deviations about the regression;
result(6)result6 DFDDFD, the degrees of freedom of deviations about the regression;
result(7)result7 MSDMSD, the mean square of deviations about the regression;
result(8)result8 SSTSST, the total sum of squares;
result(9)result9 DFTDFT, the total degrees of freedom;
result(10)result10 ss, the standard error estimate;
result(11)result11 RR, the coefficient of multiple correlation;
result(12)result12 R2R2, the coefficient of multiple determination;
result(13)result13 R2R-2, the coefficient of multiple determination corrected for the degrees of freedom.
2:     coef(ldcoef,33) – double array
ldcoefkldcoefk.
For i = 1,2,,ki=1,2,,k, the following information:
coef(i,1)coefi1
bibi, the regression coefficient for the iith variable.
coef(i,2)coefi2
se(bi)se(bi), the standard error of the regression coefficient for the iith variable.
coef(i,3)coefi3
t(bi)t(bi), the tt value of the regression coefficient for the iith variable.
3:     con(33) – double array
The following information:
con(1)con1 aa, the regression constant;
con(2)con2 se(a)se(a), the standard error of the regression constant;
con(3)con3 t(a)t(a), the tt value for the regression constant.
4:     rinv(ldrinv,k) – double array
k = k11k=k1-1.
ldrinvkldrinvk.
The inverse of the matrix of correlation coefficients for the independent variables; that is, the inverse of the matrix consisting of the first kk rows and columns of r.
5:     c(ldc,k) – double array
k = k11k=k1-1.
ldckldck.
The modified inverse matrix, where
  • c(i,j) = r(i,j) × rinv(i,j) / ssp(i,j)cij=rij×rinvij/sspij, for i = 1,2,,ki=1,2,,k and j = 1,2,,kj=1,2,,k.
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,k1 < 2k1<2.
  ifail = 2ifail=2
On entry,k1(k + 1)k1(k+1).
  ifail = 3ifail=3
On entry,nk1nk1.
  ifail = 4ifail=4
On entry,ldssp < k1ldssp<k1,
orldr < k1ldr<k1,
orldcoef < kldcoef<k,
orldrinv < kldrinv<k,
orldc < kldc<k,
orldwkz < kldwkz<k.
  ifail = 5ifail=5
The kk by kk partition of the matrix RR which is to be inverted is not positive definite.
  ifail = 6ifail=6
The refinement following the actual inversion fails, indicating that the kk by kk partition of the matrix RR, which is to be inverted, is ill-conditioned. The use of nag_correg_linregm_fit (g02da), which employs a different numerical technique, may avoid this difficulty (an extra ‘variable’ representing the constant term must be introduced for nag_correg_linregm_fit (g02da)).
  ifail = 7ifail=7

Accuracy

The accuracy of any regression function is almost entirely dependent on the accuracy of the matrix inversion method used. In nag_correg_linregm_coeffs_const (g02cg), it is the matrix of correlation coefficients rather than that of the sums of squares and cross-products of deviations from means that is inverted; this means that all terms in the matrix for inversion are of a similar order, and reduces the scope for computational error. For details on absolute accuracy, the relevant section of the document describing the inversion function used, nag_linsys_real_posdef_solve_ref (f04ab), should be consulted. nag_correg_linregm_fit (g02da) uses a different method, based on nag_linsys_real_gen_lsqsol (f04am), and that function may well prove more reliable numerically. It does not handle missing values, nor does it provide the same output as this function. (In particular it is necessary to include explicitly the constant in the regression equation as another ‘variable’.)
If, in calculating FF, t(a)t(a), or any of the t(bi)t(bi)  (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

The time taken by nag_correg_linregm_coeffs_const (g02cg) depends on kk.
This function assumes that the matrix of correlation coefficients for the independent variables in the regression is positive definite; it fails if this is not the case.
This correlation matrix will in fact be positive definite whenever the correlation matrix and the sums of squares and cross-products (of deviations from means) matrix have been formed either without regard to missing values, or by eliminating completely any cases involving missing values, for any variable. If, however, these matrices are formed by eliminating cases with missing values from only those calculations involving the variables for which the values are missing, no such statement can be made, and the correlation matrix may or may not be positive definite. You should be aware of the possible dangers of using correlation matrices formed in this way (see the G02 Chapter Introduction), but if they nevertheless wish to carry out regression using such matrices, this function is capable of handling the inversion of such matrices provided they are positive definite.
If a matrix is positive definite, its subsequent re-organisation by either nag_correg_linregm_service_select (g02ce) or nag_correg_linregm_service_reorder (g02cf) will not affect this property, and the new matrix can safely be used in this function. Thus correlation matrices produced by any of nag_correg_coeffs_pearson (g02ba), nag_correg_coeffs_pearson_miss_case (g02bb), nag_correg_coeffs_pearson_subset (g02bg) or nag_correg_coeffs_pearson_subset_miss_case (g02bh), even if subsequently modified by either nag_correg_linregm_service_select (g02ce) or nag_correg_linregm_service_reorder (g02cf), can be handled by this function.
It should be noted that in forming the sums of squares and cross-products matrix and the correlation matrix a column of constants should not be added to the data as an additional ‘variable’ in order to obtain a constant term in the regression. This function automatically calculates the regression constant, aa, and any attempt to insert such a ‘dummy variable’ is likely to cause the function to fail.
It should also be noted that the function requires the dependent variable to be the last of the k + 1k+1 variables whose statistics are provided as input to the function. If this variable is not correctly positioned in the original data, the means, standard deviations, sums of squares and cross-products of deviations from means, and correlation coefficients can be manipulated by using nag_correg_linregm_service_select (g02ce) or nag_correg_linregm_service_reorder (g02cf) to reorder the variables as necessary.

Example

function nag_correg_linregm_coeffs_const_example
n = int64(5);
xbar = [5.4;
     5.8;
     2.8];
ssp = [99.2, -57.6, 6.4;
     -57.6, 102.8, -29.2;
     6.4, -29.2, 14.8];
r = [1, -0.5704, 0.167;
     -0.5704, 1, -0.7486;
     0.167, -0.7486, 1];
[result, coeff, con, rinv, c, ifail] = nag_correg_linregm_coeffs_const(n, xbar, ssp, r)
 

result =

    9.7769
    2.0000
    4.8884
    1.9464
    5.0231
    2.0000
    2.5116
   14.8000
    4.0000
    1.5848
    0.8128
    0.6606
    0.3212


coeff =

   -0.1488    0.1937   -0.7683
   -0.3674    0.1903   -1.9309


con =

    5.7350
    2.0327
    2.8213


rinv =

    1.4823    0.8455
    0.8455    1.4823


c =

    0.0149    0.0084
    0.0084    0.0144


ifail =

                    0


function g02cg_example
n = int64(5);
xbar = [5.4;
     5.8;
     2.8];
ssp = [99.2, -57.6, 6.4;
     -57.6, 102.8, -29.2;
     6.4, -29.2, 14.8];
r = [1, -0.5704, 0.167;
     -0.5704, 1, -0.7486;
     0.167, -0.7486, 1];
[result, coeff, con, rinv, c, ifail] = g02cg(n, xbar, ssp, r)
 

result =

    9.7769
    2.0000
    4.8884
    1.9464
    5.0231
    2.0000
    2.5116
   14.8000
    4.0000
    1.5848
    0.8128
    0.6606
    0.3212


coeff =

   -0.1488    0.1937   -0.7683
   -0.3674    0.1903   -1.9309


con =

    5.7350
    2.0327
    2.8213


rinv =

    1.4823    0.8455
    0.8455    1.4823


c =

    0.0149    0.0084
    0.0084    0.0144


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