Re: [R] pca with missing values

From: Angel Lopez <angel_lul_at_hotmail.com>
Date: Thu 01 Jul 2004 - 04:37:01 EST

Thanks for the pointers.
I've read them with care but I don't seem capable of making it work. For example, if I do:

data(USArrests)
USArrests2<-USArrests
USArrests2[1,1]<-NA
princomp(USArrests2, cor = TRUE, na.action = "na.omit")

I get the error message:
Error in cov.wt(z) : x must contain finite values only

I've tried changing the 'options' na.action and using other values than na.omit with no success.

The only way that I can make it work in some way was if I did:

USArrestsNA<-na.omit(USArrests)
princomp(USArrestsNA, cor = TRUE)

I've also obtained the same by giving the correlation matrix instead of the data frame:
princomp(covmat=cor(USArrestsNA))
Both solutions do the job by not using the row with the NA. After more reading I thought I would get the same result by doing: princomp(covmat=cor(USArrests2,use="complete.obs")) but the result is slightly different. I can not manage to understand the difference.
Can someone give me some more light to keep going? P.S:Using the solution above with na.omit would not be very good in my real world problem because it is relatively common to have an NA in a row. Maybe using
princomp(covmat=cor(USArrests2,use="pairwise.complete.obs")) would be a solution but I would like to understand the above before doing this next step.
Thanks,
Ange

Prof Brian Ripley wrote:
> On Wed, 30 Jun 2004, Angel Lopez wrote:
>
>
>>I need to perform a principal components analysis on a matrix with
>>missing values.
>>I've searched the R web site but didn't manage to find anything.
>
>
> ?princomp
>
> has a description of an na.action argument, and
>
> help.search("missing values")
>
> comes up with several relevant entries.
>



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jul 01 04:45:21 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:54:38 EST