[R] How to Get Categorical Correlation Coefficient

Kum-Hoe Hwang phdhwang at gmail.com
Thu Oct 12 10:08:25 CEST 2006


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 at gmail.com



More information about the R-help mailing list