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_newvar (g02dg)

Purpose

nag_correg_linregm_fit_newvar (g02dg) calculates the estimates of the parameters of a general linear regression model for a new dependent variable after a call to nag_correg_linregm_fit (g02da).

Syntax

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

Description

nag_correg_linregm_fit_newvar (g02dg) uses the results given by nag_correg_linregm_fit (g02da) to fit the same set of independent variables to a new dependent variable.
nag_correg_linregm_fit (g02da) computes a QRQR decomposition of the matrix of pp independent variables and also, if the model is not of full rank, a singular value decomposition (SVD). These results can be used to compute estimates of the parameters for a general linear model with a new dependent variable. The QRQR decomposition leads to the formation of an upper triangular pp by pp matrix RR and an nn by nn orthogonal matrix QQ. In addition the vector c = QTyc=QTy (or QTW1 / 2yQTW1/2y) is computed. For a new dependent variable, ynewynew, nag_correg_linregm_fit_newvar (g02dg) computes a new value of c = QTynewc=QTynew or QTW1 / 2ynewQTW1/2ynew.
If RR is of full rank, then the least squares parameter estimates, β̂β^, are the solution to
Rβ̂ = c1,
Rβ^=c1,
where c1c1 is the first pp elements of cc.
If RR is not of full rank, then nag_correg_linregm_fit (g02da) will have computed an 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
β̂ = P1D1 Q*1T c1,
β^=P1D-1 Q*1T c1,
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 by nag_correg_linregm_fit (g02da) in the form of the matrix P*P*:
P* =
(D1 P1T )
P0T
.
P*= D-1 P1T P0T .
The matrix Q*Q* is made available through the workspace of nag_correg_linregm_fit (g02da).
In addition to parameter estimates, the new residuals are computed and the variance-covariance matrix of the parameter estimates are found by scaling the variance-covariance matrix for the original regression.

References

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
Searle S R (1971) Linear Models Wiley

Parameters

Compulsory Input Parameters

1:     rss – double scalar
The residual sum of squares for the original dependent variable.
Constraint: rss > 0.0rss>0.0.
2:     ip – int64int32nag_int scalar
pp, the number of independent variables (including the mean if fitted).
Constraint: 1ipn1ipn.
3:     irank – int64int32nag_int scalar
The rank of the independent variables, as given by nag_correg_linregm_fit (g02da).
Constraint: irank > 0irank>0, and if svd = falsesvd=false, then irank = ipirank=ip, else irankipirankip.
4:     cov(ip × (ip + 1) / 2ip×(ip+1)/2) – double array
The covariance matrix of the parameter estimates as given by nag_correg_linregm_fit (g02da).
5:     q(ldq,ip + 1ip+1) – double array
ldq, the first dimension of the array, must satisfy the constraint ldqnldqn.
The results of the QRQR decomposition as returned by nag_correg_linregm_fit (g02da).
6:     svd – logical scalar
Indicates if a singular value decomposition was used by nag_correg_linregm_fit (g02da).
svd = truesvd=true
A singular value decomposition was used by nag_correg_linregm_fit (g02da).
svd = falsesvd=false
A singular value decomposition was not used by nag_correg_linregm_fit (g02da).
7:     p( : :) – double array
Note: the dimension of the array p must be at least ipip if svd = falsesvd=false, and at least ip × ip + 2 × ipip×ip+2×ip otherwise.
Details of the QRQR decomposition and SVD, if used, as returned in array p by nag_correg_linregm_fit (g02da).
If svd = falsesvd=false, only the first ip elements of p are used; these 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 contain the zeta values for the QRQR decomposition (see nag_lapack_dgeqrf (f08ae) for details) and the next ip × ip + ipip×ip+ip elements of p contain details of the singular value decomposition.
8:     y(n) – double array
n, the dimension of the array, must satisfy the constraint nipnip.
The new dependent variable, ynewynew.
9:     wk(5 × (ip1) + ip × ip5×(ip-1)+ip×ip) – double array
If svd = truesvd=true, wk must be unaltered from the previous call to nag_correg_linregm_fit (g02da) or nag_correg_linregm_fit_newvar (g02dg).
If svd = falsesvd=false, wk is used as workspace.

Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the array y and the first dimension of the array q. (An error is raised if these dimensions are not equal.)
nn, the number of observations.
Constraint: nipnip.
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 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.
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.

Input Parameters Omitted from the MATLAB Interface

weight ldq

Output Parameters

