PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_correg_linregm_coeffs_noconst (g02ch)
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
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
to the data points
such that
The function calculates the regression coefficients,
, (and various other statistical quantities) by minimizing
The actual data values
are not provided as input to the function. Instead, input to the function consists of:
(i) |
The number of cases, , on which the regression is based. |
(ii) |
The total number of variables, dependent and independent, in the regression, . |
(iii) |
The number of independent variables in the regression, . |
(iv) |
The by matrix of sums of squares and cross-products about zero of all the variables in the regression; the terms involving the dependent variable, , appear in the th row and column. |
(v) |
The by matrix of correlation-like coefficients for all the variables in the regression; the correlations involving the dependent variable, , appear in the th row and column. |
The quantities calculated are:
(a) |
The inverse of the by partition of the matrix of correlation-like coefficients, , 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, , where
where is the th element of the inverse matrix of as described in (a) above. Each element of 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:
where is the sum of cross-products about zero for the independent variable and the dependent variable . |
(d) |
The sum of squares attributable to the regression, , the sum of squares of deviations about the regression, , and the total sum of squares, :
- , the sum of squares about zero for the dependent variable, ;
- .
|
(e) |
The degrees of freedom attributable to the regression, , the degrees of freedom of deviations about the regression, , and the total degrees of freedom, :
|
(f) |
The mean square attributable to the regression, , and the mean square of deviations about the regression, :
|
(g) |
The value for the analysis of variance:
|
(h) |
The standard error estimate:
|
(i) |
The coefficient of multiple correlation, , the coefficient of multiple determination, , and the coefficient of multiple determination corrected for the degrees of freedom, :
|
(j) |
The standard error of the regression coefficients:
|
(k) |
The values for the regression coefficients:
|
References
Draper N R and Smith H (1985) Applied Regression Analysis (2nd Edition) Wiley
Parameters
Compulsory Input Parameters
- 1:
– int64int32nag_int scalar
-
, the number of cases used in calculating the sums of squares and cross-products and correlation-like coefficients.
- 2:
– double array
-
ldsspz, the first dimension of the array, must satisfy the constraint
.
must be set to , the sum of cross-products about zero for the th and th variables, for and ; terms involving the dependent variable appear in row and column .
- 3:
– double array
-
ldrz, the first dimension of the array, must satisfy the constraint
.
must be set to , the correlation-like coefficient for the th and th variables, for and ; coefficients involving the dependent variable appear in row and column .
Optional Input Parameters
- 1:
– 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 , in the regression.
Constraint:
.
Output Parameters
- 1:
– double array
-
The following information:
| , the sum of squares attributable to the regression; |
| , the degrees of freedom attributable to the regression; |
| , the mean square attributable to the regression; |
| , the value for the analysis of variance; |
| , the sum of squares of deviations about the regression; |
| , the degrees of freedom of deviations about the regression; |
| , the mean square of deviations about the regression; |
| , the total sum of squares; |
| , the total degrees of freedom; |
| , the standard error estimate; |
| , the coefficient of multiple correlation; |
| , the coefficient of multiple determination; |
| , the coefficient of multiple determination corrected for the degrees of freedom. |
- 2:
– double array
-
For
, the following information:
- , the regression coefficient for the th variable.
- , the standard error of the regression coefficient for the th variable.
- , the value of the regression coefficient for the th variable.
- 3:
– double array
-
.
The inverse of the matrix of correlation-like coefficients for the independent variables; that is, the inverse of the matrix consisting of the first
rows and columns of
rz.
- 4:
– double array
-
.
The modified inverse matrix,
, where
- 5:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
-
-
-
-
-
-
On entry, | , |
or | , |
or | , |
or | , |
or | , |
or | . |
-
-
This indicates that the
by
partition of the matrix held in
rz, which is to be inverted, is not positive definite.
-
-
This indicates that the refinement following the actual inversion fails, indicating that the
by
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.
-
-
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
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
or any of the
(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 .
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.
It should be noted that the function requires the dependent variable to be the last of the
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.
Open in the MATLAB editor:
g02ch_example
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);
[result, coeff, rzinv, cz, ifail] = ...
g02ch(n, sspz, rz);
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)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015