Discussion:
[R] PCA error: svd(x, nu=0) infinite or missing values
Silvia Lomascolo
2008-01-04 23:48:31 UTC
Permalink
Hi,
I am trying to do a PCA on my data but I keep getting the error message

svd(x, nu=0) infinite or missing values
From the messages posted on the subject, I understand that the NAs in my
data might be the problem, but I thought na.omit would take care of that.
Less than 5% of my cells are missing data. However, the NAs are not
regularly distributed across my matrix: certain cases and variables have
most of the NAs in the data set. Might that be the problem? Any hints as to
how to resolve this without having to get rid of those cases and variables?
Code is pasted below.

Any help is greatly appreciated!

Silvia.

CODE:

ot = read.table('C:\\Documents and Settings\\...\\matrix.txt', header=T)
ot.pca = prcomp(ot, scale.=T, na.omit)#this is as far as I got. I have also
tried princomp but I get a very similar error message

I use Windows, and R version 2.6.0.
--
View this message in context: http://www.nabble.com/PCA-error%3A-svd%28x%2C-nu%3D0%29-infinite-or-missing-values-tp14627432p14627432.html
Sent from the R help mailing list archive at Nabble.com.
Prof Brian Ripley
2008-01-05 06:25:26 UTC
Permalink
Please read the help page:

## S3 method for class 'formula':
prcomp(formula, data = NULL, subset, na.action, ...)

## Default S3 method:
prcomp(x, retx = TRUE, center = TRUE, scale. = FALSE, tol = NULL, ...)

So there is no na.action argument for the form you used, and your
'na.omit' matches 'retx'. Try

prcomp(~ ., data=ot, na.action=na.omit, scale=TRUE)

or

prcomp(na.omit(ot), scale=TRUE)
Post by Silvia Lomascolo
Hi,
I am trying to do a PCA on my data but I keep getting the error message
svd(x, nu=0) infinite or missing values
From the messages posted on the subject, I understand that the NAs in my
data might be the problem, but I thought na.omit would take care of that.
Less than 5% of my cells are missing data. However, the NAs are not
regularly distributed across my matrix: certain cases and variables have
most of the NAs in the data set. Might that be the problem? Any hints as to
how to resolve this without having to get rid of those cases and variables?
Code is pasted below.
Any help is greatly appreciated!
Silvia.
ot = read.table('C:\\Documents and Settings\\...\\matrix.txt', header=T)
ot.pca = prcomp(ot, scale.=T, na.omit)#this is as far as I got. I have also
tried princomp but I get a very similar error message
I use Windows, and R version 2.6.0.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
Loading...