g02da performs a general multiple linear regression when the independent variables may be linearly dependent. Parameter estimates, standard errors, residuals and influence statistics are computed. g02da may be used to perform a weighted regression.

Syntax

C#
public static void g02da(
	string mean,
	string weight,
	int n,
	double[,] x,
	int m,
	int[] isx,
	int ip,
	double[] y,
	double[] wt,
	out double rss,
	out int idf,
	double[] b,
	double[] se,
	double[] cov,
	double[] res,
	double[] h,
	double[,] q,
	out bool svd,
	out int irank,
	double[] p,
	double tol,
	double[] wk,
	out int ifail
)
Visual Basic
Public Shared Sub g02da ( _
	mean As String, _
	weight As String, _
	n As Integer, _
	x As Double(,), _
	m As Integer, _
	isx As Integer(), _
	ip As Integer, _
	y As Double(), _
	wt As Double(), _
	<OutAttribute> ByRef rss As Double, _
	<OutAttribute> ByRef idf As Integer, _
	b As Double(), _
	se As Double(), _
	cov As Double(), _
	res As Double(), _
	h As Double(), _
	q As Double(,), _
	<OutAttribute> ByRef svd As Boolean, _
	<OutAttribute> ByRef irank As Integer, _
	p As Double(), _
	tol As Double, _
	wk As Double(), _
	<OutAttribute> ByRef ifail As Integer _
)
Visual C++
public:
static void g02da(
	String^ mean, 
	String^ weight, 
	int n, 
	array<double,2>^ x, 
	int m, 
	array<int>^ isx, 
	int ip, 
	array<double>^ y, 
	array<double>^ wt, 
	[OutAttribute] double% rss, 
	[OutAttribute] int% idf, 
	array<double>^ b, 
	array<double>^ se, 
	array<double>^ cov, 
	array<double>^ res, 
	array<double>^ h, 
	array<double,2>^ q, 
	[OutAttribute] bool% svd, 
	[OutAttribute] int% irank, 
	array<double>^ p, 
	double tol, 
	array<double>^ wk, 
	[OutAttribute] int% ifail
)
F#
static member g02da : 
        mean : string * 
        weight : string * 
        n : int * 
        x : float[,] * 
        m : int * 
        isx : int[] * 
        ip : int * 
        y : float[] * 
        wt : float[] * 
        rss : float byref * 
        idf : int byref * 
        b : float[] * 
        se : float[] * 
        cov : float[] * 
        res : float[] * 
        h : float[] * 
        q : float[,] * 
        svd : bool byref * 
        irank : int byref * 
        p : float[] * 
        tol : float * 
        wk : float[] * 
        ifail : int byref -> unit 

Parameters

mean
Type: System..::..String
On entry: indicates if a mean term is to be included.
mean="M"
A mean term, intercept, will be included in the model.
mean="Z"
The model will pass through the origin, zero-point.
Constraint: mean="M" or "Z".
weight
Type: System..::..String
On entry: indicates if weights are to be used.
weight="U"
Least squares estimation is used.
weight="W"
Weighted least squares is used and weights must be supplied in array wt.
Constraint: weight="U" or "W".
n
Type: System..::..Int32
On entry: n, the number of observations.
Constraint: n2.
x
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, m]
Note: dim1 must satisfy the constraint: dim1n
On entry: x[i-1,j-1] must contain the ith observation for the jth independent variable, for i=1,2,,n and j=1,2,,m.
m
Type: System..::..Int32
On entry: m, the total number of independent variables in the dataset.
Constraint: m1.
isx
Type: array<System..::..Int32>[]()[][]
An array of size [m]
On entry: indicates which independent variables are to be included in the model.
isx[j-1]>0
The variable contained in the jth column of x is included in the regression model.
Constraints:
  • isx[j-1]0, for j=1,2,,m;
  • if mean="M", exactly ip-1 values of isx must be >0;
  • if mean="Z", exactly ip values of isx must be >0.
ip
Type: System..::..Int32
On entry: the number of independent variables in the model, including the mean or intercept if present.
Constraints:
  • if mean="M", 1ipm+1;
  • if mean="Z", 1ipm;
  • otherwise 1ipn.
