orthonormalizeCovariates {ramwas}R Documentation

Orthonormalize Covariates

Description

Takes a matrix of data frame with covariates, adds a constant covariate (optional), and orthonormalizes the set.

Usage

orthonormalizeCovariates(cvrt, modelhasconstant)

Arguments

cvrt

A matrix or data frame with covariates (one column per covariate).

modelhasconstant

Set to TRUE to add a constant covariate into the set before normalization.

Details

Factor variables are split into dummy variables before orthonormalization.
The operation is performed via QR decomposition (qr).

Value

Returns a matrix with orthogonal columns with unit length, whose columns spans the same space as the covariates plus a constant (if modelhasconstant is TRUE).

Note

This function is used in several parts of the pipeline.

Author(s)

Andrey A Shabalin andrey.shabalin@gmail.com

Examples

# 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)

[Package ramwas version 1.6.0 Index]