1:     rss – double scalar
The residual sum of squares for the new dependent variable.
2:     cov(ip × (ip + 1) / 2ip×(ip+1)/2) – double array
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))cov(j×(j-1)/2+i).
3:     q(ldq,ip + 1ip+1) – double array
ldqnldqn.
The first column of q contains the new values of cc, the remainder of q will be unchanged.
4:     b(ip) – double array
The least squares estimates of the parameters of the regression model, β̂β^.
5:     se(ip) – double array
The standard error of the estimates of the parameters.
6:     res(n) – double array
The residuals for the new regression model.
7:     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:
  ifail = 1ifail=1
On entry,ip < 1ip<1,
orn < ipn<ip,
orirank0irank0,
orsvd = falsesvd=false and irankipirankip,
orsvd = truesvd=true and irank > ipirank>ip,
orldq < nldq<n,
orrss0.0rss0.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.

Accuracy

The same accuracy as nag_correg_linregm_fit (g02da) is obtained.

Further Comments

The values of the leverages, hihi, are unaltered by a change in the dependent variable so a call to nag_correg_linregm_stat_resinf (g02fa) can be made using the value of h from nag_correg_linregm_fit (g02da).

Example

function nag_correg_linregm_fit_newvar_example
rss = 22.2268;
ip = int64(5);
irank = int64(4);
covar = [0.1481786666666657;
     0.03704466666666638;
     0.7038486666666622;
     0.03704466666666652;
     -0.222268;
     0.7038486666666626;
     0.03704466666666648;
     -0.222268;
     -0.222268;
     0.7038486666666621;
     0.03704466666666641;
     -0.222268;
     -0.222268;
     -0.222268;
     0.7038486666666622];
q = [-132.3142479415325, -3.464101615137754, -0.866025403784439, ...
     -0.8660254037844387, -0.8660254037844387, -0.8660254037844387;
     -4.385, 0.2542949013547401, 1.5, -0.5, -0.5, -0.5;
     3.450681092190354, 0.2542949013547401, 0.2464408878569322, ...
     -1.414213562373095, 0.7071067811865476, 0.7071067811865477;
     -4.564215887385989, 0.2542949013547401, 0.2464408878569322, ...
     -0.1493782079840455, -1.224744871391589, 1.224744871391589;
     -0.5165745490611717, 0.2542949013547401, 0.2464408878569322, ...
     -0.1493782079840455, -0.2512250416211346, 3.684598669906146e-16;
     -1.786105166371516, 0.2542949013547401, 0.2464408878569322, ...
     0.4236386677182777, 0.04757984926531376, 0.05853513115087475;
     -2.040746763558067, 0.2542949013547401, 0.2464408878569322, ...
     -0.1493782079840455, -0.2512250416211346, 0.4717748148066523;
     1.699599417218472, 0.2542949013547401, -0.3431208422711533, ...
     -0.05795805473930137, -0.09747415577321789, 0.2226984422646312;
     1.338178326423549, 0.2542949013547401, 0.2464408878569322, ...
     -0.1493782079840455, 0.4136728082784363, 0.1941369084874573;
     2.919599417218471, 0.2542949013547401, -0.3431208422711533, ...
     -0.05795805473930137, -0.09747415577321789, 0.2226984422646312;
     -1.151821673576453, 0.2542949013547401, 0.2464408878569322, ...
     -0.1493782079840455, 0.4136728082784363, 0.1941369084874573;
     0.2738948336284861, 0.2542949013547401, 0.2464408878569322, ...
     0.4236386677182777, 0.04757984926531376, 0.05853513115087475];
svd = true;
p = [1.135198279858991;
     1.13078348304906;
     1.234006904805161;
     1.228003039942231;
     1.263332232672042;
     3.872983346207417;
     1.732050807568878;
     1.732050807568878;
     1.732050807568877;
     1.64780261914309e-16;
     0.2309401076758503;
     8.35089227579159e-18;
     -1.238223776129407e-17;
     7.900875770685859e-17;
     -0.447213595499958;
     0.0577350269189626;
     0.2871305767251709;
     0.2022129403845741;
     -0.3559016137228031;
     0.447213595499958;
     0.05773502691896256;
     0.03726461792122844;
     0.271286303307133;
     0.4183480487454616;
     0.447213595499958;
     0.05773502691896257;
     0.1515575558927682;
     -0.4677758485215264;
     0.0906424999201606;
     0.447213595499958;
     0.05773502691896258;
     -0.4759527505391677;
     -0.005723395170180857;
     -0.153088934942819;
     0.4472135954999578];
y = [63;
     69;
     68;
     71;
     68;
     65;
     65;
     66;
     72;
     67;
     70;
     67];
