planarR {lazy.fa} R Documentation

## Planar Rotation

Planar Rotation

### Usage

```planarR(func, A, initT, ..., method = "nlm", sim = 1, init = "pc",
maxiter = 100, eps = 1e-08, epsd = 1e-06, stepmax = 1, SQUAREM = 3,
nSQUAREM = 1, minalpha = -999, maxalpha = -0.5, always = 1,
reset1 = 0, reset2 = 1, print = 0)
```

### Arguments

 `func` Criterion Function to be Minimized which must have `theta, i, j, Ta, A` as the formal arguments. (See the description of critOBR.) `A` Factor Pattern Matrix to be rotated `initT` The initial orthogonal rotation matrix to start planar rotation. This has precedence over init parameter. `...` additional parameters to func such as P, Delta, Q, and Lambda for oblique rotation with fixed R. Or kappa or gamma parameter. `method` The method to be used for minimization "nlm", "opt", or "grid" `sim` = 0 to use ALS `init` = Initial rotation method: "pc", "varimax", "promax", or "random". `maxiter` max # of iterations `eps` convergence criterion for the relative improvement of criterion `epsd` convergence criterion for the max abs difference of thetas `SQUAREM` = 3 : See the help of iSQUAREM in lazy.accel package. `nSQUAREM` when to star iSQUAREM `minalpha` = -999 : See the help of iSQUAREM in lazy.accel package. `maxalpha` = -1 : See the help of iSQUAREM in lazy.accel package. `always` = 1 : See the help of iSQUAREM in lazy.accel package. `reset1` = 0 : See the help of iSQUAREM in lazy.accel package. `reset2` = 1 : See the help of iSQUAREM in lazy.accel package. `print` >= 1 to print the result

### Details

A matrix will be rotated as ` B=A %*% T`
where ` T = T_{21} T_{31} T_{32} ... T{ndim, ndim-1} `
where `T_{ij}` is the ndim x ndim matrix defined as
``` T_{ij}[i,i]=cos(theta_{ij}); T_{ij}[j,j]=cos(theta_{ij}); T_{ij}[i,j]=sin(theta_{ij}); T_{ij}[j,i]=-sin(theta_{ij}) ```
This reparametrizes the free elements of T to `theta_{ij}, i > 2`, and we store them in `thetas` vector of length ndim*(ndim-1)/2.

func function must have the following parametes:
`theta, i, j, Ta, A`
If func has an additional set of parameters, they must be passed through ... argument.

The minimization of func with respect to `thetas` will be performed in two ways:
If sim=0, the ALS approach with inline SQUAREM algorithm will be used where the conditional minimum of func with respect to each element of `thetas` is sought using the method specified in the method parameter.
Available methods are: "nlm", "optimize", and "grid".
If sim=1 the func will be minimized with respect to all the elements of thetas by R native "nlm" function.

When critOBPR is used to perform an Procrustes rotation, sim=0 and method="grid" MUST be specified.

Note that for the oblique rotation with the presicribed factor correlation matrix, `R`, the actual rotation matrix can be obtained as follows.
Let ` R=Q %*% Delta %*% t(Q)` and ` S=P %*% Lambda %*% t(P)`
where `R` is the target factor correlation matrix and `S` is the current factor correlation matrix associated with `A`,
Then, the rotated factor loadings which preserves `R` is given as
`B=A%*%solve(t(W))` where ` W=P %*%diag(1/sqrt(Lambda))%*%T%*%diag(sqrt(Delta))%*%t(Q)`
or
`B=A%*%invtW`
where
`invtW=P%*%diag(sqrt(Lambda))%*%T%*%diag(1/sqrt(Delta))%*%t(Q)`.

See the example below.

Note on the iSQUAREM:
Try always=1 with maxalpha=-1 first.
If it seems not working, use always=0 with maxalpha=1.
Changing reset1=1 and reset2=2 may help.
If all of the above fail, be patient and use SQUAREM=0.

### Value

A list of the following:
T, Ta, thetas, critval, sim, llll, SQUAREM, T0 T = The Orthogonal rotation matrix
Ta = The array of planar rotation matrices: i>j
T0 = The initial roation matrix
thetas = The vector of angles: i>j
critval = The value of criterion minimized
sim = The value of sim parameter
llll = The number of iterations required
SQUAREM = The value of SQUAREM parameter

### Examples

```
seed=1701
set.seed(seed)
n=30; ndim=5

# Simple Orthomax rotation with kappa parameter:
# ... argument is kappa=1.
resp <- planarR( orthomax, A, NULL
, kappa=1
, maxiter=400, eps=1e-7, epsd=1e-7
, method="nlm", sim=1, init="pca" )

# print the result
T=resp\$T
AT=A%*%T
Print(AT, fmt="7.3",fuzz=0.3)

# Target Factor Correlation
rho=0.2
R=matrix(rho,ndim,ndim); diag(R)=1
svd=svd(R); Q=svd\$u; Delta=svd\$d

# current factor dispersion is I
S=diag(ndim)
svd=svd(S); P=svd\$u; Lambda=svd\$d

# Oblique rotation with prescribed R:
# ... argument consists of P=P, Delta=Delta, Q=Q, Lambda=Lambda.
resp <- planarR( critOBR, A, NULL
, P=P, Delta=Delta, Q=Q, Lambda=Lambda
, maxiter=400, eps=1e-7, epsd=1e-7
, method="nlm", sim=1, init="pca" )

# recover the oblique rotation matrix from T.
T=resp\$T
invtW=P %*% diag(sqrt(Lambda)) %*% T %*% diag(1/sqrt(Delta)) %*% t(Q)
W=solve(t(invtW))
AW=A%*%invtW
Print(AW, fmt="7.3",fuzz=0.3)
Print(t(W)%*%W, fmt="7.3")

# Oblique Procrustes rotation with prescribed factor correlation
seed=1701
set.seed(seed)

n=50; ndim=6
temp=gendatafa_A( n, ndim )
Print(Target,A)
loc=( (1:ndim)[(1:ndim)%%2 == 0 | (1:ndim)%%3 == 0] )
Print(ndim,loc)
A[,loc]=-A[,loc]

# current factor dispersion is I
S=diag(ndim)
svd=svd(S); P=svd\$u; Lambda=svd\$d

# Target Factor Correlation
rho=0.2
R=matrix(rho,ndim,ndim); diag(R)=1
svd=svd(R); Q=svd\$u; Delta=svd\$d

resp <- planarR( critOBPR, A, NULL
, Target=Target, P=P, Delta=Delta, Q=Q, Lambda=Lambda
, sim=0, method="grid", print=2, SQUAREM=3
, maxiter=100, eps=1e-7, epsd=1e-7  )

T=resp\$T
invtW=P %*% diag(sqrt(Lambda)) %*% T %*% diag(1/sqrt(Delta)) %*% t(Q)
W=solve(t(invtW))
AA=A%*%invtW
tWW=t(W)%*%W
Print(T,W)
Print(R,tWW)
Print(Target, AA,fmt="8.1 8.5", fuzz=0.3)

```

[Package lazy.fa version 0.1.3 Index]