PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_correg_linregs_const (g02ca)
Purpose
nag_correg_linregs_const (g02ca) performs a simple linear regression with dependent variable and independent variable .
Syntax
Description
nag_correg_linregs_const (g02ca) fits a straight line of the form
to the data points
such that
The function calculates the regression coefficient,
, the regression constant,
(and various other statistical quantities) by minimizing
The input data consist of the
pairs of observations
on the independent variable
and the dependent variable
.
The quantities calculated are:
(a) |
Means:
|
(b) |
Standard deviations:
|
(c) |
Pearson product-moment correlation coefficient:
|
(d) |
The regression coefficient, , and the regression constant,
:
|
(e) |
The sum of squares attributable to the regression, , the sum of squares of deviations about the regression, , and the total sum of squares, :
|
(f) |
The degrees of freedom attributable to the regression, , the degrees of freedom of deviations about the regression, , and the total degrees of freedom, :
|
(g) |
The mean square attributable to the regression, , and the mean square of deviations about the regression, :
|
(h) |
The value for the analysis of variance:
|
(i) |
The standard error of the regression coefficient, , and the standard error of the regression constant, :
|
(j) |
The value for the regression coefficient, , and the value for the regression constant, :
|
References
Draper N R and Smith H (1985) Applied Regression Analysis (2nd Edition) Wiley
Parameters
Compulsory Input Parameters
- 1:
– double array
-
must contain , for .
- 2:
– double array
-
must contain , for .
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the arrays
x,
y. (An error is raised if these dimensions are not equal.)
, the number of pairs of observations.
Constraint:
.
Output Parameters
- 1:
– double array
-
The following information:
| , the mean value of the independent variable, ; |
| , the mean value of the dependent variable, ; |
| the standard deviation of the independent variable, ; |
| the standard deviation of the dependent variable, ; |
| , the Pearson product-moment correlation between the independent variable and the dependent variable ; |
| , the regression coefficient; |
| , the regression constant; |
| , the standard error of the regression coefficient; |
| , the standard error of the regression constant; |
| , the value for the regression coefficient; |
| , the value for the regression constant; |
| , 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; |
| DFT, the total degrees of freedom. |
- 2:
– 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, | all n values of at least one of the variables and are identical. |
-
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
nag_correg_linregs_const (g02ca) does not use additional precision arithmetic for the accumulation of scalar products, so there may be a loss of significant figures for large .
If, in calculating
,
or
(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_linregs_const (g02ca) depends on .
The function uses a two-pass algorithm.
Example
This example reads in eight observations on each of two variables, and then performs a simple linear regression with the first variable as the independent variable, and the second variable as the dependent variable. Finally the results are printed.
Open in the MATLAB editor:
g02ca_example
function g02ca_example
fprintf('g02ca example results\n\n');
x = [ 1.0 0.0 4.0 7.5 2.5 0.0 10.0 5.0];
y = [20.0 15.5 28.3 45.0 24.5 10.0 99.0 31.2];
n = numel(x);
fprintf(' i independent(x) dependent(y)\n');
fprintf('%3d%14.4f%14.4f\n',[1:n; x; y]);
[result, ifail] = g02ca(x, y);
fprintf('\n');
fprintf('Mean of independent variable = %8.4f\n', result(1));
fprintf('Mean of dependent variable = %8.4f\n', result(2));
fprintf('Standard deviation of independent variable = %8.4f\n', result(3));
fprintf('Standard deviation of dependent variable = %8.4f\n', result(4));
fprintf('Correlation coefficient = %8.4f\n', result(5));
fprintf('\n');
fprintf('Regression coefficient = %8.4f\n', result(6));
fprintf('Standard error of coefficient = %8.4f\n', result(8));
fprintf('t-value for coefficient = %8.4f\n', result(10));
fprintf('\n');
fprintf('Regression constant = %8.4f\n', result(7));
fprintf('Standard error of constant = %8.4f\n', result(9));
fprintf('t-value for constant = %8.4f\n', result(11));
fprintf('\nAnalysis of regression table :-\n\n');
fprintf(' Source Sum of squares D.F. Mean square F-value\n');
fprintf('Due to regression %11.3f%8d%14.3f%14.3f\n', result(12:15));
fprintf('About regression %11.3f%8d%14.3f\n', result(16:18));
fprintf('Total %11.3f%8d\n', result(19:20));
g02ca example results
i independent(x) dependent(y)
1 1.0000 20.0000
2 0.0000 15.5000
3 4.0000 28.3000
4 7.5000 45.0000
5 2.5000 24.5000
6 0.0000 10.0000
7 10.0000 99.0000
8 5.0000 31.2000
Mean of independent variable = 3.7500
Mean of dependent variable = 34.1875
Standard deviation of independent variable = 3.6253
Standard deviation of dependent variable = 28.2604
Correlation coefficient = 0.9096
Regression coefficient = 7.0905
Standard error of coefficient = 1.3224
t-value for coefficient = 5.3620
Regression constant = 7.5982
Standard error of constant = 6.6858
t-value for constant = 1.1365
Analysis of regression table :-
Source Sum of squares D.F. Mean square F-value
Due to regression 4625.303 1 4625.303 28.751
About regression 965.245 6 160.874
Total 5590.549 7
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015