NAG Library Routine Document
g02dgf
(linregm_fit_newvar)
1
Purpose
g02dgf calculates the estimates of the arguments of a general linear regression model for a new dependent variable after a call to
g02daf.
2
Specification
Fortran Interface
Subroutine g02dgf ( |
weight,
n,
wt,
rss,
ip,
irank,
cov,
q,
ldq,
svd,
p,
y,
b,
se,
res,
wk,
ifail) |
Integer, Intent (In) | :: |
n,
ip,
irank,
ldq | Integer, Intent (Inout) | :: |
ifail | Real (Kind=nag_wp), Intent (In) | :: |
wt(*),
p(*),
y(n),
wk(5*(ip-1)+ip*ip) | Real (Kind=nag_wp), Intent (Inout) | :: |
rss,
cov(ip*(ip+1)/2),
q(ldq,ip+1) | Real (Kind=nag_wp), Intent (Out) | :: |
b(ip),
se(ip),
res(n) | Logical, Intent (In) | :: |
svd | Character (1), Intent (In) | :: |
weight |
|
C Header Interface
#include nagmk26.h
void |
g02dgf_ (
const char *weight,
const Integer *n,
const double wt[],
double *rss,
const Integer *ip,
const Integer *irank,
double cov[],
double q[],
const Integer *ldq,
const logical *svd,
const double p[],
const double y[],
double b[],
double se[],
double res[],
const double wk[],
Integer *ifail,
const Charlen length_weight) |
|
3
Description
g02dgf uses the results given by
g02daf to fit the same set of independent variables to a new dependent variable.
g02daf computes a
decomposition of the matrix of
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 arguments for a general linear model with a new dependent variable. The
decomposition leads to the formation of an upper triangular
by
matrix
and an
by
orthogonal matrix
. In addition the vector
(or
) is computed. For a new dependent variable,
,
g02dgf computes a new value of
or
.
If
is of full rank, then the least squares parameter estimates,
, are the solution to
where
is the first
elements of
.
If
is not of full rank, then
g02daf will have computed an SVD of
,
where
is a
by
diagonal matrix with nonzero diagonal elements,
being the rank of
, and
and
are
by
orthogonal matrices. This gives the solution
being the first
columns of
, i.e.,
, and
being the first
columns of
. Details of the SVD are made available by
g02daf in the form of the matrix
:
The matrix
is made available through the workspace of
g02daf.
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.
4
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
5
Arguments
- 1: – Character(1)Input
-
On entry: indicates if weights are to be used.
- Least squares estimation is used.
- Weighted least squares is used and weights must be supplied in array wt.
Constraint:
or .
- 2: – IntegerInput
-
On entry: , the number of observations.
Constraint:
.
- 3: – Real (Kind=nag_wp) arrayInput
-
Note: the dimension of the array
wt
must be at least
if
, and at least
otherwise.
On entry: if
>,
wt must contain the weights to be used in the weighted regression.
If , the th 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 referenced and the effective number of observations is
.
Constraint:
if , , for .
-
On entry: the residual sum of squares for the original dependent variable.
On exit: the residual sum of squares for the new dependent variable.
Constraint:
.
- 5: – IntegerInput
-
On entry: , the number of independent variables (including the mean if fitted).
Constraint:
.
- 6: – IntegerInput
-
On entry: the rank of the independent variables, as given by
g02daf.
Constraint:
, and if , then , else .
- 7: – Real (Kind=nag_wp) arrayInput/Output
-
On entry: the covariance matrix of the parameter estimates as given by
g02daf.
On exit: 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
and the parameter estimate given in
,
, is stored in
.
- 8: – Real (Kind=nag_wp) arrayInput/Output
-
On entry: the results of the
decomposition as returned by
g02daf.
On exit: the first column of
q contains the new values of
, the remainder of
q will be unchanged.
- 9: – IntegerInput
-
On entry: the first dimension of the array
q as declared in the (sub)program from which
g02dgf is called.
Constraint:
.
- 10: – LogicalInput
-
On entry: indicates if a singular value decomposition was used by
g02daf.
- A singular value decomposition was used by g02daf.
- A singular value decomposition was not used by g02daf.
- 11: – Real (Kind=nag_wp) arrayInput
-
Note: the dimension of the array
p
must be at least
if
, and at least
otherwise.
On entry: details of the
decomposition and SVD, if used, as returned in array
p by
g02daf.
If
, only the first
ip elements of
p are used; these contain the zeta values for the
decomposition (see
f08aef (dgeqrf) for details).
If
, the first
ip elements of
p contain the zeta values for the
decomposition (see
f08aef (dgeqrf) for details) and the next
elements of
p contain details of the singular value decomposition.
- 12: – Real (Kind=nag_wp) arrayInput
-
On entry: the new dependent variable, .
- 13: – Real (Kind=nag_wp) arrayOutput
-
On exit: the least squares estimates of the parameters of the regression model, .
- 14: – Real (Kind=nag_wp) arrayOutput
-
On exit: the standard error of the estimates of the parameters.
- 15: – Real (Kind=nag_wp) arrayOutput
-
On exit: the residuals for the new regression model.
- 16: – Real (Kind=nag_wp) arrayInput
-
On entry: if
,
wk must be unaltered from the previous call to
g02daf or
g02dgf.
If
,
wk is used as workspace.
- 17: – IntegerInput/Output
-
On entry:
ifail must be set to
,
. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this argument, the recommended value is
.
When the value is used it is essential to test the value of ifail on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6
Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
x04aaf).
Errors or warnings detected by the routine:
-
On entry, .
Constraint: .
On entry, .
Constraint: .
On entry, and .
Constraint: if , .
On entry, and .
Constraint: if , .
On entry, and .
Constraint: .
On entry, and .
Constraint: .
On entry, .
Constraint: .
On entry, .
Constraint: or .
-
On entry, .
Constraint: , for .
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
Accuracy
The same accuracy as
g02daf is obtained.
8
Parallelism and Performance
g02dgf is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g02dgf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
The values of the leverages,
, are unaltered by a change in the dependent variable so a call to
g02faf can be made using the value of
h from
g02daf.
10
Example
A dataset consisting of
observations with four independent variables and two dependent variables are read in. A model with all four independent variables is fitted to the first dependent variable by
g02daf and the results printed. The model is then fitted to the second dependent variable by
g02dgf and those results printed.
10.1
Program Text
Program Text (g02dgfe.f90)
10.2
Program Data
Program Data (g02dgfe.d)
10.3
Program Results
Program Results (g02dgfe.r)