hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_correg_linregm_fit (g02da)

Purpose

nag_correg_linregm_fit (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. nag_correg_linregm_fit (g02da) may be used to perform a weighted regression.

Syntax

[rss, idf, b, se, cov, res, h, q, svd, irank, p, wk, ifail] = g02da(mean, x, isx, ip, y, 'n', n, 'm', m, 'wt', wt, 'tol', tol)
[rss, idf, b, se, cov, res, h, q, svd, irank, p, wk, ifail] = nag_correg_linregm_fit(mean, x, isx, ip, y, 'n', n, 'm', m, 'wt', wt, 'tol', tol)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 23: weight dropped from interface, wt now optional
.

Description

The general linear regression model is defined by
y = Xβ + ε,
y=Xβ+ε,
where
If V = IV=I, the identity matrix, then least squares estimation is used. If VIVI, then for a given weight matrix WV1WV-1, weighted least squares estimation is used.
The least squares estimates β̂β^ of the parameters ββ minimize (yXβ)T (yXβ) (y-Xβ)T (y-Xβ)  while the weighted least squares estimates minimize (yXβ)T W(yXβ) (y-Xβ)T W(y-Xβ) .
nag_correg_linregm_fit (g02da) finds a QRQR decomposition of XX (or W1 / 2XW1/2X in weighted case), i.e.,
X = QR*(or  W1 / 2X = QR*),
X=QR*(or  W1/2X=QR*),
where R* =
(R)
0
R*= R 0  and RR is a pp by pp upper triangular matrix and QQ is an nn by nn orthogonal matrix. If RR is of full rank, then β̂β^ is the solution to
Rβ̂ = c1,
Rβ^=c1,
where c = QTyc=QTy (or QTW1 / 2yQTW1/2y) and c1c1 is the first pp elements of cc. If RR is not of full rank a solution is obtained by means of a singular value decomposition (SVD) of RR,
R = Q*
(D0)
0 0
PT,
R=Q* D 0 0 0 PT,
where DD is a kk by kk diagonal matrix with nonzero diagonal elements, kk being the rank of RR, and Q*Q* and PP are pp by pp orthogonal matrices. This gives the solution
β̂ = P1D1Q*1Tc1,
β^=P1D-1Q*1Tc1,
P1P1 being the first kk columns of PP, i.e., P =
(P1P0)
P=P1P0, and Q*1Q*1 being the first kk columns of Q*Q*.
Details of the SVD, are made available, in the form of the matrix P*P*:
P* =
(D1 P1T )
P0T
.
P*= D-1 P1T P0T .
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 nag_correg_linregm_constrain (g02dk) after using nag_correg_linregm_fit (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 = yiri=yi-y^, where = Xβ̂y^=Xβ^ are the fitted values. The fitted values can be written as HyHy for an nn by nn matrix HH. The iith diagonal elements of HH, hihi, give a measure of the influence of the iith values of the independent variables on the fitted regression model. The values hihi are sometimes known as leverages. Both riri and hihi are provided by nag_correg_linregm_fit (g02da).
The output of nag_correg_linregm_fit (g02da) also includes β̂β^, the residual sum of squares and associated degrees of freedom, (nk)(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 = 1Xi,1=1, for i = 1,2,,ni=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 QRQR decomposition and, if used, the SVD, are made available. These allow the regression to be updated by adding or deleting an observation using nag_correg_linregm_obs_edit (g02dc), adding or deleting a variable using nag_correg_linregm_var_add (g02de) and nag_correg_linregm_var_del (g02df) or estimating and testing an estimable function using nag_correg_linregm_estfunc (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

Parameters

Compulsory Input Parameters

1:     mean – string (length ≥ 1)
Indicates if a mean term is to be included.
mean = 'M'mean='M'
A mean term, intercept, will be included in the model.
mean = 'Z'mean='Z'
The model will pass through the origin, zero-point.
Constraint: mean = 'M'mean='M' or 'Z''Z'.
2:     x(ldx,m) – double array
ldx, the first dimension of the array, must satisfy the constraint ldxnldxn.
x(i,j)xij must contain the iith observation for the jjth independent variable, for i = 1,2,,ni=1,2,,n and j = 1,2,,mj=1,2,,m.
3:     isx(m) – int64int32nag_int array
m, the dimension of the array, must satisfy the constraint m1m1.
Indicates which independent variables are to be included in the model.
isx(j) > 0isxj>0
The variable contained in the jjth column of x is included in the regression model.
Constraints:
  • isx(j)0isxj0, for j = 1,2,,mj=1,2,,m;
  • if mean = 'M'mean='M', exactly ip1ip-1 values of isx must be > 0>0;
  • if mean = 'Z'mean='Z', exactly ip values of isx must be > 0>0.
4:     ip – int64int32nag_int scalar
The number of independent variables in the model, including the mean or intercept if present.
Constraints:
  • if mean = 'M'mean='M', 1ipm + 11ipm+1;
  • if mean = 'Z'mean='Z', 1ipm1ipm;
  • otherwise 1ipn1ipn.
5:     y(n) – double array
n, the dimension of the array, must satisfy the constraint n2n2.
yy, observations on the dependent variable.

Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the array y and the first dimension of the array x. (An error is raised if these dimensions are not equal.)
nn, the number of observations.
Constraint: n2n2.
2:     m – int64int32nag_int scalar
Default: The dimension of the array isx and the second dimension of the array x. (An error is raised if these dimensions are not equal.)
mm, the total number of independent variables in the dataset.
Constraint: m1m1.
3:     wt( : :) – double array
Note: the dimension of the array wt must be at least nn if weight = 'W'weight='W', and at least 11 otherwise.
If If provided, wt must contain the weights to be used in the weighted regression.
If wt(i) = 0.0wti=0.0, the iith 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 wt is not provided, the effective number of observations is nn.
Constraint: if weight = 'W'weight='W', wt(i)0.0wti0.0, for i = 1,2,,ni=1,2,,n.
4:     tol – double scalar
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.0tol=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.
Default: 0.0000010.000001
Constraint: tol0.0tol0.0.

Input Parameters Omitted from the MATLAB Interface

weight ldx ldq

Output Parameters

1:     rss – double scalar
The residual sum of squares for the regression.
2:     idf – int64int32nag_int scalar
The degrees of freedom associated with the residual sum of squares.
3:     b(ip) – double array
b(i)bi, i = 1,2,,ipi=1,2,,ip contains the least squares estimates of the parameters of the regression model, β̂β^.
If mean = 'M'mean='M', b(1)b1 will contain the estimate of the mean parameter and b(i + 1)bi+1 will contain the coefficient of the variable contained in column jj of x, where isx(j)isxj is the iith positive value in the array isx.
If mean = 'Z'mean='Z', b(i)bi will contain the coefficient of the variable contained in column jj of x, where isx(j)isxj is the iith positive value in the array isx.
4:     se(ip) – double array
se(i)sei, i = 1,2,,ipi=1,2,,ip contains the standard errors of the ip parameter estimates given in b.
5:     cov(ip × (ip + 1) / 2ip×(ip+1)/2) – double array
The first ip × (ip + 1) / 2ip×(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)bi and the parameter estimate given in b(j)bj, jiji, is stored in cov(j × (j1) / 2 + i)covj×(j-1)/2+i.
6:     res(n) – double array
The (weighted) residuals, riri, for i = 1,2,,ni=1,2,,n.
7:     h(n) – double array
The diagonal elements of HH, hihi, for i = 1,2,,ni=1,2,,n.
8:     q(ldq,ip + 1ip+1) – double array
ldqnldqn.
The results of the QRQR decomposition:
  • the first column of q contains cc;
  • the upper triangular part of columns 22 to ip + 1ip+1 contain the RR matrix;
  • the strictly lower triangular part of columns 22 to ip + 1ip+1 contain details of the QQ matrix.
9:     svd – logical scalar
If a singular value decomposition has been performed then svd will be true, otherwise svd will be false.
10:   irank – int64int32nag_int scalar
The rank of the independent variables.
If svd = falsesvd=false, irank = ipirank=ip.
If svd = truesvd=true, irank is an estimate of the rank of the independent variables.
irank is calculated as the number of singular values greater that tol × tol× (largest singular value). It is possible for the SVD to be carried out but irank to be returned as ip.
11:   p(2 × ip + ip × ip2×ip+ip×ip) – double array
Details of the QRQR decomposition and SVD if used.
If svd = falsesvd=false, only the first ip elements of p are used these will contain the zeta values for the QRQR decomposition (see nag_lapack_dgeqrf (f08ae) for details).
If svd = truesvd=true, the first ip elements of p will contain the zeta values for the QRQR decomposition (see nag_lapack_dgeqrf (f08ae) for details) and the next ip elements of p contain singular values. The following ip by ip elements contain the matrix P*P* stored by columns.
12:   wk(max (2,5 × (ip1) + ip × ip)max(2,5×(ip-1)+ip×ip)) – double array
If on exit svd = truesvd=true, wk contains information which is needed by nag_correg_linregm_fit_newvar (g02dg); otherwise wk is used as workspace.
13:   ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

  ifail = 1ifail=1
On entry,n < 2n<2,
orm < 1m<1,
orldx < nldx<n,
orldq < nldq<n,
ortol < 0.0tol<0.0,
orip0ip0,
orip > nip>n.
  ifail = 2ifail=2
On entry,mean'M'mean'M' or 'Z''Z',
orweight'W'weight'W' or 'U''U'.
  ifail = 3ifail=3
On entry,weight = 'W'weight='W' and a value of wt < 0.0wt<0.0.
  ifail = 4ifail=4
On entry,a value of isx < 0isx<0,
orthe value of ip is incompatible with the values of mean and isx,
orip is greater than the effective number of observations.
W ifail = 5ifail=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 HH, but neither standard errors nor the variance-covariance matrix will be calculated.
  ifail = 6ifail=6
The singular value decomposition has failed to converge, see nag_eigen_real_triang_svd (f02wu). This is an unlikely error.

Accuracy

The accuracy of nag_correg_linregm_fit (g02da) is closely related to the accuracy of nag_eigen_real_triang_svd (f02wu) and nag_lapack_dgeqrf (f08ae). These function documents should be consulted.

Further Comments

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

Example

function nag_correg_linregm_fit_example
mean_p = 'M';
x = [1, 0, 0, 0;
     0, 0, 0, 1;
     0, 1, 0, 0;
     0, 0, 1, 0;
     0, 0, 0, 1;
     0, 1, 0, 0;
     0, 0, 0, 1;
     1, 0, 0, 0;
     0, 0, 1, 0;
     1, 0, 0, 0;
     0, 0, 1, 0;
     0, 1, 0, 0];
isx = [int64(1);1;1;1];
ip = int64(5);
y = [33.63;
     39.62;
     38.18;
     41.46;
     38.02;
     35.83;
     35.99;
     36.58;
     42.92;
     37.8;
     40.43;
     37.89];
[rss, idf, b, se, covar, res, h, q, svd, irank, p, wk, ifail] = ...
    nag_correg_linregm_fit(mean_p, x, isx, ip, y)
 

rss =

   22.2268


idf =

                    8


b =

   30.5567
    5.4467
    6.7433
   11.0467
    7.3200


se =

    0.3849
    0.8390
    0.8390
    0.8390
    0.8390


covar =

    0.1482
    0.0370
    0.7038
    0.0370
   -0.2223
    0.7038
    0.0370
   -0.2223
   -0.2223
    0.7038
    0.0370
   -0.2223
   -0.2223
   -0.2223
    0.7038


res =

   -2.3733
    1.7433
    0.8800
   -0.1433
    0.1433
   -1.4700
   -1.8867
    0.5767
    1.3167
    1.7967
   -1.1733
    0.5900


h =

    0.3333
    0.3333
    0.3333
    0.3333
    0.3333
    0.3333
    0.3333
    0.3333
    0.3333
    0.3333
    0.3333
    0.3333


q =

 -132.3142   -3.4641   -0.8660   -0.8660   -0.8660   -0.8660
   -4.3850    0.2543    1.5000   -0.5000   -0.5000   -0.5000
    3.4507    0.2543    0.2464   -1.4142    0.7071    0.7071
   -4.5642    0.2543    0.2464   -0.1494   -1.2247    1.2247
    0.9125    0.2543    0.2464   -0.1494   -0.2512   -0.0000
   -2.1257    0.2543    0.2464    0.4236    0.0476   -0.6063
   -1.7393    0.2543    0.2464   -0.1494   -0.2512         0
    1.6157    0.2543   -0.3431   -0.0580   -0.0975   -0.3638
    1.4622    0.2543    0.2464   -0.1494    0.4137         0
    2.8357    0.2543   -0.3431   -0.0580   -0.0975   -0.3638
   -1.0278    0.2543    0.2464   -0.1494    0.4137         0
   -0.0657    0.2543    0.2464    0.4236    0.0476   -0.6063


svd =

     1


irank =

                    4


p =

    1.1352
    1.1308
    1.2340
    1.2280
    1.0000
    3.8730
    1.7321
    1.7321
    1.7321
    0.0000
   -0.2309
         0
   -0.0000
         0
    0.4472
   -0.0577
    0.3922
    0.3050
    0.0562
   -0.4472
   -0.0577
   -0.4154
    0.2719
   -0.0595
   -0.4472
   -0.0577
    0.0695
   -0.2884
   -0.4025
   -0.4472
   -0.0577
   -0.0463
   -0.2884
    0.4058
   -0.4472


wk =

    1.0000
   -0.0000
    0.0000
         0
    0.0000
         0
    0.7844
    0.6038
   -0.1418
    0.0000
    0.0000
    0.6100
   -0.7924
    0.0000
    0.0000
         0
    0.1124
    0.0865
    0.9899
   -0.0000
   -0.0000
   -0.0000
   -0.0000
    0.0000
    1.0000
   -0.2887
   -0.4154
    0.2719
   -0.0595
    1.0000
    0.5000
    0.5774
    0.7071
         0
   -0.8660
   -0.8165
   -0.7071
         0
         0
         0
         0
         0
         0
         0
         0


ifail =

                    0


function g02da_example
mean_p = 'M';
x = [1, 0, 0, 0;
     0, 0, 0, 1;
     0, 1, 0, 0;
     0, 0, 1, 0;
     0, 0, 0, 1;
     0, 1, 0, 0;
     0, 0, 0, 1;
     1, 0, 0, 0;
     0, 0, 1, 0;
     1, 0, 0, 0;
     0, 0, 1, 0;
     0, 1, 0, 0];
isx = [int64(1);1;1;1];
ip = int64(5);
y = [33.63;
     39.62;
     38.18;
     41.46;
     38.02;
     35.83;
     35.99;
     36.58;
     42.92;
     37.8;
     40.43;
     37.89];
[rss, idf, b, se, covar, res, h, q, svd, irank, p, wk, ifail] = g02da(mean_p, x, isx, ip, y)
 

rss =

   22.2268


idf =

                    8


b =

   30.5567
    5.4467
    6.7433
   11.0467
    7.3200


se =

    0.3849
    0.8390
    0.8390
    0.8390
    0.8390


covar =

    0.1482
    0.0370
    0.7038
    0.0370
   -0.2223
    0.7038
    0.0370
   -0.2223
   -0.2223
    0.7038
    0.0370
   -0.2223
   -0.2223
   -0.2223
    0.7038


res =

   -2.3733
    1.7433
    0.8800
   -0.1433
    0.1433
   -1.4700
   -1.8867
    0.5767
    1.3167
    1.7967
   -1.1733
    0.5900


h =

    0.3333
    0.3333
    0.3333
    0.3333
    0.3333
    0.3333
    0.3333
    0.3333
    0.3333
    0.3333
    0.3333
    0.3333


q =

 -132.3142   -3.4641   -0.8660   -0.8660   -0.8660   -0.8660
   -4.3850    0.2543    1.5000   -0.5000   -0.5000   -0.5000
    3.4507    0.2543    0.2464   -1.4142    0.7071    0.7071
   -4.5642    0.2543    0.2464   -0.1494   -1.2247    1.2247
    0.9125    0.2543    0.2464   -0.1494   -0.2512   -0.0000
   -2.1257    0.2543    0.2464    0.4236    0.0476   -0.6063
   -1.7393    0.2543    0.2464   -0.1494   -0.2512         0
    1.6157    0.2543   -0.3431   -0.0580   -0.0975   -0.3638
    1.4622    0.2543    0.2464   -0.1494    0.4137         0
    2.8357    0.2543   -0.3431   -0.0580   -0.0975   -0.3638
   -1.0278    0.2543    0.2464   -0.1494    0.4137         0
   -0.0657    0.2543    0.2464    0.4236    0.0476   -0.6063


svd =

     1


irank =

                    4


p =

    1.1352
    1.1308
    1.2340
    1.2280
    1.0000
    3.8730
    1.7321
    1.7321
    1.7321
    0.0000
   -0.2309
         0
   -0.0000
         0
    0.4472
   -0.0577
    0.3922
    0.3050
    0.0562
   -0.4472
   -0.0577
   -0.4154
    0.2719
   -0.0595
   -0.4472
   -0.0577
    0.0695
   -0.2884
   -0.4025
   -0.4472
   -0.0577
   -0.0463
   -0.2884
    0.4058
   -0.4472


wk =

    1.0000
   -0.0000
    0.0000
         0
    0.0000
         0
    0.7844
    0.6038
   -0.1418
    0.0000
    0.0000
    0.6100
   -0.7924
    0.0000
    0.0000
         0
    0.1124
    0.0865
    0.9899
   -0.0000
   -0.0000
   -0.0000
   -0.0000
    0.0000
    1.0000
   -0.2887
   -0.4154
    0.2719
   -0.0595
    1.0000
    0.5000
    0.5774
    0.7071
         0
   -0.8660
   -0.8165
   -0.7071
         0
         0
         0
         0
         0
         0
         0
         0


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013