y
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: y, observations on the dependent variable.
wt
Type: array<System..::..Double>[]()[][]
An array of size [dim1]
Note: the dimension of the array wt must be at least n if weight="W", and at least 1 otherwise.
On entry: if weight="W", wt must contain the weights to be used in the weighted regression.
If wt[i-1]=0.0, the ith observation is not included in the model, in which case the effective number of observations is the number of observations with nonzero weights. The values of res and h will be set to zero for observations with zero weights.
If weight="U", wt is not referenced and the effective number of observations is n.
Constraint: if weight="W", wt[i-1]0.0, for i=1,2,,n.
rss
Type: System..::..Double%
On exit: the residual sum of squares for the regression.
idf
Type: System..::..Int32%
On exit: the degrees of freedom associated with the residual sum of squares.
b
Type: array<System..::..Double>[]()[][]
An array of size [ip]
On exit: b[i-1], i=1,2,,ip contains the least squares estimates of the parameters of the regression model, β^.
If mean="M", b[0] will contain the estimate of the mean parameter and b[i] will contain the coefficient of the variable contained in column j of x, where isx[j-1] is the ith positive value in the array isx.
If mean="Z", b[i-1] will contain the coefficient of the variable contained in column j of x, where isx[j-1] is the ith positive value in the array isx.
se
Type: array<System..::..Double>[]()[][]
An array of size [ip]
On exit: se[i-1], i=1,2,,ip contains the standard errors of the ip parameter estimates given in b.
cov
Type: array<System..::..Double>[]()[][]
An array of size [ip×ip+1/2]
On exit: the first ip×ip+1/2 elements of cov contain the upper triangular part of the variance-covariance matrix of the ip parameter estimates given in b. They are stored packed by column, i.e., the covariance between the parameter estimate given in b[i-1] and the parameter estimate given in b[j-1], ji, is stored in cov[j×j-1/2+i-1].
res
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: the (weighted) residuals, ri, for i=1,2,,n.
h
Type: array<System..::..Double>[]()[][]
An array of size [n]
On exit: the diagonal elements of H, hi, for i=1,2,,n.
q
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, ip+1]
Note: dim1 must satisfy the constraint: dim1n
On exit: the results of the QR decomposition:
  • the first column of q contains c;
  • the upper triangular part of columns 2 to ip+1 contain the R matrix;
  • the strictly lower triangular part of columns 2 to ip+1 contain details of the Q matrix.
svd
Type: System..::..Boolean%
On exit: if a singular value decomposition has been performed then svd will be true, otherwise svd will be false.
irank
Type: System..::..Int32%
On exit: the rank of the independent variables.
If svd=false, irank=ip.
If svd=true, irank is an estimate of the rank of the independent variables.
irank is calculated as the number of singular values greater that tol× (largest singular value). It is possible for the SVD to be carried out but irank to be returned as ip.
p
Type: array<System..::..Double>[]()[][]
An array of size [2×ip+ip×ip]
On exit: details of the QR decomposition and SVD if used.
If svd=false, only the first ip elements of p are used these will contain the zeta values for the QR decomposition (see (F08AEF not in this release) for details).
If svd=true, the first ip elements of p will contain the zeta values for the QR decomposition (see (F08AEF not in this release) for details) and the next ip elements of p contain singular values. The following ip by ip elements contain the matrix P* stored by columns.
tol
Type: System..::..Double
On entry: the value of tol is used to decide if the independent variables are of full rank and if not what is the rank of the independent variables. The smaller the value of tol the stricter the criterion for selecting the singular value decomposition. If tol=0.0, the singular value decomposition will never be used; this may cause run time errors or inaccurate results if the independent variables are not of full rank.
Suggested value: tol=0.000001.
Constraint: tol0.0.
wk
Type: array<System..::..Double>[]()[][]
An array of size [max2,5×ip-1+ip×ip]
On exit: if on exit svd=true, wk contains information which is needed by g02dg; otherwise wk is used as workspace.
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

The general linear regression model is defined by
y=Xβ+ε,
where
  • y is a vector of n observations on the dependent variable,
  • X is an n by p matrix of the independent variables of column rank k,
  • β is a vector of length p of unknown parameters, and
  • ε is a vector of length n of unknown random errors such that varε=Vσ2, where V is a known diagonal matrix.
