# NAG FL Interfaceg02dnf (linregm_​estfunc)

## 1Purpose

g02dnf gives the estimate of an estimable function along with its standard error.

## 2Specification

Fortran Interface
 Subroutine g02dnf ( ip, b, cov, p, f, est, stat, t, tol, wk,
 Integer, Intent (In) :: ip, irank Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: b(ip), cov(ip*(ip+1)/2), p(ip*ip+2*ip), f(ip), tol Real (Kind=nag_wp), Intent (Out) :: stat, sestat, t, wk(ip) Logical, Intent (Out) :: est
#include <nag.h>
 void g02dnf_ (const Integer *ip, const Integer *irank, const double b[], const double cov[], const double p[], const double f[], logical *est, double *stat, double *sestat, double *t, const double *tol, double wk[], Integer *ifail)
The routine may be called by the names g02dnf or nagf_correg_linregm_estfunc.

## 3Description

g02dnf computes the estimates of an estimable function for a general linear regression model which is not of full rank. It is intended for use after a call to g02daf or g02ddf. An estimable function is a linear combination of the parameters such that it has a unique estimate. For a full rank model all linear combinations of parameters are estimable.
In the case of a model not of full rank the routines use a singular value decomposition (SVD) to find the parameter estimates, $\stackrel{^}{\beta }$, and their variance-covariance matrix. Given the upper triangular matrix $R$ obtained from the $QR$ decomposition of the independent variables the SVD gives
 $R=Q* D 0 0 0 PT,$
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,$
${P}_{1}$ being the first $k$ columns of $P$, i.e., $P=\left({P}_{1}{P}_{0}\right)$, ${Q}_{{*}_{1}}$ being the first $k$ columns of ${Q}_{*}$, and ${c}_{1}$ being the first $p$ elements of $c$.
Details of the SVD are made available in the form of the matrix ${P}^{*}$:
 $P*= D-1 P1T P0T ,$
as given by g02daf and g02ddf.
A linear function of the parameters, $F={f}^{\mathrm{T}}\beta$, can be tested to see if it is estimable by computing $\zeta ={P}_{0}^{\mathrm{T}}f$. If $\zeta$ is zero, then the function is estimable; if not, the function is not estimable. In practice $\left|\zeta \right|$ is tested against some small quantity $\eta$.
Given that $F$ is estimable it can be estimated by ${f}^{\mathrm{T}}\stackrel{^}{\beta }$ and its standard error calculated from the variance-covariance matrix of $\stackrel{^}{\beta }$, ${C}_{\beta }$, as
 $seF=fTCβf.$
Also a $t$-statistic,
 $t=fTβ^ seF ,$
can be computed. The $t$-statistic will have a Student's $t$-distribution with degrees of freedom as given by the degrees of freedom for the residual sum of squares for the model.

## 4References

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

## 5Arguments

1: $\mathbf{ip}$Integer Input
On entry: $p$, the number of terms in the linear model.
Constraint: ${\mathbf{ip}}\ge 1$.
2: $\mathbf{irank}$Integer Input
On entry: $k$, the rank of the independent variables.
Constraint: $1\le {\mathbf{irank}}\le {\mathbf{ip}}$.
3: $\mathbf{b}\left({\mathbf{ip}}\right)$Real (Kind=nag_wp) array Input
On entry: the ip values of the estimates of the parameters of the model, $\stackrel{^}{\beta }$.
4: $\mathbf{cov}\left({\mathbf{ip}}×\left({\mathbf{ip}}+1\right)/2\right)$Real (Kind=nag_wp) array Input
On entry: 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 ${\mathbf{b}}\left(i\right)$ and the parameter estimate given in ${\mathbf{b}}\left(j\right)$, $j\ge i$, is stored in ${\mathbf{cov}}\left(\left(j×\left(j-1\right)/2+i\right)\right)$.
5: $\mathbf{p}\left({\mathbf{ip}}×{\mathbf{ip}}+2×{\mathbf{ip}}\right)$Real (Kind=nag_wp) array Input
On entry: as returned by g02daf and g02ddf.
6: $\mathbf{f}\left({\mathbf{ip}}\right)$Real (Kind=nag_wp) array Input
On entry: $f$, the linear function to be estimated.
7: $\mathbf{est}$Logical Output
On exit: indicates if the function was estimable.
${\mathbf{est}}=\mathrm{.TRUE.}$
The function is estimable.
${\mathbf{est}}=\mathrm{.FALSE.}$
The function is not estimable and stat, sestat and t are not set.
8: $\mathbf{stat}$Real (Kind=nag_wp) Output
On exit: if ${\mathbf{est}}=\mathrm{.TRUE.}$, stat contains the estimate of the function, ${f}^{\mathrm{T}}\stackrel{^}{\beta }$.
9: $\mathbf{sestat}$Real (Kind=nag_wp) Output
On exit: if ${\mathbf{est}}=\mathrm{.TRUE.}$, sestat contains the standard error of the estimate of the function, $\mathrm{se}\left(F\right)$.
10: $\mathbf{t}$Real (Kind=nag_wp) Output
On exit: if ${\mathbf{est}}=\mathrm{.TRUE.}$, t contains the $t$-statistic for the test of the function being equal to zero.
11: $\mathbf{tol}$Real (Kind=nag_wp) Input
On entry: $\eta$, the tolerance value used in the check for estimability.
If ${\mathbf{tol}}\le 0.0$ then $\sqrt{\epsilon }$, where $\epsilon$ is the machine precision, is used instead.
12: $\mathbf{wk}\left({\mathbf{ip}}\right)$Real (Kind=nag_wp) array Workspace
13: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, . If you are unfamiliar with this argument you should refer to Section 4 in the Introduction to the NAG Library FL Interface 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 $1$ is recommended. Otherwise, because for this routine the values of the output arguments may be useful even if ${\mathbf{ifail}}\ne {\mathbf{0}}$ on exit, the recommended value is $-1$. When the value is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
Note: in some cases g02dnf may return useful information.
${\mathbf{ifail}}=1$
On entry, ${\mathbf{ip}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ip}}\ge 1$.
On entry, ${\mathbf{irank}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{irank}}\ge 1$.
On entry, ${\mathbf{irank}}=〈\mathit{\text{value}}〉$ and ${\mathbf{ip}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{irank}}\le {\mathbf{ip}}$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{irank}}={\mathbf{ip}}$, i.e., model of full rank. In this case est is returned as true and all statistics are calculated.
${\mathbf{ifail}}=3$
Standard error of statistic $\text{}=0.0$; this may be due to rounding errors if the standard error is very small or due to mis-specified inputs cov and f.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

The computations are believed to be stable.

## 8Parallelism and Performance

g02dnf 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 value of estimable functions is independent of the solution chosen from the many possible solutions. While g02dnf may be used to estimate functions of the parameters of the model as computed by g02dkf, ${\beta }_{c}$, these must be expressed in terms of the original parameters, $\beta$. The relation between the two sets of parameters may not be straightforward.

## 10Example

Data from an experiment with four treatments and three observations per treatment are read in. A model, with a mean term, is fitted by g02daf. The number of functions to be tested is read in, then the linear functions themselves are read in and tested with g02dnf. The results of g02dnf are printed.

### 10.1Program Text

Program Text (g02dnfe.f90)

### 10.2Program Data

Program Data (g02dnfe.d)

### 10.3Program Results

Program Results (g02dnfe.r)