## SWEEP Function

**sweeps a matrix**
**SWEEP(** *matrix, index-vector***)**

The inputs to the SWEEP function are as follows:
*matrix*
- is a numeric matrix or literal.

*index-vector*
- is a numeric vector indicating the pivots.

The SWEEP function sweeps *matrix* on the pivots
indicated in *index-vector* to produce a new matrix.
The values of the index vector must be less than
or equal to the number of rows or the number of
columns in *matrix*, whichever is smaller.

For example, suppose that **A** is partitioned into

such that **R** is *q* ×*q*
and **U** is (*m*-*q*) ×(*n*-*q*).
Let
I = [1 2 3 . . . q]

Then, the statement
s=sweep(A,I);

becomes

The index vector can be omitted.
In this case, the function sweeps the matrix on all
pivots on the main diagonal 1:MIN(*nrow*,*ncol*).

The SWEEP function has sequential and reversibility
properties when the submatrix swept is positive definite:
- SWEEP(SWEEP(
**A**,1),2)=SWEEP(**A**,{ 1 2 })
- SWEEP(SWEEP(
**A**,**I**),**I**)=**A**

See Beaton (1964) for more information about these properties.

To use the SWEEP function for regression,
suppose the matrix **A** contains

where **X**'**X** is *k* ×*k*.

Then **B** = SWEEP(**A**,1 ... *k*) contains

The partitions of **B** form the beta values, SSE, and a
matrix proportional to the covariance of the beta values for
the least-squares estimates of **B** in the linear model

If any pivot becomes very close to zero (less than or equal
to 1E-12), the row and column for that pivot are zeroed.
See Goodnight (1979) for more information.

Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.