If V=I, the identity matrix, then least squares estimation is used. If VI, then for a given weight matrix WV-1, weighted least squares estimation is used.
The least squares estimates β^ of the parameters β minimize y-XβTy-Xβ while the weighted least squares estimates minimize y-XβTWy-Xβ.
g02da finds a QR decomposition of X (or W1/2X in weighted case), i.e.,
X=QR*or  W1/2X=QR*,
where R*=R0 and R is a p by p upper triangular matrix and Q is an n by n orthogonal matrix. If R is of full rank, then β^ is the solution to
Rβ^=c1,
where c=QTy (or QTW1/2y) and c1 is the first p elements of c. If R is not of full rank a solution is obtained by means of a singular value decomposition (SVD) of R,
R=Q*D000PT,
where D is a k by k diagonal matrix with nonzero diagonal elements, k being the rank of R, and Q* and P are p by p orthogonal matrices. This gives the solution
β^=P1D-1Q*1Tc1,
P1 being the first k columns of P, i.e., P=P1P0, and Q*1 being the first k columns of Q*.
Details of the SVD, are made available, in the form of the matrix P*:
P*=D-1P1TP0T.
This will be only one of the possible solutions. Other estimates may be obtained by applying constraints to the parameters. These solutions can be obtained by using g02dk after using g02da. Only certain linear combinations of the parameters will have unique estimates; these are known as estimable functions.
The fit of the model can be examined by considering the residuals, ri=yi-y^, where y^=Xβ^ are the fitted values. The fitted values can be written as Hy for an n by n matrix H. The ith diagonal elements of H, hi, give a measure of the influence of the ith values of the independent variables on the fitted regression model. The values hi are sometimes known as leverages. Both ri and hi are provided by g02da.
The output of g02da also includes β^, the residual sum of squares and associated degrees of freedom, n-k, the standard errors of the parameter estimates and the variance-covariance matrix of the parameter estimates.
In many linear regression models the first term is taken as a mean term or an intercept, i.e., Xi,1=1, for i=1,2,,n. This is provided as an option. Also only some of the possible independent variables are required to be included in a model, a facility to select variables to be included in the model is provided.
Details of the QR decomposition and, if used, the SVD, are made available. These allow the regression to be updated by adding or deleting an observation using g02dc, adding or deleting a variable using g02de and g02df or estimating and testing an estimable function using g02dn.

References

Cook R D and Weisberg S (1982) Residuals and Influence in Regression Chapman and Hall
Draper N R and Smith H (1985) Applied Regression Analysis (2nd Edition) Wiley
Golub G H and Van Loan C F (1996) Matrix Computations (3rd Edition) Johns Hopkins University Press, Baltimore
Hammarling S (1985) The singular value decomposition in multivariate statistics SIGNUM Newsl. 20(3) 2–25
McCullagh P and Nelder J A (1983) Generalized Linear Models Chapman and Hall
Searle S R (1971) Linear Models Wiley

Error Indicators and Warnings

Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (LDX, LDQ) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
ifail=1
On entry,n<2,
orm<1,
ortol<0.0,
orip0,
orip>n.
ifail=2
On entry,mean"M" or "Z",
orweight"W" or "U".
ifail=3
On entry,weight="W" and a value of wt<0.0.
ifail=4
On entry,a value of isx<0,
orthe value of ip is incompatible with the values of mean and isx,
orip is greater than the effective number of observations.
ifail=5
The degrees of freedom for the residuals are zero, i.e., the designated number of parameters is equal to the effective number of observations. In this case the parameter estimates will be returned along with the diagonal elements of H, but neither standard errors nor the variance-covariance matrix will be calculated.
ifail=6
The singular value decomposition has failed to converge, see (F02WUF not in this release). This is an unlikely error.
ifail=-9000
An error occured, see message report.
ifail=-6000
Invalid Parameters value
ifail=-4000
Invalid dimension for array value
ifail=-8000
Negative dimension for array value
ifail=-6000
Invalid Parameters value

Accuracy

The accuracy of g02da is closely related to the accuracy of (F08AEF not in this release) (F02WUF not in this release). These method documents should be consulted.

Parallelism and Performance

None.

Further Comments

Standardized residuals and further measures of influence can be computed using g02fa. g02fa requires, in particular, the results stored in res and h.

Example

See Also