NAG Library Manual, Mark 28.4
```    Program g02dgfe

!     G02DGF Example Program Text

!     Mark 28.4 Release. NAG Copyright 2022.

!     .. Use Statements ..
Use nag_library, Only: g02daf, g02dgf, nag_wp
!     .. Implicit None Statement ..
Implicit None
!     .. Parameters ..
Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
Integer                          :: i, idf, ifail, ip, irank, ldq, ldx,  &
lwk, lwt, m, n
Logical                          :: svd
Character (1)                    :: mean, weight
!     .. Local Arrays ..
Real (Kind=nag_wp), Allocatable  :: b(:), cov(:), h(:), oy(:), p(:),     &
q(:,:), res(:), se(:), wk(:), wt(:), &
x(:,:), y(:)
Integer, Allocatable             :: isx(:)
!     .. Intrinsic Procedures ..
Intrinsic                        :: count
!     .. Executable Statements ..
Write (nout,*) 'G02DGF Example Program Results'
Write (nout,*)

!     Skip heading in data file
Read (nin,*) n, m, weight, mean

If (weight=='W' .Or. weight=='w') Then
lwt = n
Else
lwt = 0
End If
ldx = n
Allocate (x(ldx,m),isx(m),oy(n),y(n),wt(lwt))

If (lwt>0) Then
Else
End If

!     Read in variable inclusion flags

!     Calculate IP
ip = count(isx(1:m)>0)
If (mean=='M' .Or. mean=='m') Then
ip = ip + 1
End If

lwk = 5*(ip-1) + ip*ip
ldq = n
Allocate (b(ip),se(ip),cov(ip*(ip+1)/2),res(n),h(n),q(ldq,ip+1),p(2*ip+  &
ip*ip),wk(lwk))

!     Use suggested value for tolerance
tol = 0.000001E0_nag_wp

!     Fit general linear regression model to first dependent variable
ifail = 0
ldq,svd,irank,p,tol,wk,ifail)

!     Display results for model fit to original dependent variable
Write (nout,*) 'Results for original y-variable using G02DAF'
Write (nout,*)
If (svd) Then
Write (nout,*) 'Model not of full rank'
Write (nout,*)
End If
Write (nout,99999) 'Residual sum of squares = ', rss
Write (nout,99998) 'Degrees of freedom = ', idf
Write (nout,*)
Write (nout,*) 'Variable   Parameter estimate   Standard error'
Write (nout,*)
Write (nout,99997)(i,b(i),se(i),i=1,ip)
Write (nout,*)

!     Read in the new dependent variable

!     Fit same model to different dependent variable
ifail = 0
ifail)

!     Display results for model fit to new dependent variable
Write (nout,*) 'Results for second y-variable using G02DGF'
Write (nout,*)
Write (nout,99999) 'Residual sum of squares = ', rss
Write (nout,99998) 'Degrees of freedom = ', idf
Write (nout,*)
Write (nout,*) 'Variable   Parameter estimate   ', 'Standard error'
Write (nout,*)
Write (nout,99997)(i,b(i),se(i),i=1,ip)

99999 Format (1X,A,E12.4)
99998 Format (1X,A,I4)
99997 Format (1X,I6,2E20.4)
End Program g02dgfe
```