|
NAG[g02cac] NAG[nag_simple_linear_regression] - Simple linear regression with or without a constant term, data may be weighted
|
|
Calling Sequence
g02cac(mean, x, y, a, b, a_serr, b_serr, rsq, rss, df, 'n'=n, 'wt'=wt, 'fail'=fail)
nag_simple_linear_regression(. . .)
Parameters
|
mean - String;
|
|
|
On entry: indicates whether nag_simple_linear_regression (g02cac) is to include a constant term in the regression.
|
|
The regression constant is included.
|
|
Constraint: "Nag_AboutMean" or "Nag_AboutZero". .
|
|
|
x - Vector(1..n, datatype=float[8]);
|
|
|
Constraint: all the values of must not be identical. .
|
|
|
y - Vector(1..n, datatype=float[8]);
|
|
|
Constraint: all the values of must not be identical. .
|
|
|
a - assignable;
|
|
|
Note: On exit the variable a will have a value of type float.
|
|
On exit: if then a is the regression constant , otherwise a is set to zero.
|
|
|
b - assignable;
|
|
|
Note: On exit the variable b will have a value of type float.
|
|
On exit: the regression coefficient .
|
|
|
a_serr - assignable;
|
|
|
Note: On exit the variable a_serr will have a value of type float.
|
|
On exit: the standard error of the regression constant .
|
|
|
b_serr - assignable;
|
|
|
Note: On exit the variable b_serr will have a value of type float.
|
|
On exit: the standard error of the regression coefficient .
|
|
|
rsq - assignable;
|
|
|
Note: On exit the variable rsq will have a value of type float.
|
|
On exit: the coefficient of determination, .
|
|
|
rss - assignable;
|
|
|
Note: On exit the variable rss will have a value of type float.
|
|
On exit: the sum of squares of the residuals about the regression.
|
|
|
df - assignable;
|
|
|
Note: On exit the variable df will have a value of type float.
|
|
On exit: the degrees of freedom associated with the residual sum of squares.
|
|
|
'n'=n - integer; (optional)
|
|
|
Default value: the first dimension of the arrays x, y, wt.
|
|
On entry: the number of observations, .
|
|
if , ;
|
|
if ,.
|
|
|
'wt'=wt - Vector(1..n, datatype=float[8]); (optional)
|
|
|
Constraint: , for . .
|
|
|
'fail'=fail - table; (optional)
|
|
|
The NAG error argument, see the documentation for NagError.
|
|
|
|
Description
|
|
|
Purpose
|
|
nag_simple_linear_regression (g02cac) performs a simple linear regression with or without a constant term. The data is optionally weighted.
|
|
Description
|
|
nag_simple_linear_regression (g02cac) fits a straight line model of the form,
where is the expected value of the variable , to the data points
such that
where the values are independent random errors. The th data point may have an associated weight , these may be used either in the situation when var or if observations have to be removed from the regression by having zero weight or have been observed with frequency .
The regression coefficient, , and the regression constant, are estimated by minimizing
if the weights option is not selected then .
The following statistics are computed:
|
the estimate of regression constant ,
|
|
the estimate of regression coefficient ,
|
|
the residual sum of squares ,
|
where the weighted means and are
The number of degrees of freedom associated with is
|
where
|
|
where
|
Note: the weights should be scaled to give the correct degrees of freedom in the case var .
The value or coefficient of determination
This measures the proportion of the total variation about the mean that can be explained by the regression.
The standard error for the regression constant
The standard error for the regression coefficient
Similar formulae can be derived for the case when the line goes through the origin, that is .
|
|
Error Indicators and Warnings
|
|
"NE_BAD_PARAM"
On entry, argument mean had an illegal value.
"NE_INT_ARG_LT"
On entry, n must not be less than 1: if .
"NE_NEG_WEIGHT"
On entry, at least one of the weights is negative.
"NE_SW_LOW"
On entry, the sum of elements of wt must be greater than 1.0 if or greater than 2.0 if .
"NE_WT_LOW"
On entry, wt must contain at least 1 positive element if or at least 2 positive elements if .
"NE_X_OR_Y_IDEN"
On entry, all elements of x and/or y are equal.
"NE_ZERO_DOF_RESID"
On entry, the degrees of freedom for the residual are zero, i.e., the designated number of arguments the effective number of observations.
"NW_RSS_EQ_ZERO"
Residual sum of squares is zero, i.e., a perfect fit was obtained.
|
|
Accuracy
|
|
The computations are believed to be stable.
|
|
Further Comments
|
|
The time taken by the function depends on . The function uses a two-pass algorithm.
|
|
|
Examples
|
|
>
|
mean := "Nag_AboutMean":
n := 8:
x := Vector([1, 0, 4, 7.5, 2.5, 0, 10, 5], datatype=float[8]):
y := Vector([20, 15.5, 28.3, 45, 24.5, 10, 99, 31.2], datatype=float[8]):
wt := Vector([1, 1, 1, 1, 1, 1, 1, 1], datatype=float[8]):
NAG:-g02cac(mean, x, y, a, b, a_serr, b_serr, rsq, rss, df, 'n' = n, 'wt' = wt):
|
|
|