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_var_add (g02de)

Purpose

nag_correg_linregm_var_add (g02de) adds a new independent variable to a general linear regression model.

Syntax

[q, p, rss, ifail] = g02de(ip, q, p, x, 'n', n, 'wt', wt, 'tol', tol)
[q, p, rss, ifail] = nag_correg_linregm_var_add(ip, q, p, x, 'n', n, '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

A linear regression model may be built up by adding new independent variables to an existing model. nag_correg_linregm_var_add (g02de) updates the QRQR decomposition used in the computation of the linear regression model. The QRQR decomposition may come from nag_correg_linregm_fit (g02da) or a previous call to nag_correg_linregm_var_add (g02de). The general linear regression model is defined by
y = Xβ + ε,
y=Xβ+ε,
where yy is a vector of nn observations on the dependent variable,
XX is an nn by pp matrix of the independent variables of column rank kk,
ββ is a vector of length pp of unknown parameters,
and εε is a vector of length nn of unknown random errors such that varε = Vσ2varε=Vσ2, where VV is a known diagonal matrix.
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β) .
The parameter estimates may be found by computing a QRQR decomposition of XX (or W(1/2)XW12X in the weighted case), i.e.,
X = QR*(or  W(1/2)X = QR*),
X=QR*(or  W12X=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 QTW(1/2)yQTW12y) 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.
To add a new independent variable, xp + 1xp+1, RR and cc have to be updated. The matrix Qp + 1Qp+1 is found such that Qp + 1T [R : QTxp + 1] Qp+1T [R:QTxp+1] (or Qp + 1T [R : QTW(1/2)xp + 1] Qp+1T [R:QTW12xp+1]) is upper triangular. The vector cc is then updated by multiplying by Qp + 1T Qp+1T .
The new independent variable is tested to see if it is linearly related to the existing independent variables by checking that at least one of the values (QTxp + 1)i(QTxp+1)i, for i = p + 2,,ni=p+2,,n, is nonzero.
The new parameter estimates, β̂β^, can then be obtained by a call to nag_correg_linregm_update (g02dd).
The function can be used with p = 0p=0, in which case RR and cc are initialized.

References

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:     ip – int64int32nag_int scalar
pp, the number of independent variables already in the model.
Constraint: ip0ip0 and ip < nip<n.
2:     q(ldq,ip + 2ip+2) – double array
ldq, the first dimension of the array, must satisfy the constraint ldqnldqn.
If ip0ip0, q must contain the results of the QRQR decomposition for the model with pp parameters as returned by nag_correg_linregm_fit (g02da) or a previous call to nag_correg_linregm_var_add (g02de).
If ip = 0ip=0, the first column of q should contain the nn values of the dependent variable, yy.
3:     p(ip + 1ip+1) – double array
Contains further details of the QRQR decomposition used. The first ip elements of p must contain the zeta values for the QRQR decomposition (see nag_lapack_dgeqrf (f08ae) for details).
The first ip elements of array p are provided by nag_correg_linregm_fit (g02da) or by previous calls to nag_correg_linregm_var_add (g02de).
4:     x(n) – double array
n, the dimension of the array, must satisfy the constraint n1n1.
xx, the new independent variable.

Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the array x and the first dimension of the array q. (An error is raised if these dimensions are not equal.)
nn, the number of observations.
Constraint: n1n1.
2:     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 provided, wt must contain the weights to be used.
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.
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.
3:     tol – double scalar
The value of tol is used to decide if the new independent variable is linearly related to independent variables already included in the model. If the new variable is linearly related then cc is not updated. The smaller the value of tol the stricter the criterion for deciding if there is a linear relationship.
Default: 0.0000010.000001
Constraint: tol > 0.0tol>0.0.

Input Parameters Omitted from the MATLAB Interface

weight ldq

Output Parameters

1:     q(ldq,ip + 2ip+2) – double array
ldqnldqn.
The results of the QRQR decomposition for the model with p + 1p+1 parameters:
  • the first column of q contains the updated value of cc;
  • the columns 22 to ip + 1ip+1 are unchanged;
  • the first ip + 1ip+1 elements of column ip + 2ip+2 contain the new column of RR, while the remaining nip1n-ip-1 elements contain details of the matrix Qp + 1Qp+1.
2:     p(ip + 1ip+1) – double array
The first ip elements of p are unchanged and the (ip + 1)(ip+1)th element contains the zeta value for Qp + 1Qp+1.
3:     rss – double scalar
The residual sum of squares for the new fitted model.
Note:  this will only be valid if the model is of full rank, see Section [Further Comments].
4:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Note: nag_correg_linregm_var_add (g02de) may return useful information for one or more of the following detected errors or 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 < 1n<1,
orip < 0ip<0,
oripnipn,
orldq < nldq<n,
ortol0.0tol0.0,
orweight'U'weight'U' or 'W''W'.
  ifail = 2ifail=2
On entry, weight = 'W'weight='W' and a value of wt < 0.0wt<0.0.
W ifail = 3ifail=3
The new independent variable is a linear combination of existing variables. The (ip + 2)(ip+2)th column of q will therefore be null.

Accuracy

The accuracy is closely related to the accuracy of nag_lapack_dormqr (f08ag) which should be consulted for further details.

Further Comments

It should be noted that the residual sum of squares produced by nag_correg_linregm_var_add (g02de) may not be correct if the model to which the new independent variable is added is not of full rank. In such a case nag_correg_linregm_update (g02dd) should be used to calculate the residual sum of squares.

Example

function nag_correg_linregm_var_add_example
ip = int64(0);
q = [4.32, 0;
     5.21, 0;
     6.49, 0;
     7.1,  0;
     7.94, 0;
     8.53, 0;
     8.84, 0;
     9.02, 0;
     9.27, 0;
     9.43, 0;
     9.68, 0;
     9.83, 0];
p = [0];
x = [1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1];
[qOut, pOut, rss, ifail] = nag_correg_linregm_var_add(ip, q, p, x)
 

qOut =

  -27.6147   -3.4641
   -1.9437    0.2543
   -0.6637    0.2543
   -0.0537    0.2543
    0.7863    0.2543
    1.3763    0.2543
    1.6863    0.2543
    1.8663    0.2543
    2.1163    0.2543
    2.2763    0.2543
    2.5263    0.2543
    2.6763    0.2543


pOut =

    1.1352


rss =

   36.2666


ifail =

                    0


function g02de_example
ip = int64(0);
q = [4.32, 0;
     5.21, 0;
     6.49, 0;
     7.1,  0;
     7.94, 0;
     8.53, 0;
     8.84, 0;
     9.02, 0;
     9.27, 0;
     9.43, 0;
     9.68, 0;
     9.83, 0];
p = [0];
x = [1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1];
[qOut, pOut, rss, ifail] = g02de(ip, q, p, x)
 

qOut =

  -27.6147   -3.4641
   -1.9437    0.2543
   -0.6637    0.2543
   -0.0537    0.2543
    0.7863    0.2543
    1.3763    0.2543
    1.6863    0.2543
    1.8663    0.2543
    2.1163    0.2543
    2.2763    0.2543
    2.5263    0.2543
    2.6763    0.2543


pOut =

    1.1352


rss =

   36.2666


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