Skip to content

prcomp

4 messages · Rosario Garcia Gil, David Winsemius, David L Carlson

#
Hello

I am trying to run a PCA on the attached file, but I get this error message:

pc<-prcomp(data[,-(1:2)],scale=T)$x
Error in svd(x, nu = 0) : infinite or missing values in 'x'

Thanks in advance
/R
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Romania_PCA_Chlor1.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110817/105129de/attachment.txt>
#
On Aug 17, 2011, at 5:19 PM, Rosario Garcia Gil wrote:

            
What part of "missing values in 'x'" is unclear in that error message?
#
On Aug 17, 2011, at 5:47 PM, David Winsemius wrote:

            
After looking further at the prcomp defaults I see that na.action  
defaults to na.omit so it may not be the missing data, but rather  
collinearity. Do these plotting and descriptive steps to see that your  
data is extremely clustered:

matplot(dat[,-(1:2)] )
  pairs(dat[-(1:2)])
summary(dat[-(1:2)])

So the effort to invert the data matrix is probably failing due to the  
application of inappropriate data reduction to variables which, though  
nominally numeric, are really categorical, and fairly strangely  
distributed ones at that. Also not this advice in ?prcomp:

"Note that scale = TRUE cannot be used if there are zero or constant  
(for center = TRUE) variables." I cpunt four variables that violate  
that restriction. But removing scale=T still does not fix the problem.
#
I think David's idea about NA's was correct. This works:

prcomp(na.omit(Chlor1[,-(1:2)]), scale=TRUE)

The number of cases drops from 288 to 250. There also three 0's in the
dataset that probably should be NA's.

----------------------------------------------
David L Carlson
Texas A&M University
College Station, TX 77843-4352



-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of David Winsemius
Sent: Wednesday, August 17, 2011 5:03 PM
To: David Winsemius
Cc: r-help at r-project.org; Rosario Garcia Gil
Subject: Re: [R] prcomp
On Aug 17, 2011, at 5:47 PM, David Winsemius wrote:

            
After looking further at the prcomp defaults I see that na.action  
defaults to na.omit so it may not be the missing data, but rather  
collinearity. Do these plotting and descriptive steps to see that your  
data is extremely clustered:

matplot(dat[,-(1:2)] )
  pairs(dat[-(1:2)])
summary(dat[-(1:2)])

So the effort to invert the data matrix is probably failing due to the  
application of inappropriate data reduction to variables which, though  
nominally numeric, are really categorical, and fairly strangely  
distributed ones at that. Also not this advice in ?prcomp:

"Note that scale = TRUE cannot be used if there are zero or constant  
(for center = TRUE) variables." I cpunt four variables that violate  
that restriction. But removing scale=T still does not fix the problem.