From sokol at insa-toulouse.fr  Mon Jan 22 17:21:40 2018
From: sokol at insa-toulouse.fr (Serguei Sokol)
Date: Mon, 22 Jan 2018 17:21:40 +0100
Subject: [Rd] Inconsistent rank in qr()
Message-ID: <25bfaeec-31e8-c2db-812e-cb0759342a15@insa-toulouse.fr>

Hi,

I have noticed different rank values calculated by qr() depending on
LAPACK parameter. When it is FALSE (default) a true rank is estimated and returned.
Unfortunately, when LAPACK is set to TRUE, the min(nrow(A), ncol(A)) is returned
which is only occasionally a true rank.

Would not it be more consistent to replace the rank in the latter case by something
based on the following pseudo code ?

d=abs(diag(qr))
rank=sum(d >= d[1]*tol)

Here, we rely on the fact column pivoting is activated in the called lapack routine (dgeqp3)
and diagonal term in qr matrix are put in decreasing order (according to their absolute values).

Serguei.

How to reproduce:

a=diag(2)
a[2,2]=0
qaf=qr(a, LAPACK=FALSE)
qaf$rank # shows 1. OK it's the true rank value
qat=qr(a, LAPACK=TRUE)
qat$rank #shows 2. Bad, it's not the expected value.



[Rd] Inconsistent rank in qr()
Serguei Sokol