g02ae {NAGFWrappers} R Documentation

## g02ae: Computes the nearest correlation matrix with k-factor structure to a real square matrix

### Description

g02ae computes the factor loading matrix associated with the nearest correlation matrix with k-factor structure, in the Frobenius norm, to a given square, input matrix.

### Usage

```g02ae(g, k,
n = nrow(g),
errtol = 0.0,
maxit = 0)
```

### Arguments

 `g` double array G, the initial matrix. `k` integer k, the number of factors and columns of X. `n` integer: default = nrow(g) n, the size of the matrix G. `errtol` double: default = 0.0 The termination tolerance for the projected gradient norm. See references for further details. If errtol <= 0.0 then 0.01 is used. This is often a suitable default value. `maxit` integer: default = 0 Specifies the maximum number of iterations in the spectral projected gradient method.

### Details

R interface to the NAG Fortran routine G02AEF.

### Value

 `G` double array A symmetric matrix (1)/(2)(G + G^T) with the diagonal elements set to unity. `X` double array Contains the matrix X. `ITER` integer The number of steps taken in the spectral projected gradient method. `FEVAL` integer The number of function evaluations. `NRMPGD` double The norm of the projected gradient at the final iteration. `IFAIL` integer ifail =0 unless the function detects an error or a warning has been flagged (see the Errors section in Fortran library documentation).

NAG

### Examples

```
ifail <- 0

errtol <- 1e-07

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)

k <- 2

maxits <- 200

maxit <- 10

ans <- g02ae(g, k)

if (ifail == 0) {

"\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))

}

```

[Package NAGFWrappers version 24.0 Index]