[Rd] bug in det using method="qr" (PR#1244) (PR#4450)

maechler at stat.math.ethz.ch maechler at stat.math.ethz.ch
Wed Nov 12 17:58:02 MET 2003

>>>>> "Wilhelm" == Wilhelm B Kloke <wb at arb-phys.uni-dortmund.de>
>>>>>     on Wed, 12 Nov 2003 13:37:13 +0100 (CET) writes:

    Wilhelm> I just detected, that det() is not working on
    Wilhelm> complex matrices any more, due to the fix to the
    Wilhelm> bug reports noted above. I am not happy with this,
    Wilhelm> as determinants are perfectly usable on complex
    Wilhelm> matrices.

Btw, this is not a bug in the strict sense, 
but a feature request;  OTOH, I know that det() did work for
complex matrices.

    Wilhelm> AFAIUI the bugs resulted from less than optimal
    Wilhelm> behaviour of qr() in certain cases. IMHO this is
    Wilhelm> due to the unhappy decision to use a default for
    Wilhelm> parameter tol to decide whether the the
    Wilhelm> decomposition is rank deficient.

    Wilhelm> A better fix for (PR#1244) should be considered. I
    Wilhelm> propose, using qr method with tol=0 as default, for
    Wilhelm> det(). Even more preferrable, tol=0 can be made the
    Wilhelm> default for qr(), forcing all applications to set a
    Wilhelm> reasonable tol for their own.

I'm not entirely sure about the correctness of your
interpretation of bug fixes here.
Nevertheless, I agree that we should consider allowing
determinant() and hence det() to work for complex matrices --
and change determinant.matrix()'s default argument
`logarithm = TRUE' to 
`logarithm = !is.complex(x)'

Then replace

    if (is.complex(x)) 
        stop("determinant not currently defined for complex matrices")

by something like (we had in R 1.6)

    if (is.complex(x)) {
        qx <- qr(x, tol = 0)
        if (qx$rank < n) 
        x <- prod(diag(qx$qr))
        return(if (n%%2 == 1) x else -x)


Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><

More information about the R-devel mailing list