[Rd] prcomp: problem with zeros? (PR#8870)
Jari Oksanen
jari.oksanen at oulu.fi
Wed May 17 21:25:53 CEST 2006
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
More information about the R-devel
mailing list