| Language Reference |
sweeps a matrix
I = [1 2 3 . . . q]
Then, the statement
B=sweep(A,I);
becomes
An example that uses the SWEEP function for regression follows:
x = { 1 1 1,
1 2 4,
1 3 9,
1 4 16,
1 5 25,
1 6 36,
1 7 49,
1 8 64 };
y = { 3.929,
5.308,
7.239,
9.638,
12.866,
17.069,
23.191,
31.443 };
n = nrow(x); /* number of observations */
k = ncol(x); /* number of variables */
xy = x||y; /* augment design matrix */
A = xy` * xy; /* form cross products */
S = sweep( A, 1:k );
beta = S[1:k,4]; /* parameter estimates */
sse = S[4,4]; /* sum of squared errors */
mse = sse / (n-k); /* mean squared error */
cov = S[1:k, 1:k] # mse; /* covariance of estimates */
print cov, beta, sse;
COV
0.9323716 -0.436247 0.0427693
-0.436247 0.2423596 -0.025662
0.0427693 -0.025662 0.0028513
BETA
5.0693393
-1.109935
0.5396369
SSE
2.395083
The SWEEP function performs most of its computations in the memory allocated for the result matrix.
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.