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_noconst (g02ch)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

nag_correg_linregm_coeffs_noconst (g02ch) performs a multiple linear regression with no constant on a set of variables whose sums of squares and cross-products about zero and correlation-like coefficients are given.

Syntax

[result, coef, rznv, cz, ifail] = g02ch(n, sspz, rz, 'k1', k1)
[result, coef, rznv, cz, ifail] = nag_correg_linregm_coeffs_noconst(n, sspz, rz, 'k1', k1)
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 23: k was removed from the interface

Description

nag_correg_linregm_coeffs_noconst (g02ch) fits a curve of the form
y=b1x1+b2x2++bkxk  
to the data points
x11,x21,,xk1,y1 x12,x22,,xk2,y2 x1n,x2n,,xkn,yn  
such that
yi=b1x1i+b2x2i++bkxki+ei,  i=1,2,,n.  
The function calculates the regression coefficients, b1,b2,,bk, (and various other statistical quantities) by minimizing
i=1nei2.  
The actual data values x1i,x2i,,xki,yi are not provided as input to the function. Instead, input to the function consists of:
(i) The number of cases, n, on which the regression is based.
(ii) The total number of variables, dependent and independent, in the regression, k+1.
(iii) The number of independent variables in the regression, k.
(iv) The k+1 by k+1 matrix S~ij of sums of squares and cross-products about zero of all the variables in the regression; the terms involving the dependent variable, y, appear in the k+1th row and column.
(v) The k+1 by k+1 matrix R~ij of correlation-like coefficients for all the variables in the regression; the correlations involving the dependent variable, y, appear in the k+1th row and column.
The quantities calculated are:
(a) The inverse of the k by k partition of the matrix of correlation-like coefficients, R~ij, involving only the independent variables. The inverse is obtained using an accurate method which assumes that this sub-matrix is positive definite (see Further Comments).
(b) The modified matrix, C=cij, where
cij=R~ijr~ijS~ij,  i,j=1,2,,k,  
where r~ij is the i,jth element of the inverse matrix of R~ij as described in (a) above. Each element of C is thus the corresponding element of the matrix of correlation-like 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 about zero.
(c) The regression coefficients:
bi=j=1kcijS~jk+1,  i=1,2,,k,  
where S~jk+1 is the sum of cross-products about zero for the independent variable xj and the dependent variable y.
(d) The sum of squares attributable to the regression, SSR, the sum of squares of deviations about the regression, SSD, and the total sum of squares, SST:
  • SST=S~k+1k+1, the sum of squares about zero for the dependent variable, y;
  • SSR=j=1kbjS~jk+1;  SSD=SST-SSR.
(e) The degrees of freedom attributable to the regression, DFR, the degrees of freedom of deviations about the regression, DFD, and the total degrees of freedom, DFT:
DFR=k;  DFD=n-k;  DFT=n.  
(f) The mean square attributable to the regression, MSR, and the mean square of deviations about the regression, MSD:
MSR=SSR/DFR;  MSD=SSD/DFD.  
(g) The F value for the analysis of variance:
F=MSR/MSD.  
(h) The standard error estimate:
s=MSD.  
(i) The coefficient of multiple correlation, R, the coefficient of multiple determination, R2, and the coefficient of multiple determination corrected for the degrees of freedom, R-2:
R=1-SSD SST ;  R2=1-SSD SST ;   R-2=1-SSD×DFT SST×DFD .  
(j) The standard error of the regression coefficients:
sebi=MSD×cii,   i= 1,2,,k.  
(k) The t values for the regression coefficients:
tbi=bi sebi ,  i=1,2,,k.  

References

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

Parameters

Compulsory Input Parameters

1:     n int64int32nag_int scalar
n, the number of cases used in calculating the sums of squares and cross-products and correlation-like coefficients.
2:     sspzldsspzk1 – double array
ldsspz, the first dimension of the array, must satisfy the constraint ldsspzk1.
sspzij must be set to S~ij, the sum of cross-products about zero for the ith and jth variables, for i=1,2,,k+1 and j=1,2,,k+1; terms involving the dependent variable appear in row k+1 and column k+1.
3:     rzldrzk1 – double array
ldrz, the first dimension of the array, must satisfy the constraint ldrzk1.
rzij must be set to R~ij, the correlation-like coefficient for the ith and jth variables, for i=1,2,,k+1 and j=1,2,,k+1; coefficients involving the dependent variable appear in row k+1 and column k+1.

Optional Input Parameters

1:     k1 int64int32nag_int scalar
Default: the first dimension of the arrays sspz, rz and the second dimension of the arrays sspz, rz. (An error is raised if these dimensions are not equal.)
The total number of variables, independent and dependent k+1, in the regression.
Constraint: 2k1n.

Output Parameters

