gram_schmidt: Apply the Gram-Schmidt Process to a Matrix

Description Usage Arguments Value Examples

View source: R/gram-schmidt.r

Description

Apply the Gram-Schmidt process to a matrix. This orthogonalizes the columns of a matrix iteratively starting with the left-most column and moving to the right after a pivoting step to ensure numerical stability.

Usage

1
gram_schmidt(x, drop_colinear = TRUE, order_pivot = TRUE)

Arguments

x

a matrix

drop_colinear

should colinear columns be dropped? (default TRUE)

order_pivot

should the columns of the return be orderd by the pivot? (default TRUE)

Value

the return matrix is an orthogonalized version of the input.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Create a matrix from iris.
x <- model.matrix(~ Sepal.Length+Petal.Width+Petal.Length + Petal.Width - 1,
                  data = iris)

# Colinear columns removed and columns are orthogonal.
crossprod(gram_schmidt(x))

# Same linear subspace information as before:
summary(lm(Sepal.Width ~ Sepal.Length+Petal.Width+Petal.Length - 1,
           data = iris))

summary(lm(iris$Sepal.Width ~ Sepal.Length+Petal.Width+Petal.Length - 1,
           data = as.data.frame(gram_schmidt(x))))

presagia-analytics/normalizer documentation built on Dec. 12, 2019, 7:40 a.m.