Takes a matrix of data frame with covariates, adds a constant covariate (optional), and orthonormalizes the set.
A matrix or data frame with covariates (one column per covariate).
Factor variables are split into dummy variables before orthonormalization.
The operation is performed via QR decomposition (qr).
Returns a matrix with orthogonal columns with unit length,
whose columns spans the same space as the covariates plus a constant
This function is used in several parts of the pipeline.
Andrey A Shabalin firstname.lastname@example.org
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# Sample matrix of covariates covariates = data.frame(a = 1:12, b = 12:1) # Orthonormalizing Covariates cvrtqr = orthonormalizeCovariates(covariates, modelhasconstant = TRUE) # Checking the results (round to ignore rounding errors) print( round(crossprod(cvrtqr),15) ) # Stop if not orthonormal stopifnot(all.equal( crossprod(cvrtqr), diag(ncol(cvrtqr)) )) # Example with a factor variable groups = data.frame(gr = c("a","a","a","b","b","b","c","c","c")) orthonormalizeCovariates(groups)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.