[R] Missing Value And cor() function

Frank E Harrell Jr fharrell at virginia.edu
Thu Apr 24 12:55:41 CEST 2003


On Thu, 24 Apr 2003 12:27:50 +0200
vincent.stoliaroff at socgen.com wrote:

> 
> 
> Hi r lovers!
> 
> I 'd like to apply the cor() function to a matrix which have some missing values
> As a matter of fact and quite logically indeed it doesn't work
> Is there a trick to replace the missing value by the mean of each variable or by any other relevant figures ?
> Or should I apply a special derivate of the cor() function, (I don't have any idea if it exists and have some trouble to figure out how it could)
> to skip this trouble?
> Thanks a lot for any suggestions and help
> 
> Vincent
> 
> 

Even though using pairwise deletion of NAs will result sometimes in a singular correlation matrix, it is better to do that than to replace NAs with constants, which will distort the correlations.

You may want to look at the rcorr function in the Hmisc package, which does pairwise deletion of NAs for Pearson and Spearman correlations.  See http://hesweb1.med.virginia.edu/biostat/s/Hmisc.html

> 
> 
> 
> *************************************************************************
> Ce message et toutes les pieces jointes (ci-apres le "message") sont
> confidentiels et etablis a l'intention exclusive de ses destinataires.
> Toute utilisation ou diffusion non autorisee est interdite. 
> Tout message electronique est susceptible d'alteration. 
> La SOCIETE GENERALE et ses filiales declinent toute responsabilite au 
> titre de ce message s'il a ete altere, deforme ou falsifie.
> 				********
> This message and any attachments (the "message") are confidentia... {{dropped}}

Please do not include such long disclaimers in your messages.

---
Frank E Harrell Jr              Prof. of Biostatistics & Statistics
Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences
U. Virginia School of Medicine  http://hesweb1.med.virginia.edu/biostat



More information about the R-help mailing list