Fitting a linear model,
lm(y ~ X), by least squares can be thought of geometrically as the orthogonal projection of
y on the column space of
X. This function is designed to allow exploration of projections
a vector, treated as a one-column matrix
a vector or matrix. Number of rows of
logical; if FALSE, return just the projected vector; otherwise returns a list
The projection is defined as P y where P = X (X'X)^- X' and X^- is a generalized inverse.
the projection of
list=FALSE) or a list with elements
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
X <- matrix( c(1, 1, 1, 1, 1, -1, 1, -1), 4,2, byrow=TRUE) y <- 1:4 Proj(y, X[,1]) # project y on unit vector Proj(y, X[,2]) Proj(y, X) # orthogonal complements yp <-Proj(y, X, list=TRUE) yp$y P <- yp$P IP <- diag(4) - P yc <- c(IP %*% y) crossprod(yp$y, yc) # P is idempotent: P P = P P %*% P all.equal(P, P %*% P)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.