g02ab {NAGFWrappers}R Documentation

g02ab: Computes the nearest correlation matrix to a real square matrix, augmented g02aa to incorporate weights and bounds

Description

g02ab computes the nearest correlation matrix, in the Frobenius norm or weighted Frobenius norm, and optionally with bounds on the eigenvalues, to a given square, input matrix.

Usage

g02ab(g, opt, alpha, w,
      n = nrow(w),
      errtol = 0.0,
      maxits = 0,
      maxit = 0)

Arguments

g

double array

G

, the initial matrix.

opt

string

Indicates the problem to be solved.

opt='A'

: The lower bound problem is solved.

opt='W'

: The weighted norm problem is solved.

opt='B'

: Both problems are solved.

alpha

double

The value of α.

w

double array

The square roots of the diagonal elements of W, that is the diagonal of W^(1)/(2).

n

integer: default = nrow(w)

The size of the matrix G.

errtol

double: default = 0.0

The termination tolerance for the Newton iteration. If errtol <= 0.0 then n \times sqrt(machine precision) is used.

maxits

integer: default = 0

Specifies the maximum number of iterations to be used by the iterative scheme to solve the linear algebraic equations at each Newton step.

maxit

integer: default = 0

Specifies the maximum number of Newton iterations.

Details

R interface to the NAG Fortran routine G02ABF.

Value

G

double array

A symmetric matrix (1)/(2)(G + G^T) with the diagonal set to I.

W

double array

If opt='W', 'B', the array is scaled so max(W_i) = 1 for i=1 . . . n.

X

double array

Contains the nearest correlation matrix.

ITER

integer

The number of Newton steps taken.

FEVAL

integer

The number of function evaluations of the dual problem.

NRMGRD

double

The norm of the gradient of the last Newton step.

IFAIL

integer

ifail =0

unless the function detects an error or a warning has been flagged (see the Errors section in Fortran library documentation).

Author(s)

NAG

References

http://www.nag.co.uk/numeric/FL/nagdoc_fl23/pdf/G02/g02abf.pdf

Examples


ifail <- 0

opt <- "b"

alpha <- 0.02

g <- matrix(c(2, -1, 0, 0, -1, 2, -1, 0, 0, -1, 2, 
    -1, 0, 0, -1, 2), nrow = 4, ncol = 4, byrow = TRUE)



w <- matrix(c(100, 20, 20, 20), nrow = 4, ncol = 1, 
    byrow = TRUE)



errtol <- 1e-07

maxits <- 200

maxit <- 10

ans <- g02ab(g, opt, alpha, w)

if (ifail == 0) {
    
    writeLines(sprintf("\n Nearest Correlation Matrix\n", 
        "\n"))
    
    
    x <- ans$X
    
    print(x) 
    
    iter <- ans$ITER
    
    writeLines(sprintf("\n Number of Newton steps taken: %d\n", 
        iter))
    
    
    feval <- ans$FEVAL
    
    writeLines(sprintf(" Number of function evaluations: %d\n", 
        feval))
    
    
    alpha <- ans$ALPHA
    
    writeLines(sprintf(" \n\n Alpha: %30.3f\n", 
        alpha))
    
    
} 


[Package NAGFWrappers version 24.0 Index]