[R] strange behavior of cor() with pairwise.complete.obs

Hilmar Berger hilmar.berger at imise.uni-leipzig.de
Thu Jan 3 10:06:35 CET 2008



Peter Dalgaard schrieb:
> Hilmar Berger wrote:
>> Sorry,
>> I obviously did not state clearly what the problem is (thanks Daniel):
>>
>> 1. minor problem: cor() does return different types of variables for
>> methods "kendall" and pearson (matrix vs. scalar) when 
>> pairwise.complete.obs is selected.
>> 2. major problem: cor() does return with an error if both x and y are 
>> matrices with method="kendall" when pairwise.complete.obs is
>> selected and one column of one of the two matrices is completely NA.
>> This does not happen for method "pearson".
>>
>> Regards,
>> Hilmar
>>
>> Hilmar Berger <hilmar.berger <at> imise.uni-leipzig.de> writes:
>>  
>>> Hi all,
>>> I'm not quite sure if this is a feature or a bug or if I just fail to
>>> understand
>>> the documentation:
>>> If I use cor() with pairwise.complete.obs and method=pearson, the
>>> result is a
>>> scalar:
>>> ->cor(c(1,2,3),c(3,4,6),use="pairwise.complete.obs",method="pearson")
>>> [1] 0.9819805
>>>
>>> The documentation says that " '"pairwise.complete.obs"' only works 
>>> with the '"pearson"' method
>>>      for 'cov' and 'var'."
>>>
>>> Thus, I guess that cor() should work for pairwise.complete.obs and
>>> method =
>>> "kendall", or am I misinterpreting that statement ?
>>>
>>>     
> I would interpret it to mean that it does NOT work for "kendall" and 
> "spearman" and I don't see how you can possibly interpret otherwise.
> 

Well, the phrase states that in the case of *cov* and *var* it does not 
work for kendall and spearman. It does not say anything about *cor*, so 
I assume that it should work there for all methods.
Looking at the code of cor() I noticed that the case of 
pairwise.complete.obs is explicitly handled for "kendall" and 
"spearman", returning even a result and not an error.

Regards,
Hilmar


-- 

Hilmar Berger
Studienkoordinator
Institut für medizinische Informatik, Statistik und Epidemiologie
Universität Leipzig
Härtelstr. 16-18
D-04107 Leipzig

Tel. +49 341 97 16 101
Fax. +49 341 97 16 109
email: hilmar.berger at imise.uni-leipzig.de




More information about the R-help mailing list