Learn R Programming

matlib (version 0.9.6)

swp: The Matrix Sweep Operator

Description

The swp function “sweeps” a matrix on the rows and columns given in index to produce a new matrix with those rows and columns “partialled out” by orthogonalization. This was defined as a fundamental statistical operation in multivariate methods by Beaton (1964) and expanded by Dempster (1969). It is closely related to orthogonal projection, but applied to a cross-products or covariance matrix, rather than to data.

Usage

swp(M, index)

Value

the matrix M with rows and columns in indices swept.

Arguments

M

a numeric matrix

index

a numeric vector indicating the rows/columns to be swept. The entries must be less than or equal to the number or rows or columns in M. If missing, the function sweeps on all rows/columns 1:min(dim(M)).

Details

If M is the partitioned matrix $$\left[ \begin{array}{cc} \mathbf {R} & \mathbf {S} \\ \mathbf {T} & \mathbf {U} \end{array} \right]$$ where \(R\) is \(q \times q\) then swp(M, 1:q) gives $$\left[ \begin{array}{cc} \mathbf {R}^{-1} & \mathbf {R}^{-1}\mathbf {S} \\ -\mathbf {TR}^{-1} & \mathbf {U}-\mathbf {TR}^{-1}\mathbf {S} \\ \end{array} \right]$$

References

Beaton, A. E. (1964), The Use of Special Matrix Operations in Statistical Calculus, Princeton, NJ: Educational Testing Service.

Dempster, A. P. (1969) Elements of Continuous Multivariate Analysis. Addison-Wesley, Reading, Mass.

See Also

Proj, QR

Examples

Run this code
data(therapy)
mod3 <- lm(therapy ~ perstest + IE + sex, data=therapy)
X <- model.matrix(mod3)
XY <- cbind(X, therapy=therapy$therapy)
XY
M <- crossprod(XY)
swp(M, 1)
swp(M, 1:2)

Run the code above in your browser using DataLab