g02cd performs a simple linear regression with no constant, with dependent variable and independent variable , omitting cases involving missing values.
Syntax
C# |
---|
public static void g02cd( int n, double[] x, double[] y, double xmiss, double ymiss, double[] result, out int ifail ) |
Visual Basic |
---|
Public Shared Sub g02cd ( _ n As Integer, _ x As Double(), _ y As Double(), _ xmiss As Double, _ ymiss As Double, _ result As Double(), _ <OutAttribute> ByRef ifail As Integer _ ) |
Visual C++ |
---|
public: static void g02cd( int n, array<double>^ x, array<double>^ y, double xmiss, double ymiss, array<double>^ result, [OutAttribute] int% ifail ) |
F# |
---|
static member g02cd : n : int * x : float[] * y : float[] * xmiss : float * ymiss : 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 .
- xmiss
- Type: System..::..DoubleOn entry: the value , which is to be taken as the missing value for the variable (see [Accuracy]).
- ymiss
- Type: System..::..DoubleOn entry: the value , which is to be taken as the missing value for the variable (see [Accuracy]).
- 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 value ; , the standard error of the regression coefficient; the value ; , the value for the regression coefficient; the value ; , 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 number of observations used in the calculations.
- ifail
- Type: System..::..Int32%On exit: unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).
Description
g02cd fits a straight line of the form
to those of the data points
that do not include missing values, such that
for those , for
which do not include missing values.
The method eliminates all pairs of observations which contain a missing value for either or , and then calculates the regression coefficient, , and various other statistical quantities by minimizing the sum of the over those cases remaining in the calculations.
The input data consists of the pairs of observations on the independent variable and the dependent variable .
In addition two values, and , are given which are considered to represent missing observations for and respectively. (See [Accuracy]).
Let , if the th observation of either or is missing, i.e., if and/or ; and otherwise, for .
The quantities calculated are:
(a) | Means:
|
||
(b) | Standard deviations:
|
||
(c) | Pearson product-moment correlation coefficient:
|
||
(d) | The regression coefficient, :
|
||
(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:
|
||
(j) | The value for the regression coefficient:
|
||
(k) | The number of observations used in the calculations:
|
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, .
- After observations with missing values were omitted, fewer than two cases remained.
- After observations with missing values were omitted, all remaining values of at least one of the variables and were identical.
Accuracy
g02cd does not use additional precision arithmetic for the accumulation of scalar products, so there may be a loss of significant figures for large .
You are warned of the need to exercise extreme care in your selection of missing values. g02cd treats all values in the inclusive range , where is the missing value for variable specified in xmiss.
You must therefore ensure that the missing value chosen for each variable is sufficiently different from all valid values for that variable so that none of the valid values fall within the range indicated above.
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 g02cd depends on and the number of missing observations.
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 no constant, with the first variable as the independent variable, and the second variable as the dependent variable, omitting cases involving missing values ( for the first variable, for the second). Finally the results are printed.
Example program (C#): g02cde.cs