1

我有一些相关矩阵,想测试它们在统计上是否相等。为此,我正在使用包中的cortest.mat函数psych,但收到以下错误:

solve.default(R1) 中的错误:系统在计算上是奇异的:倒数条件数 = 4.96434e-18

使用随机数也会产生相同的错误,即:

Random<-cor(matrix(rnorm(400, 0, .25), nrow=(20), ncol=(20)))
cortest.mat(Random,Random,n1=400, n2=400)

由于这个包是用来比较相关矩阵的,我不明白我做错了什么。

包: http ://www.personality-project.org/r/html/cortest.mat.html

提前致谢。

4

1 回答 1

0

您需要您的矩阵是一个包含类元素的对象psychsim,您可以使用以下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创建一个具有两个矩阵的对象——一个用于样本,另一个用于总体——我们在测试中使用了样本矩阵(显然)。

于 2016-09-17T01:05:34.817 回答