g02ca performs a simple linear regression with dependent variable and independent variable .
Syntax
C# |
---|
public static void g02ca( int n, double[] x, double[] y, double[] result, out int ifail ) |
Visual Basic |
---|
Public Shared Sub g02ca ( _ n As Integer, _ x As Double(), _ y As Double(), _ result As Double(), _ <OutAttribute> ByRef ifail As Integer _ ) |
Visual C++ |
---|
public: static void g02ca( int n, array<double>^ x, array<double>^ y, array<double>^ result, [OutAttribute] int% ifail ) |
F# |
---|
static member g02ca : n : int * x : float[] * y : float[] * result : float[] * ifail : int byref -> unit |
Parameters
- n
- Type: System..::..Int32On entry: , the number of pairs of observations.Constraint: .
- x
- Type: array<System..::..Double>[]()[][]An array of size [n]On entry: must contain , for .
- y
- Type: array<System..::..Double>[]()[][]An array of size [n]On entry: must contain , for .
- result
- Type: array<System..::..Double>[]()[][]An array of size []On exit: 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.
- ifail
- Type: System..::..Int32%On exit: unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).
Description
g02ca fits a straight line of the form
to the data points
such that
The method 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
Error Indicators and Warnings
Errors or warnings detected by the method:
On entry, .
On entry, all n values of at least one of the variables and are identical.
Accuracy
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 real variable, by means of a call to x02al.
Parallelism and Performance
None.
Further Comments
The time taken by g02ca depends on .
The method 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.
Example program (C#): g02cae.cs