g02aa {NAGFWrappers} | R Documentation |
g02aa computes the nearest correlation matrix, in the Frobenius norm, to a given square, input matrix.
g02aa(g, n = nrow(g), errtol = 0.0, maxits = 0, maxit = 0)
g |
double array G, the initial matrix. |
n |
integer: default = nrow(g) 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 Maxits specifies the maximum number of iterations used for the iterative scheme used to solve the linear algebraic equations at each Newton step. |
maxit |
integer: default = 0 Specifies the maximum number of Newton iterations. |
R interface to the NAG Fortran routine G02AAF.
G |
double array A symmetric matrix (1)/(2)(G + G^T) with the diagonal set to I. |
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 =0unless the function detects an error or a warning has been flagged (see the Errors section in Fortran library documentation). |
NAG
http://www.nag.co.uk/numeric/FL/nagdoc_fl23/pdf/G02/g02aaf.pdf
ifail <- 0 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) errtol <- 1e-07 maxits <- 200 maxit <- 10 ans <- g02aa(g) 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", iter)) feval <- ans$FEVAL writeLines(sprintf(" Number of function evaluations: %d", feval)) nrmgrd <- ans$NRMGRD if (nrmgrd > errtol) { writeLines(sprintf(" Norm of gradient of last Newton step: %6.4f", nrmgrd)) } }