NAG FL Interface
g02ccf (linregs_const_miss)
1
Purpose
g02ccf performs a simple linear regression with dependent variable and independent variable , omitting cases involving missing values.
2
Specification
Fortran Interface
Integer, Intent (In) |
:: |
n |
Integer, Intent (Inout) |
:: |
ifail |
Real (Kind=nag_wp), Intent (In) |
:: |
x(n), y(n), xmiss, ymiss |
Real (Kind=nag_wp), Intent (Out) |
:: |
result(21) |
|
C Header Interface
#include <nag.h>
void |
g02ccf_ (const Integer *n, const double x[], const double y[], const double *xmiss, const double *ymiss, double result[], Integer *ifail) |
|
C++ Header Interface
#include <nag.h> extern "C" {
void |
g02ccf_ (const Integer &n, const double x[], const double y[], const double &xmiss, const double &ymiss, double result[], Integer &ifail) |
}
|
The routine may be called by the names g02ccf or nagf_correg_linregs_const_miss.
3
Description
g02ccf fits a straight line of the form
to those of the data points
that do not include missing values, such that
for those
,
which do not include missing values.
The routine eliminates all pairs of observations which contain a missing value for either or , and then calculates the regression coefficient, , the regression constant, , 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
Section 7).
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, , 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, :
-
(k)The number of observations used in the calculations:
4
References
Draper N R and Smith H (1985) Applied Regression Analysis (2nd Edition) Wiley
5
Arguments
-
1:
– Integer
Input
-
On entry: , the number of pairs of observations.
Constraint:
.
-
2:
– Real (Kind=nag_wp) array
Input
-
On entry: must contain , for .
-
3:
– Real (Kind=nag_wp) array
Input
-
On entry: must contain , for .
-
4:
– Real (Kind=nag_wp)
Input
-
On entry: the value
which is to be taken as the missing value for the variable
. See
Section 7.
-
5:
– Real (Kind=nag_wp)
Input
-
On entry: the value
which is to be taken as the missing value for the variable
. See
Section 7.
-
6:
– Real (Kind=nag_wp) array
Output
-
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; |
| , the total degrees of freedom; |
| , the number of observations used in the calculations. |
-
7:
– Integer
Input/Output
-
On entry:
ifail must be set to
,
or
to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of means that an error message is printed while a value of means that it is not.
If halting is not appropriate, the value
or
is recommended. If message printing is undesirable, then the value
is recommended. Otherwise, the value
is recommended.
When the value or is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
-
On entry, .
Constraint: .
-
After observations with missing values were omitted, two or fewer cases remained.
-
After observations with missing values were omitted, all remaining values of at least one of
x and
y were identical.
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See
Section 9 in the Introduction to the NAG Library FL Interface for further information.
7
Accuracy
g02ccf 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.
g02ccf 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
Section 3), 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
x02alf.
8
Parallelism and Performance
g02ccf is not threaded in any implementation.
The time taken by g02ccf depends on and the number of missing observations.
The routine uses a two-pass algorithm.
10
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 ( for the first variable, for the second). Finally the results are printed.
10.1
Program Text
10.2
Program Data
10.3
Program Results