g02cb Method
関数リスト一覧   NagLibrary Namespaceへ  ライブラリイントロダクション  本ヘルプドキュメントのchm形式版

g02cb performs a simple linear regression with no constant, with dependent variable y and independent variable x.

Syntax

C#
public static void g02cb(
	int n,
	double[] x,
	double[] y,
	double[] result,
	out int ifail
)
Visual Basic (Declaration)
Public Shared Sub g02cb ( _
	n As Integer, _
	x As Double(), _
	y As Double(), _
	result As Double(), _
	<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void g02cb(
	int n, 
	array<double>^ x, 
	array<double>^ y, 
	array<double>^ result, 
	[OutAttribute] int% ifail
)
F#
static member g02cb : 
        n:int * 
        x:float[] * 
        y:float[] * 
        result:float[] * 
        ifail:int byref -> unit 

Parameters

n
Type: System..::.Int32
On entry: n, the number of pairs of observations.
Constraint: n2.
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.
result
Type: array< System..::.Double >[]()[]
An array of size [20]
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] the value 0.0;
result[7] seb, the standard error of the regression coefficient;
result[8] the value 0.0;
result[9] tb, the t value for the regression coefficient;
result[10] the value 0.0;
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.
ifail
Type: System..::.Int32 %
On exit: ifail=0 unless the method detects an error (see [Error Indicators and Warnings]).

Description

g02cb fits a straight line of the form
y=bx
to the data points
x1,y1,x2,y2,,xn,yn ,
such that
yi=bxi+ei,  i=1,2,,nn2.
The method calculates the regression coefficient, b, and the various other statistical quantities by minimizing
i=1nei2.
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.
The quantities calculated are:
(a) Means:
x-=1ni=1nxi;  y-=1ni=1nyi.
(b) Standard deviations:
sx=1n- 1 i= 1n xi-x- 2;   sy=1n- 1 i= 1n yi-y- 2.
(c) Pearson product-moment correlation coefficient:
r=i=1nxi-x-yi-y- i=1n xi-x- 2i=1n yi-y- 2 .
(d) The regression coefficient, b:
b=i=1nxiyi i=1nxi2 .
(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=1nyi2;   SSD=i=1n yi-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=n;  DFD=n-1,  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=MSD i= 1nxi2 .
(j) The t value for the regression coefficient:
tb=bseb .

References

Error Indicators and Warnings

Accuracy

g02cb does not use additional precision arithmetic for the accumulation of scalar products, so there may be a loss of significant figures for large n.
If, in calculating F or tb  (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.

Further Comments

Computation time depends on n.
g02cb uses a two-pass algorithm.

Example

See Also