Questions tagged [qr-decomposition]

QR factorization is an important type of matrix factorization in scientific computing. It is commonly used for generating orthonormal basis and solving least squares problem.

The standard scientific library supports Householder QR factorization with or without pivoting via dgeqrf and dgeqp3.

The scientific software for statistical computing and graphics has a built-in function qr(, LAPACK = TRUE) that interfaces dgeqp3. Note that if LAPACK = FALSE (default), the factorization is implemented with a modified LINPACK routine that can detect numerical rank. This is used for lm and glm functions that fits linear models and generalized linear models.

69 questions
17
votes
2 answers

Find the Rotation and Skew of a Matrix transformation

I have the the following Transform Matrix in CSS // rotate the element 60deg element.style.transform = "matrix(0.5,0.866025,-0.866025,0.5,0,0)" And i can find the rotation using this... // where a = [0.710138,0.502055,-0.57735,1,0,0] var rotation =…
Drew
  • 1,420
  • 1
  • 11
  • 14
11
votes
1 answer

Compute projection / hat matrix via QR factorization, SVD (and Cholesky factorization?)

I'm trying to calculate in R a projection matrix P of an arbitrary N x J matrix S: P = S (S'S) ^ -1 S' I've been trying to perform this with the following function: P <- function(S){ output <- S %*% solve(t(S) %*% S) %*% t(S) …
bikeclub
  • 369
  • 2
  • 10
9
votes
1 answer

How can you implement Householder based QR decomposition in Python?

I'm currently trying to implement the Householder based QR decomposition for rectangular matrices as described in http://eprints.ma.man.ac.uk/1192/1/qrupdating_12nov08.pdf (pages 3, 4, 5). Apparently I got some of the pseudocode wrong though, since…
8
votes
1 answer

Multiple regression analysis in R using QR decomposition

I am trying to write a function for solving multiple regression using QR decomposition. Input: y vector and X matrix; output: b, e, R^2. So far I`ve got this and am terribly stuck; I think I have made everything way too complicated: QR.regression <-…
AGMG
  • 83
  • 6
7
votes
2 answers

Shaken faith in `qr()`

I have relied on the qr() function a lot in dealing with rank-deficient situations, but have recently run into some examples where it doesn't work correctly. Consider the matrix badX below: badX <- structure(c(-1.641906809157e-10, 0, 0, 0, 0, -0.5,…
Russ Lenth
  • 5,922
  • 2
  • 13
  • 21
7
votes
1 answer

How to most efficiently use QR-decomposition in Julia?

Avoiding array allocations is good for performance. However, I have yet to understand what is the most possible efficient way one can perform a QR decomposition of a matrix A. (note: both Q and R matrices are needed) Simply using Q, R = qr(A) is…
7
votes
1 answer

QR Decomposition Algorithm Using Givens Rotations

I am coding a QR decomposition algorithm in MATLAB, just to make sure I have the mechanics correct. Here is the code for the main function: function [Q,R] = QRgivens(A) n = length(A(:,1)); Q = eye(n); R = A; for…
pr0gramR
  • 126
  • 1
  • 2
  • 12
6
votes
1 answer

qr function in R and matlab

I have a question about converting a matlab function into R, and I was hoping that someone could help. The standard QR decomposition used in both matlab and R is referred to as qr(). To my understanding, the standard way of performing a qr…
Ellie
  • 63
  • 3
6
votes
1 answer

How to calculate variance of least squares estimator using QR decomposition in R?

I'm trying to learn QR decomposition, but can't figure out how to get the variance of beta_hat without resorting to traditional matrix calculations. I'm practising with the iris data set, and here's what I have so…
5
votes
1 answer

What does the "Unexpected end of input" error mean?

I am currently building an application in R to calculate the QR matrix decomposition, the QR non negative matrix decomposition and computing ICA. At the moment I am working on the first task. I am getting the following…
Carol
  • 61
  • 1
  • 1
  • 3
5
votes
2 answers

How to get the Q from the QR factorization output?

DGEQRF and SGEQRF from LAPACK return the Q part of the QR factorization in a packed format. Unpacking it seems to require O(k^3) steps (k low-rank products), and doesn't seem to be very straightforward. Plus, the numerical stability of doing k…
MWB
  • 11,740
  • 6
  • 46
  • 91
5
votes
1 answer

Get hat matrix from QR decomposition for weighted least square regression

I am trying to extend the lwr() function of the package McSptial, which fits weigthed regressions as non-parametric estimation. In the core of the lwr() function, it inverts a matrix using solve() instead of a QR decomposition, resulting in…
Arthur
  • 1,208
  • 13
  • 25
4
votes
2 answers

Perfect collinearity detection in sparse matrix using Matrix::qr()

The overall goal of the exercise is to find perfectly collinear columns in a very large, but sparse matrix X in R in the context of a linear regression problem. One approach that pops up from time to time is to make use of the underlying QR…
yrx1702
  • 1,619
  • 15
  • 27
4
votes
0 answers

Differences in QR decomposition of complex matrix in R and Matlab

With the below matrix A, I get different matrices for R in its QR decomposition between [R] and Matlab. (The Q's are different as well, of course.) A <- structure(c(1+0i, -0.75+0.75i, 0+0i, 0+0i, 1+0i, -0.75+0.75i, 1+0i, -1.5+1.5i, 0-1i), .Dim =…
user2474226
  • 1,472
  • 1
  • 9
  • 9
4
votes
1 answer

QR decomposition for rectangular matrices in which n > m in scipy/numpy

I have a m x n rectangular matrix A for which n > m. Given the rank r <= m of A, the reduced QR decomposition yields matrix Q with m x r dimensions, and R with r x n dimensions. The columns of Q are an orthonormal basis for the range of A. R will be…
Anselmo
  • 179
  • 6
1
2 3 4 5