[R] prcomp

David L Carlson dcarlson at tamu.edu
Thu Aug 18 19:04:54 CEST 2011


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:

>
> On Aug 17, 2011, at 5:19 PM, Rosario Garcia Gil wrote:
>
>> 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'
>
> What part of "missing values in 'x'" is unclear in that error message?

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.

-- 

David Winsemius, MD
West Hartford, CT

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list