g02cc performs a simple linear regression with dependent variable y and independent variable x, omitting cases involving missing values.

Syntax

C#
public static void g02cc(
	int n,
	double[] x,
	double[] y,
	double xmiss,
	double ymiss,
	double[] result,
	out int ifail
)
Visual Basic
Public Shared Sub g02cc ( _
	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 g02cc(
	int n, 
	array<double>^ x, 
	array<double>^ y, 
	double xmiss, 
	double ymiss, 
	array<double>^ result, 
	[OutAttribute] int% ifail
)
F#
static member g02cc : 
        n : int * 
        x : float[] * 
        y : float[] * 
        xmiss : float * 
        ymiss : float * 
        result : float[] * 
        ifail : int byref -> unit 

Parameters

n
Type: System..::..Int32
On entry: n, the number of pairs of observations.
Constraint: n>2.
x
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: x[i-1] must contain xi, for i=1,2,,n.
y
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: y[i-1] must contain yi, for i=1,2,,n.
xmiss
Type: System..::..Double
On entry: the value xm which is to be taken as the missing value for the variable x. See [Accuracy].
ymiss
Type: System..::..Double
On entry: the value ym which is to be taken as the missing value for the variable y. See [Accuracy].
result
Type: array<System..::..Double>[]()[][]
An array of size [21]
On exit: the following information:
result[0]x-, the mean value of the independent variable, x;
result[1]y-, the mean value of the dependent variable, y;
result[2]sx, the standard deviation of the independent variable, x;
result[3]sy, the standard deviation of the dependent variable, y;
result[4]r, the Pearson product-moment correlation between the independent variable x and the dependent variable y
result[5]b, the regression coefficient;
result[6]a, the regression constant;
result[7]seb, the standard error of the regression coefficient;
result[8]sea, the standard error of the regression constant;
result[9]tb, the t value for the regression coefficient;
result[10]ta, the t value for the regression constant;
result[11]SSR, the sum of squares attributable to the regression;
result[12]DFR, the degrees of freedom attributable to the regression;
result[13]MSR, the mean square attributable to the regression;
result[14]F, the F value for the analysis of variance;
result[15]SSD, the sum of squares of deviations about the regression;
result[16]DFD, the degrees of freedom of deviations about the regression;
result[17]MSD, the mean square of deviations about the regression;
result[18]SST, the total sum of squares;
result[19]DFT, the total degrees of freedom;
result[20]nc, the number of observations used in the calculations.
ifail
Type: System..::..Int32%
On exit: ifail=0 unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

Description

g02cc fits a straight line of the form
y=a+bx
to those of the data points
x1,y1,x2,y2,,xn,yn
that do not include missing values, such that
yi=a+bxi+ei
for those xi,yi, i=1,2,,nn>2 which do not include missing values.
The method eliminates all pairs of observations xi,yi which contain a missing value for either x or y, and then calculates the regression coefficient, b, the regression constant, a, and various other statistical quantities, by minimizing the sum of the ei2 over those cases remaining in the calculations.
The input data consists of the n pairs of observations x1,y1,x2,y2,,xn,yn on the independent variable x and the dependent variable y.
In addition two values, xm and ym, are given which are considered to represent missing observations for x and y respectively. (See [Accuracy]).
Let wi=0 if the ith observation of either x or y is missing, i.e., if xi=xm and/or yi=ym; and wi=1 otherwise, for i=1,2,,n.
The quantities calculated are:
(a) Means:
x-=i=1nwixii=1nwi;  y-=i=1nwiyii=1nwi.
(b) Standard deviations:
sx=i=1nwixi-x-2i=1nwi-1;  sy=i=1nwiyi-y-2i=1nwi-1.
(c) Pearson product-moment correlation coefficient:
r=i=1nwixi-x-yi-y-i=1nwixi-x-2i=1nwiyi-y-2.
(d) The regression coefficient, b, and the regression constant, a:
b=i=1nwixi-x-yi-y-i=1nwixi-x-2,  a=y--bx-.
(e) 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=i=1nwiyi-y-2;  SSD=i=1nwiyi-a-bxi2;  SSR=SST-SSD.
(f) 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:
DFT=i=1nwi-1;  DFD=i=1nwi-2;  DFR=1.
(g) The mean square attributable to the regression, MSR, and the mean square of deviations about the regression, MSD:
MSR=SSR/DFR;  MSD=SSD/DFD.
(h) The F value for the analysis of variance:
F=MSR/MSD.
(i) The standard error of the regression coefficient, seb, and the standard error of the regression constant, sea:
seb=MSDi=1nwixi-x-2;  sea=MSD1i=1nwi+x-2i=1nwixi-x-2.
(j) The t value for the regression coefficient, tb, and the t value for the regression constant, ta:
tb=bseb;  ta=asea.
(k) The number of observations used in the calculations:
nc=i=1nwi.

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:
ifail=1
On entry,n2.
ifail=2
After observations with missing values were omitted, two or fewer cases remained.
ifail=3
After observations with missing values were omitted, all remaining values of at least one of the variables x and y were identical.
ifail=-9000
An error occured, see message report.
ifail=-8000
Negative dimension for array value
ifail=-6000
Invalid Parameters value

Accuracy

g02cc does not use additional precision arithmetic for the accumulation of scalar products, so there may be a loss of significant figures for large n.
You are warned of the need to exercise extreme care in your selection of missing values. g02cc treats all values in the inclusive range 1±0.1x02be-2×xmj, where xmj is the missing value for variable j 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 F or ta  (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 g02cc depends on n 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 the first variable as the independent variable, and the second variable as the dependent variable, omitting cases involving missing values (0.0 for the first variable, 99.0 for the second). Finally the results are printed.

Example program (C#): g02cce.cs

Example program data: g02cce.d

Example program results: g02cce.r

See Also