createOrthogonalX: Create Design Matrix With Orthogonal Columns
Description
Create a design matrix whose columns are orthogonal to each other.
Usage
createOrthogonalX(n, p)
Value
Matrix with n rows, p columns, and column names X1,
X2, and so forth.
Arguments
n
Number of rows in \(X\)
p
Number of columns in \(X\)
Author
Laurel Stell and Chiara Sabatti
Maintainer: Laurel Stell <lstell@stanford.edu>
Details
First create
\(\hat{X} = (I_p\,\,\,I_p\,\,\,\cdots\,\,\,I_p)^T,\)
where \(I_p\), the identity matrix of size \(p\), is repeated
ceiling(n/p) times. If p does not divide n, remove
rows at the bottom so that \(\hat{X}\) has n rows. Divide by the
root mean square of the columns of \(\hat{X}\).
n <- 50; p <- 5
X <- createOrthogonalX(n, p)
XtX <- t(X) %*% X
D <- diag(n-1, nrow=p)
# XtX and D are not quite equal due to roundoff errorrange(XtX - D)