[R] How to Get Categorical Correlation Coefficient

From: Kum-Hoe Hwang <phdhwang_at_gmail.com>
Date: Thu 12 Oct 2006 - 08:08:25 GMT

Howdy Gurus !

I have a different correlation result from the same data. The "corridor1" string variable is expressed as a number like the "corridor2" number variable.

> levels(corridor1)

[1] "A" "B" "C" "D" "E" "F"
> levels(as.factor(corridor2))
[1] "0" "1" "2" "3" "4"

I have the correlation results followings using cor() function.

> cor(jh1_1, as.factor(corridor1))

[1] 0.01528538
> cor(jh1_1, as.factor(corridor2))

[1] -0.4972571

I donot know why the above correlation coefficients used the same data are different.
They are 0.015 from as.factor(corridor1), -0.497 from as,factor(corridor2). The string variable "corridor1" is the same catergory data with the variable corridor2.
The difference is that "A" is replaced with "0", "B" with "1", "C" with "2", .....

Could you tell me why they are different, and which correlation coefficient is correct?

Thank in advance,

Kum-Hoe Hwang, Ph.D.Phone : 82-31-250-3516Email : phdhwang@gmail.com

R-help@stat.math.ethz.ch mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Thu Oct 12 18:12:24 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 12 Oct 2006 - 09:30:09 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.