如何关联R中的非数字向量

时间:2016-10-12 01:39:07

标签: r

我有两个非数字向量,如下所示: aluOrientation向量包含两个字符串之一:Complementary和Direct aluFamily vector包含三个字符串之一:AluS,AluY,AluJ 两者都是36号。

我想将这两者联系起来。那就是我想知道它之间的联系有多强,例如,Complementary和Alu S.我知道如何用数值变量进行相关性测试。但是这些方法(例如kendall)不适用于非数字变量。

我尝试将我的矢量转换为R中的因子。但它似乎并不起作用。有没有人知道R中的函数或包可以关联两个非数字向量?

1 个答案:

答案 0 :(得分:1)

aluOrientation <- rep (c("Complementary", "Direct"), 18)
aluFamily      <- rep(c("AluS", "AluY", "AluJ"), 12)

实现这一目标的一种方法是因子分析:

df1 <- data.frame(aluOrientation, aluFamily)

library(psych)
fa(r = cor(model.matrix(~aluFamily + aluOrientation  - 1, data = df1)), 
   rotate = "none", fm = "pa")
Standardized loadings (pattern matrix) based upon correlation matrix
                       PA1      h2    u2 com
aluFamilyAluJ         1.73 3.0e+00 -1.99   1
aluFamilyAluS        -0.24 5.9e-02  0.94   1
aluFamilyAluY        -0.24 5.9e-02  0.94   1
aluOrientationDirect  0.00 1.0e-30  1.00   1

                PA1
SS loadings    3.11
Proportion Var 0.78

Mean item complexity =  1
Test of the hypothesis that 1 factor is sufficient.

The degrees of freedom for the null model are  6  and the objective function was  5.5
The degrees of freedom for the model are 2  and the objective function was  NaN 

The root mean square of the residuals (RMSR) is  0.23 
The df corrected root mean square of the residuals is  0.4 

Fit based upon off diagonal values = 0.57

更多详情:

http://www.ats.ucla.edu/stat/r/whatstat/whatstat.htm#factor