wk = [-1;
     4.888782090057172e-17;
     3.783865581974411e-17;
     3.205148747669446e-17;
     2.127304033926049e-17;
     -7.232084855102773e-18;
     0.574261153450342;
     -0.282082169979652;
     -0.7685400295478783;
     -1.766548161010173e-16;
     1.072333245697965e-17;
     0.4044258807691484;
     -0.7184712955241166;
     0.5658963725559621;
     -3.152388336389935e-17;
     -6.842359129558908e-17;
     -0.7118032274456063;
     -0.635789781993599;
     -0.2985088248453474;
     7.896994727506343e-17;
     2.12730403392605e-17;
     1.57267977670022e-16;
     -8.430959034105682e-17;
     -1.677854456096144e-16;
     1;
     0.2886751345948128;
     0.03726461792122845;
     0.271286303307133;
     0.4183480487454616;
     5;
     3.25;
     5.25;
     4.25;
     5.25;
     6.070050924028785e-16;
     0.7071067811865474;
     -0.5700260616371526;
     0.9995120760870788;
     1;
     0.7071067811865475;
     0.8216266117004956;
     0.03123475237772124;
     5.777618349603308e-32;
     -0.7071067811865476;
     -0.5700260616371526];
[rssOut, covarOut, qOut, b, se, res, ifail] = ...
    nag_correg_linregm_fit_newvar(rss, ip, irank, covar, q, svd, p, y, wk)
 

rssOut =

   24.0000


covarOut =

    0.1600
    0.0400
    0.7600
    0.0400
   -0.2400
    0.7600
    0.0400
   -0.2400
   -0.2400
    0.7600
    0.0400
   -0.2400
   -0.2400
   -0.2400
    0.7600


qOut =

 -234.1155   -3.4641   -0.8660   -0.8660   -0.8660   -0.8660
   -4.5000    0.2543    1.5000   -0.5000   -0.5000   -0.5000
    3.5355    0.2543    0.2464   -1.4142    0.7071    0.7071
   -4.4907    0.2543    0.2464   -0.1494   -1.2247    1.2247
   -0.5880    0.2543    0.2464   -0.1494   -0.2512    0.0000
   -2.1727    0.2543    0.2464    0.4236    0.0476    0.0585
   -2.6415    0.2543    0.2464   -0.1494   -0.2512    0.4718
    1.6690    0.2543   -0.3431   -0.0580   -0.0975    0.2227
    0.9087    0.2543    0.2464   -0.1494    0.4137    0.1941
    2.6690    0.2543   -0.3431   -0.0580   -0.0975    0.2227
   -1.0913    0.2543    0.2464   -0.1494    0.4137    0.1941
   -0.1727    0.2543    0.2464    0.4236    0.0476    0.0585


b =

   54.0667
   11.2667
   12.6000
   16.9333
   13.2667


se =

    0.4000
    0.8718
    0.8718
    0.8718
    0.8718


res =

   -2.3333
    1.6667
    1.3333
    0.0000
    0.6667
   -1.6667
   -2.3333
    0.6667
    1.0000
    1.6667
   -1.0000
    0.3333


ifail =

                    0


function g02dg_example
rss = 22.2268;
ip = int64(5);
irank = int64(4);
covar = [0.1481786666666657;
     0.03704466666666638;
     0.7038486666666622;
     0.03704466666666652;
     -0.222268;
     0.7038486666666626;
     0.03704466666666648;
     -0.222268;
     -0.222268;
     0.7038486666666621;
     0.03704466666666641;
     -0.222268;
     -0.222268;
     -0.222268;
     0.7038486666666622];
q = [-132.3142479415325, -3.464101615137754, -0.866025403784439, ...
     -0.8660254037844387, -0.8660254037844387, -0.8660254037844387;
     -4.385, 0.2542949013547401, 1.5, -0.5, -0.5, -0.5;
     3.450681092190354, 0.2542949013547401, 0.2464408878569322, ...
     -1.414213562373095, 0.7071067811865476, 0.7071067811865477;
     -4.564215887385989, 0.2542949013547401, 0.2464408878569322, ...
     -0.1493782079840455, -1.224744871391589, 1.224744871391589;
     -0.5165745490611717, 0.2542949013547401, 0.2464408878569322, ...
     -0.1493782079840455, -0.2512250416211346, 3.684598669906146e-16;
     -1.786105166371516, 0.2542949013547401, 0.2464408878569322, ...
     0.4236386677182777, 0.04757984926531376, 0.05853513115087475;
     -2.040746763558067, 0.2542949013547401, 0.2464408878569322, ...
     -0.1493782079840455, -0.2512250416211346, 0.4717748148066523;
     1.699599417218472, 0.2542949013547401, -0.3431208422711533, ...
     -0.05795805473930137, -0.09747415577321789, 0.2226984422646312;
     1.338178326423549, 0.2542949013547401, 0.2464408878569322, ...
     -0.1493782079840455, 0.4136728082784363, 0.1941369084874573;
     2.919599417218471, 0.2542949013547401, -0.3431208422711533, ...
     -0.05795805473930137, -0.09747415577321789, 0.2226984422646312;
     -1.151821673576453, 0.2542949013547401, 0.2464408878569322, ...
     -0.1493782079840455, 0.4136728082784363, 0.1941369084874573;
     0.2738948336284861, 0.2542949013547401, 0.2464408878569322, ...
     0.4236386677182777, 0.04757984926531376, 0.05853513115087475];
