Skip to content

prcomp: problem with zeros? (PR#8870)

2 messages · Brian Ripley, Jari Oksanen

#
On Wed, 17 May 2006, juha.heljoranta at iki.fi wrote:

            
Not a current version of R.
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.

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

            
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