matSwp {lazy.mat}R Documentation

Matrix Sweep Operator

Description

Matrix Sweep Operator

Usage

matSwp(
  A,
  loc = c(1:nrow(A)),
  eps = 1e-08,
  nopermute = 0,
  chkginv = 0,
  debug = 0,
  history = 0
)

Arguments

A

a matrix to be sweeped.

loc

vector consisting of the pivot locations.

eps

small value to check if the pivot is 0.

nopermute

=1 to avoid permuting rows/cols when inverting A.

chkginv

= 1 to check if the resulting g-inverse is genuine.

debug

= 1 to print intermediate result.

history

= 1 to return the permutation matrix RR and CC.

Details

By default, inv(A) will be calculated by permuting columns and rows of A in order to avoid zero pivots as much as possible.
In this case, if RR and CC are the permutation matrix,
inv(A) = CC %*% inv(RR %*% A %*% CC) %*% RR
If history=1 is given, a list of A=matSwp(A) and RR and CC will be returned.


For a symbolic matrix, use matSweep in lazy.symbolic package.

Value

A matrix swept
or a list of A matrix swept and permutation matrix.

References

Beaton, A.E. (1964) The use of special matrix operators in statistical calculus. Ed. D thesis, Harvard University. Reprinted as Educational Testing Service Research Bulletin 64-51. Princeton, N.J.
Goodnight, J.H. (1979) Tutorial on the SWEEP operator. The Amarican Statistician, 33, 3, 149-158.
Dempster,A.P. (1969) Elements of Continuous Multivariate Analysis. Addison- Wesley Publishing Co.,Inc.

Examples

M <- matrix(c(1,2,3,3,2,1,4,5,2),3,3)
Minv <- matSwp(M)
Minv-matSwp(M,1:3)
Minv-matSwp(M,c(3,1,2))
M-matSwp( matSwp(M,1), 1 )


#' # zeros in diagonal
M <- pmat(4,1,3)%*%pmat(4,2,3)

# wrong result
Minv0  <- matSwp(M, nopermute=1)  # same as matSwp(M,1:4)
M%*%Minv0
Minv0%*%M

# correct result
res <- matSwp(M, history=1)
res
Minv <- res$inv
M%*%Minv
Minv%*%M

# correct result 2
M1 <- res$RR %*% M %*% res$CC
Minv1 <- res$CC %*% matSwp(M1, 1:4) %*% res$RR
M%*%Minv1
Minv1%*%M


# g2 inverse
M <- matrix(c(1,2,3,3,2,1,4,5,2),3,3)
M[1,] <- 0
matSwp(M,chkginv=1)

# g2 inverse of a rectangular matrix by augmenting with 0s.
G <- matrix(c(1,2,3,3,2,1),3,2)
ginvG <- matSwp(cbind(G,0))[1:2,1:3]
chkginv( G, ginvG, print=1 )



[Package lazy.mat version 0.1.4 Index]