From sokol at insa-toulouse.fr  Mon Jan 22 17:57:47 2018
From: sokol at insa-toulouse.fr (Serguei Sokol)
Date: Mon, 22 Jan 2018 17:57:47 +0100
Subject: [Rd] Inconsistent rank in qr()
In-Reply-To: <DCF48AFB-EE93-4048-99E1-56613BB43872@nyu.edu>
References: <25bfaeec-31e8-c2db-812e-cb0759342a15@insa-toulouse.fr>
 <DCF48AFB-EE93-4048-99E1-56613BB43872@nyu.edu>
Message-ID: <dce19c1c-d8e7-c315-7db2-15f3a279373d@insa-toulouse.fr>

Le 22/01/2018 ? 17:40, Keith O'Hara a ?crit?:
> This behavior is noted in the qr documentation, no?
>
> rank - the rank of x as computed by the decomposition(*): always full rank in the LAPACK case.
For a me a "full rank matrix" is a matrix the rank of which is indeed min(nrow(A), ncol(A))
but here the meaning of "always is full rank" is somewhat confusing. Does it mean
that only full rank matrices must be submitted to qr() when LAPACK=TRUE?
May be there is a jargon where "full rank" is a synonym of min(nrow(A), ncol(A)) for any matrix
but the fix to stick with commonly admitted rank definition (i.e. the number of linearly independent
columns in A) is so easy. Why to discard lapack case from it (even properly documented)?

>
>
>
>> On Jan 22, 2018, at 11:21 AM, Serguei Sokol <sokol at insa-toulouse.fr> wrote:
>>
>> 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.
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Serguei Sokol
Ingenieur de recherche INRA

Cellule math?matique
LISBP, INSA/INRA UMR 792, INSA/CNRS UMR 5504
135 Avenue de Rangueil
31077 Toulouse Cedex 04

tel: +33 5 6155 9849
email: sokol at insa-toulouse.fr
http://www.lisbp.fr



[Rd] Inconsistent rank in qr()
Serguei Sokol