orthog {rchemo} | R Documentation |
Orthogonalization of a matrix to another matrix
Description
Function orthog
orthogonalizes a matrix Y
to a matrix X
. The row observations can be weighted.
The function uses function lm
.
Usage
orthog(X, Y, weights = NULL)
Arguments
X |
A |
Y |
A |
weights |
A vector of length |
Value
Y |
The |
b |
The regression coefficients used for orthogonalization. |
Examples
n <- 8 ; p <- 3
set.seed(1)
X <- matrix(rnorm(n * p, mean = 10), ncol = p, byrow = TRUE)
Y <- matrix(rnorm(n * 2, mean = 10), ncol = 2, byrow = TRUE)
colnames(Y) <- c("y1", "y2")
set.seed(NULL)
X
Y
res <- orthog(X, Y)
res$Y
crossprod(res$Y, X)
res$b
# Same as:
fm <- lm(Y ~ X)
Y - fm$fitted.values
fm$coef
#### WITH WEIGHTS
w <- 1:n
fm <- lm(Y ~ X, weights = w)
Y - fm$fitted.values
fm$coef
res <- orthog(X, Y, weights = w)
res$Y
t(res$Y)
res$b
[Package rchemo version 0.1-2 Index]