G2SWEEP | R Documentation |
Generalized inverse is usually not unique. Some programs use this algorithm to get a unique generalized inverse matrix.
G2SWEEP(A, Augmented=FALSE, eps=1e-08)
A |
a matrix to be inverted. If |
Augmented |
If this is |
eps |
Less than this value is considered as zero. |
Generalized inverse of g2-type is used by some softwares to do linear regression. See 'SAS Technical Report R106, The Sweep Operator: Its importance in Statistical Computing' by J. H. Goodnight for the detail.
when Augmented=FALSE |
ordinary g2 inverse |
when Augmented=TRUE |
g2 inverse and beta hats in the last column and the last row, and sum of square error (SSE) in the last cell |
attribute "rank" |
the rank of input matrix |
Kyun-Seop Bae k@acr.kr
lfit
, ModelMatrix
f1 = uptake ~ Type + Treatment # formula
x = ModelMatrix(f1, CO2) # Model matrix and relevant information
y = model.frame(f1, CO2)[, 1] # observation vector
nc = ncol(x$X) # number of columns of model matrix
XpY = crossprod(x$X, y)
aXpX = rbind(cbind(crossprod(x$X), XpY), cbind(t(XpY), crossprod(y)))
ag2 = G2SWEEP(aXpX, Augmented=TRUE)
b = ag2[1:nc, (nc + 1)] ; b # Beta hat
iXpX = ag2[1:nc, 1:nc] ; iXpX # g2 inverse of X'X
SSE = ag2[(nc + 1), (nc + 1)] ; SSE # Sum of Square Error
DFr = nrow(x$X) - attr(ag2, "rank") ; DFr # Degree of freedom for the residual
# Compare the below with the above
REG(f1, CO2)
aov1(f1, CO2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.