Learn R Programming

fastQR (version 1.1.4)

qr_lse_fitted: Compute fitted values using QR decomposition

Description

Computes the fitted values \(\hat y = X\hat\beta\) for a linear least-squares problem using a QR decomposition computed internally.

Usage

qr_lse_fitted(X, y)

Value

a numeric vector of fitted values \(\hat y\).

Arguments

X

numeric matrix of dimension \(n \times p\).

y

numeric response vector of length \(n\).

Details

The QR decomposition of \(X\) is computed internally. The fitted values are obtained as $$\widehat y = Q Q^\top y$$ without explicitly forming the orthogonal matrix \(Q\).

This function is intended as a convenience wrapper for least-squares computations when the explicit QR factors are not required.

Examples

Run this code
set.seed(1)
n <- 10; p <- 4
X <- matrix(rnorm(n * p), n, p)
y <- rnorm(n)

yhat1 <- fastQR::qr_lse_fitted(X, y)

## reference computation
yhat2 <- base::qr.fitted(base::qr(X), y)

max(abs(yhat1 - yhat2))

Run the code above in your browser using DataLab