From jari.oksanen at oulu.fi  Wed May 17 21:25:53 2006
From: jari.oksanen at oulu.fi (Jari Oksanen)
Date: Wed, 17 May 2006 22:25:53 +0300
Subject: [Rd] prcomp: problem with zeros? (PR#8870)
In-Reply-To: <20060517190240.0A383494DA@slim.kubism.ku.dk>
References: <20060517190240.0A383494DA@slim.kubism.ku.dk>
Message-ID: <bb12b242f645d6ffbcacccfbc115da60@oulu.fi>


On 17 May 2006, at 22:02, ripley at stats.ox.ac.uk wrote:

> On Wed, 17 May 2006, juha.heljoranta at iki.fi wrote:
>>
>> prcomp has a bug which causes following error
>>
>>    Error in svd(x, nu = 0) : infinite or missing values in 'x'
>>
>> on a valid data set (no Infs, no missing values). The error is most 
>> likely
>> caused by the zeros in data.
>
> Why do you say that?  Without a reproducible example, we cannot judge 
> what
> is going on.  If you called prcomp with scale=TRUE on a matrix that 
> has a
> completely zero (or constant) column, then this is a reasonable error
> message.

Constant columns (which is a likely reason here) indeed become NaN 
after scale(), but the error message was:

Error in svd(x, nu = 0) : infinite or missing values in 'x'

and calling this 'reasonable' is stretching the limits of reason.

However, in general this is "easy" to solve:  scale() before the 
analysis and replace NaN with 0 (prcomp handles zeros).  For instance,

x <- scale(x)
x[is.nan(x)] <- 0
prcomp(x)

(and a friendly prcomp() would do this internally.)

cheers, jari oksanen
--
Jari Oksanen, Oulu, Finland



[Rd] prcomp: problem with zeros? (PR#8870)
Jari Oksanen