svd = true;
p = [1.135198279858991;
     1.13078348304906;
     1.234006904805161;
     1.228003039942231;
     1.263332232672042;
     3.872983346207417;
     1.732050807568878;
     1.732050807568878;
     1.732050807568877;
     1.64780261914309e-16;
     0.2309401076758503;
     8.35089227579159e-18;
     -1.238223776129407e-17;
     7.900875770685859e-17;
     -0.447213595499958;
     0.0577350269189626;
     0.2871305767251709;
     0.2022129403845741;
     -0.3559016137228031;
     0.447213595499958;
     0.05773502691896256;
     0.03726461792122844;
     0.271286303307133;
     0.4183480487454616;
     0.447213595499958;
     0.05773502691896257;
     0.1515575558927682;
     -0.4677758485215264;
     0.0906424999201606;
     0.447213595499958;
     0.05773502691896258;
     -0.4759527505391677;
     -0.005723395170180857;
     -0.153088934942819;
     0.4472135954999578];
y = [63;
     69;
     68;
     71;
     68;
     65;
     65;
     66;
     72;
     67;
     70;
     67];
wk = [-1;
     4.888782090057172e-17;
     3.783865581974411e-17;
     3.205148747669446e-17;
     2.127304033926049e-17;
     -7.232084855102773e-18;
     0.574261153450342;
     -0.282082169979652;
     -0.7685400295478783;
     -1.766548161010173e-16;
     1.072333245697965e-17;
     0.4044258807691484;
     -0.7184712955241166;
     0.5658963725559621;
     -3.152388336389935e-17;
     -6.842359129558908e-17;
     -0.7118032274456063;
     -0.635789781993599;
     -0.2985088248453474;
     7.896994727506343e-17;
     2.12730403392605e-17;
     1.57267977670022e-16;
     -8.430959034105682e-17;
     -1.677854456096144e-16;
     1;
     0.2886751345948128;
     0.03726461792122845;
     0.271286303307133;
     0.4183480487454616;
     5;
     3.25;
     5.25;
     4.25;
     5.25;
     6.070050924028785e-16;
     0.7071067811865474;
     -0.5700260616371526;
     0.9995120760870788;
     1;
     0.7071067811865475;
     0.8216266117004956;
     0.03123475237772124;
     5.777618349603308e-32;
     -0.7071067811865476;
     -0.5700260616371526];
[rssOut, covarOut, qOut, b, se, res, ifail] = ...
    g02dg(rss, ip, irank, covar, q, svd, p, y, wk)
 

rssOut =

   24.0000


covarOut =

    0.1600
    0.0400
    0.7600
    0.0400
   -0.2400
    0.7600
    0.0400
   -0.2400
   -0.2400
    0.7600
    0.0400
   -0.2400
   -0.2400
   -0.2400
    0.7600


qOut =

 -234.1155   -3.4641   -0.8660   -0.8660   -0.8660   -0.8660
   -4.5000    0.2543    1.5000   -0.5000   -0.5000   -0.5000
    3.5355    0.2543    0.2464   -1.4142    0.7071    0.7071
   -4.4907    0.2543    0.2464   -0.1494   -1.2247    1.2247
   -0.5880    0.2543    0.2464   -0.1494   -0.2512    0.0000
   -2.1727    0.2543    0.2464    0.4236    0.0476    0.0585
   -2.6415    0.2543    0.2464   -0.1494   -0.2512    0.4718
    1.6690    0.2543   -0.3431   -0.0580   -0.0975    0.2227
    0.9087    0.2543    0.2464   -0.1494    0.4137    0.1941
    2.6690    0.2543   -0.3431   -0.0580   -0.0975    0.2227
   -1.0913    0.2543    0.2464   -0.1494    0.4137    0.1941
   -0.1727    0.2543    0.2464    0.4236    0.0476    0.0585


b =

   54.0667
   11.2667
   12.6000
   16.9333
   13.2667


se =

    0.4000
    0.8718
    0.8718
    0.8718
    0.8718


res =

   -2.3333
    1.6667
    1.3333
    0.0000
    0.6667
   -1.6667
   -2.3333
    0.6667
    1.0000
    1.6667
   -1.0000
    0.3333


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