QRGS {lazy.mat} R Documentation

## QR decomposition of X matrix by the Gram Schmidt orthogonalization or Finding non redundant columns of X

### Description

QR decomposition of X matrix by the Gram Schmidt orthogonalization or
Finding non redundant columns of X

### Usage

```QRGS(X, orth = 0, zero = 1, epsg = 1e-09, print = 0, debug = 0)
```

### Arguments

 `X` The input matrix of size `n x p` `orth` If orth = 0 Q will contains non redundant rows of X If orth = 1 Q will be orthogonalized using Gram-Schumidt. If orth = 2 Q will be orthonormalized using Gram-Schumidt. `zero` = 1 (not used) `epsg` crit for zero `print` = 1 to print the summary = 2 too print Q,R,P = 3 to print Q0, P0, R0 when zero=1 `debug` = 1 to print intermediate result

### Details

`X` matrix will be decomposed as `X = Q %*% R` where `Q` is the `nrow(X) x rank(X)` matrix and `R` is the `rank(X) x ncol(X)` upper triangular matrix.

Reduction is performed from left to right.
X may contain all zero rows/coluumns.
The Q, R and P matrices can be calculated by the native qr function as

```    qr=qr(X)
Qfromqr=qr.qy(qr,diag(nrow(X)))[,1:ncol(X)][,1:qr\$rank,drop=F]
Rfromqr=t(Qfromqr)
Pfromqr=t(Rfromqr)
Xhat=Qfromqr
QasXP=X
```

This should always give X-Xhat == 0.

### Value

A list of
Q n x r matrix, where r is the rank of X matrix
R r x p upper triangle matrix
P p x r upper triangle matrix to calculate Q as
`Q = X %*% P`
rank rank of X: # of independent columns of X
loczero a vector consisting of the locations of zero pivot
maxadX `max( abs( X - Q %*% R ) )`
and if X is not full rank, Q0, R0, and P0 will be added which are, resp, `n x p, p x p`, and `p x p`.

### Examples

```( resQRGS <- QRGS(demomat(4,3)) )
demomat(4,3) - resQRGS\$Q %*% resQRGS\$R
resQRGS\$Q - demomat(4,3) %*% resQRGS\$P

( resQRGS1 <- QRGS(demomat(4,3), orth=1) )
demomat(4,3) - resQRGS1\$Q %*% resQRGS1\$R
resQRGS1\$Q - demomat(4,3) %*% resQRGS1\$P

( resQRGS2 <- QRGS(demomat(4,3), orth=2) )
demomat(4,3) - resQRGS2\$Q %*% resQRGS2\$R
resQRGS2\$Q - demomat(4,3) %*% resQRGS2\$P

# linearly dependent columns as shown by loczero
A <- cbind(matrix(0:9,6,2),matrix(0:9,6,2)^2)
A <- cbind(A[,1],A[,1]+2*A[,2],A[,2:4])
( resQRGSA <- QRGS(A) )
# depends on the order of sweep
( resQRGSAr <- QRGS(A[,5:1]) )

# linearly dependent rows  as shown by loczero
( resQRGSA <- QRGS( t(A) ) )

# recovering Q of the same size as A  (There are in the output list.)
resQRGSA0 <- QRGS(A, orth=2)
Q0 <- matrix(0,nrow(A),ncol(A))
Q0[,setdiff(1:ncol(A),resQRGSA0\$loczero)] <- resQRGSA0\$Q
R0 <- matrix(0,ncol(A),ncol(A))
R0[setdiff(1:ncol(A),resQRGSA0\$loczero),] <- resQRGSA0\$R
A-Q0%*%R0

```

[Package lazy.mat version 0.1.3 Index]