您需要您的矩阵是一个包含类元素的对象psych
和sim
,您可以使用以下sim.congeneric
函数来实现psych
#The code below results in a sample and population matrix for x and y
y <- sim.congeneric(loads =c(.20,.19,.18,.17,.16,.15,.14,.13,.12,.11,.10,
.9,.8,.7,.6,.5,.4,.3,.2,.1),N=1000,short=FALSE)
x <- sim.congeneric(loads =c(.20,.19,.18,.17,.16,.15,.14,.13,.12,.11,.10,
.9,.8,.7,.6,.5,.4,.3,.2,.1),N=1000,short=FALSE)
#To show the class
class(x)
[1] "psych" "sim"
class(y)
[1] "psych" "sim"
#Now you can run the test
cortest.mat(x$r,y$r,n1=1000,n2=1000) #here we extract the sample matrix using '$r' and run the test
Tests of correlation matrices
Call:cortest.mat(R1 = x$r, R2 = y$r, n1 = 1000, n2 = 1000)
Chi Square value 403.47 with df = 380 with probability < 0.2
让我们生成一个尺寸更小的新相关矩阵,以便我们检查:
sim.congeneric(loads =c(.5,.4,.3,.2,.1),N=1000,short=FALSE)
Call: NULL
$model (Population correlation matrix)
V1 V2 V3 V4 V5
V1 1.00 0.20 0.15 0.10 0.05
V2 0.20 1.00 0.12 0.08 0.04
V3 0.15 0.12 1.00 0.06 0.03
V4 0.10 0.08 0.06 1.00 0.02
V5 0.05 0.04 0.03 0.02 1.00
$r (Sample correlation matrix for sample size = 1000 )
V1 V2 V3 V4 V5
V1 1.00 0.151 0.124 0.1471 0.0303
V2 0.15 1.000 0.137 0.1083 0.0507
V3 0.12 0.137 1.000 0.0894 0.0159
V4 0.15 0.108 0.089 1.0000 0.0018
V5 0.03 0.051 0.016 0.0018 1.0000
请注意,sim.congeneric
创建一个具有两个矩阵的对象——一个用于样本,另一个用于总体——我们在测试中使用了样本矩阵(显然)。