1:     result13 – double array
The following information:
result1 SSR, the sum of squares attributable to the regression;
result2 DFR, the degrees of freedom attributable to the regression;
result3 MSR, the mean square attributable to the regression;
result4 F, the F value for the analysis of variance;
result5 SSD, the sum of squares of deviations about the regression;
result6 DFD, the degrees of freedom of deviations about the regression;
result7 MSD, the mean square of deviations about the regression;
result8 SST, the total sum of squares;
result9 DFT, the total degrees of freedom;
result10 s, the standard error estimate;
result11 R, the coefficient of multiple correlation;
result12 R2, the coefficient of multiple determination;
result13 R-2, the coefficient of multiple determination corrected for the degrees of freedom.
2:     coefldcoef3 – double array
For i=1,2,,k, the following information:
coefi1
bi, the regression coefficient for the ith variable.
coefi2
sebi, the standard error of the regression coefficient for the ith variable.
coefi3
tbi, the t value of the regression coefficient for the ith variable.
3:     rznvldrznvk – double array
k=k1-1.
The inverse of the matrix of correlation-like coefficients for the independent variables; that is, the inverse of the matrix consisting of the first k rows and columns of rz.
4:     czldczk – double array
k=k1-1.
The modified inverse matrix, C, where
czij=rzij×rznvij sspzij ,  i,j=1,2,,k.  
5:     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,k1<2.
   ifail=2
On entry,k1k+1.
   ifail=3
On entry,n<k1.
   ifail=4
On entry,ldsspz<k1,
orldrz<k1,
orldcoef<k,
orldrznv<k,
orldcz<k,
orldwkz<k.
   ifail=5
This indicates that the k by k partition of the matrix held in rz, which is to be inverted, is not positive definite.
   ifail=6
This indicates that the refinement following the actual inversion fails, indicating that the k by k partition of the matrix held in rz, which is to be inverted, is ill-conditioned. The use of nag_correg_linregm_fit (g02da), which employs a different numerical technique, may avoid the difficulty.
   ifail=7
   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

The accuracy of any regression function is almost entirely dependent on the accuracy of the matrix inversion method used. In nag_correg_linregm_coeffs_noconst (g02ch), it is the matrix of correlation-like coefficients rather than that of the sums of squares and cross-products about zero 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.
If, in calculating F or any of the tbi  (see 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_noconst (g02ch) depends on k.
This function assumes that the matrix of correlation-like 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-like matrix and the sums of squares and cross-products (about zero) 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-like 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 regressions 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 of 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_zero (g02bd), nag_correg_coeffs_zero_miss_case (g02be), nag_correg_coeffs_zero_subset (g02bk) or nag_correg_coeffs_zero_subset_miss_case (g02bl), 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 the function requires the dependent variable to be the last of the k+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 about zero, and correlation-like 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

This example reads in the sums of squares and cross-products about zero, and correlation-like coefficients for three variables. A multiple linear regression with no constant is then performed with the third and final variable as the dependent variable. Finally the results are printed.
function g02ch_example


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

n = int64(5);
k = 2;
sspz = [245,  99, 82;
         99, 271, 52;
         82,  52, 54];
rz   = [1,      0.3842, 0.7129;
        0.3842, 1,      0.4299;
        0.7129, 0.4299, 1     ];

disp('Sums of squares and cross-products about zero:');
disp(sspz);
disp('Correlation-like coefficients:');
disp(rz);

% Fit multiple linear regression model
[result, coeff, rzinv, cz, ifail] = ...
  g02ch(n, sspz, rz);

% Display results
fprintf('  Variable    Coef      Std err  t-value\n');
disp([[1:k]' coeff]);
  
fprintf('Analysis of regression table :-\n\n');
fprintf('      Source        Sum of squares  DF   Mean square   F-value\n');
fprintf('Due to regression %11.3f%8d%13.3f%12.3f\n', result(1:4));
fprintf('About  regression %11.3f%8d%13.3f\n', result(5:7));
fprintf('Total             %11.3f%8d\n\n', result(8:9));
fprintf('Standard error of estimate = %8.4f\n', result(10));
fprintf('Multiple correlation (R)   = %8.4f\n', result(11));
fprintf('Determination (R squared)  = %8.4f\n', result(12));
fprintf('Corrected R squared        = %8.4f\n\n', result(13));

disp('Inverse of correlation matrix of independent variables:');
disp(rzinv);
disp('Modified inverse matrix:');
disp(cz);


g02ch example results

Sums of squares and cross-products about zero:
   245    99    82
    99   271    52
    82    52    54

Correlation-like coefficients:
    1.0000    0.3842    0.7129
    0.3842    1.0000    0.4299
    0.7129    0.4299    1.0000

  Variable    Coef      Std err  t-value
    1.0000    0.3017    0.1998    1.5098
    2.0000    0.0817    0.1900    0.4299

Analysis of regression table :-

      Source        Sum of squares  DF   Mean square   F-value
Due to regression      28.986       2       14.493       1.738
About  regression      25.014       3        8.338
Total                  54.000       5

Standard error of estimate =   2.8876
Multiple correlation (R)   =   0.7326
Determination (R squared)  =   0.5368
Corrected R squared        =   0.2280

Inverse of correlation matrix of independent variables:
    1.1732   -0.4507
   -0.4507    1.1732

Modified inverse matrix:
    0.0048   -0.0017
   -0.0017    0.0043


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