Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

selectedQr

QR Decomposition Preserving Selected Columns


Description

Runs a matrix through the QR decomposition and returns the transformed matrix and the forward and inverse transforming matrices R, Rinv. If columns of the input matrix X are centered the QR transformed matrix will be orthogonal. This is helpful in understanding the transformation and in scaling prior distributions on the transformed scale. not can be specified to keep selected columns as-is. cornerQr leaves the last column of X alone (possibly after centering). When not is specified, the square transforming matrices have appropriate identity submatrices inserted so that recreation of original X is automatic.

Usage

selectedQr(X, not = NULL, corner = FALSE, center = TRUE)

Arguments

X

a numeric matrix

not

an integer vector specifying which columns of X are to be kept with their original values

corner

set to FALSE to not treat the last column specially. You may not specify both not and corner.

center

set to FALSE to not center columns of X first

Value

list with elements X, R, Rinv, xbar where xbar is the vector of means (vector of zeros if center=FALSE)

Author(s)

Ben Goodrich and Frank Harrell

Examples

x <- 1 : 10
  X <- cbind(x, x^2)
  w <- selectedQr(X)
  w
  with(w, X %*% R)  # = scale(X, center=TRUE, scale=FALSE)
  Xqr <- w$X
  plot(X[, 1], Xqr[, 1])
  plot(X[, 1], Xqr[, 2])
  cov(X)
  cov(Xqr)
  X <- cbind(x, x^3, x^4, x^2)
  w <- selectedQr(X, not=2:3)
  with(w, X %*% R)

rmsb

Bayesian Regression Modeling Strategies

v0.0.2
GPL (>= 3)
Authors
Frank Harrell [aut, cre] (<https://orcid.org/0000-0002-8271-5493>), Ben Goodrich [ctb] (contributed Stan code), Ben Bolker [ctb] (wrote original code that is folded into the pdensityContour function), Doug Bates [ctb] (write original code for highest posterior density interval that is folded into the HPDint function)
Initial release
2021-02-27

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.